|
| 1 | +/* |
| 2 | + * This file is part of Arduino Builder. |
| 3 | + * |
| 4 | + * Arduino Builder is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation; either version 2 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program; if not, write to the Free Software |
| 16 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | + * |
| 18 | + * As a special exception, you may use this file as part of a free software |
| 19 | + * library without restriction. Specifically, if other files instantiate |
| 20 | + * templates or use macros or inline functions from this file, or you compile |
| 21 | + * this file and link it with other files to produce an executable, this |
| 22 | + * file does not by itself cause the resulting executable to be covered by |
| 23 | + * the GNU General Public License. This exception does not however |
| 24 | + * invalidate any other reasons why the executable file might be covered by |
| 25 | + * the GNU General Public License. |
| 26 | + * |
| 27 | + * Copyright 2016 Arduino LLC (http://www.arduino.cc/) |
| 28 | + */ |
| 29 | + |
| 30 | +package phases |
| 31 | + |
| 32 | +import ( |
| 33 | + "testing" |
| 34 | + |
| 35 | + "github.com/stretchr/testify/require" |
| 36 | +) |
| 37 | + |
| 38 | +func TestSizerWithAVRData(t *testing.T) { |
| 39 | + output := []byte(`/tmp/test597119152/sketch.ino.elf : |
| 40 | +section size addr |
| 41 | +.data 36 8388864 |
| 42 | +.text 3966 0 |
| 43 | +.bss 112 8388900 |
| 44 | +.comment 17 0 |
| 45 | +.debug_aranges 704 0 |
| 46 | +.debug_info 21084 0 |
| 47 | +.debug_abbrev 4704 0 |
| 48 | +.debug_line 5456 0 |
| 49 | +.debug_frame 1964 0 |
| 50 | +.debug_str 8251 0 |
| 51 | +.debug_loc 7747 0 |
| 52 | +.debug_ranges 856 0 |
| 53 | +Total 54897 |
| 54 | +`) |
| 55 | + |
| 56 | + size, err := computeSize(`^(?:\.text|\.data|\.bootloader)\s+([0-9]+).*`, output) |
| 57 | + require.NoError(t, err) |
| 58 | + require.Equal(t, 4002, size) |
| 59 | + |
| 60 | + size, err = computeSize(`^(?:\.data|\.bss|\.noinit)\s+([0-9]+).*`, output) |
| 61 | + require.NoError(t, err) |
| 62 | + require.Equal(t, 148, size) |
| 63 | + |
| 64 | + size, err = computeSize(`^(?:\.eeprom)\s+([0-9]+).*`, output) |
| 65 | + require.NoError(t, err) |
| 66 | + require.Equal(t, 0, size) |
| 67 | +} |
| 68 | + |
| 69 | +func TestSizerWithSAMDData(t *testing.T) { |
| 70 | + output := []byte(`/tmp/test737785204/sketch_usbhost.ino.elf : |
| 71 | +section size addr |
| 72 | +.text 8076 8192 |
| 73 | +.data 152 536870912 |
| 74 | +.bss 1984 536871064 |
| 75 | +.ARM.attributes 40 0 |
| 76 | +.comment 128 0 |
| 77 | +.debug_info 178841 0 |
| 78 | +.debug_abbrev 14968 0 |
| 79 | +.debug_aranges 2080 0 |
| 80 | +.debug_ranges 3840 0 |
| 81 | +.debug_line 26068 0 |
| 82 | +.debug_str 55489 0 |
| 83 | +.debug_frame 5036 0 |
| 84 | +.debug_loc 20978 0 |
| 85 | +Total 317680 |
| 86 | +`) |
| 87 | + |
| 88 | + size, err := computeSize(`\.text\s+([0-9]+).*`, output) |
| 89 | + require.NoError(t, err) |
| 90 | + require.Equal(t, 8076, size) |
| 91 | +} |
| 92 | + |
| 93 | +func TestSizerEmptyRegexpReturnsMinusOne(t *testing.T) { |
| 94 | + size, err := computeSize(``, []byte(`xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`)) |
| 95 | + require.NoError(t, err) |
| 96 | + require.Equal(t, -1, size) |
| 97 | +} |
| 98 | + |
| 99 | +func TestSizerWithInvalidRegexp(t *testing.T) { |
| 100 | + _, err := computeSize(`[xx`, []byte(`xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`)) |
| 101 | + require.Error(t, err) |
| 102 | +} |
0 commit comments