Skip to content

Commit 5f4f32a

Browse files
committed
Added test for burn bootloader
1 parent c26ba92 commit 5f4f32a

File tree

4 files changed

+73
-30
lines changed

4 files changed

+73
-30
lines changed

commands/upload/testdata/hardware/alice/avr/boards.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@ board1.conf.board=conf-board1
33
board1.upload.tool=one
44
board1.upload.protocol=protocol
55
board1.upload.speed=speed
6-
76
board1.bootloader.tool=one
8-
board1.bootloader.low_fuses=0xFF
9-
board1.bootloader.high_fuses=0xDE
10-
board1.bootloader.extended_fuses=0xFD
11-
board1.bootloader.unlock_bits=0x3F
12-
board1.bootloader.lock_bits=0x0F
13-
board1.bootloader.file=optiboot/optiboot_atmega328.hex
7+
board1.bootloader.fuses=0xFF
8+
board1.bootloader.file=niceboot/niceboot.hex
149

1510

1611
board2.name=board2

commands/upload/testdata/hardware/alice/avr/platform.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ tools.one.program.params.verify=verify
1818
tools.one.program.params.noverify=noverify
1919
tools.one.program.pattern={cmd.path} {conf.board} {conf.general} {program.conf} {program.verbose} {program.verify} {program.protocol} "{serial.port}" -b{upload.speed} "{build.path}/{build.project_name}.hex"
2020

21+
tools.one.erase.conf=conf-erase
22+
tools.one.erase.params.verbose=verbose
23+
tools.one.erase.params.quiet=quiet
24+
tools.one.erase.params.verify=verify
25+
tools.one.erase.params.noverify=noverify
26+
tools.one.erase.pattern={cmd.path} ERASE {conf.board} {conf.general} {erase.conf} {erase.verbose} {erase.verify} {protocol} "{serial.port}" -b{upload.speed}
27+
28+
tools.one.bootloader.conf=conf-bootloader
29+
tools.one.bootloader.params.verbose=verbose
30+
tools.one.bootloader.params.quiet=quiet
31+
tools.one.bootloader.params.verify=verify
32+
tools.one.bootloader.params.noverify=noverify
33+
tools.one.bootloader.pattern={cmd.path} BURN {conf.board} {conf.general} {bootloader.conf} {bootloader.verbose} {bootloader.verify} {protocol} "{serial.port}" -b{upload.speed} -F{bootloader.fuses} "{runtime.platform.path}/bootloaders/{bootloader.file}"
34+
2135
# Upload test 2
2236
tools.one-noport.cmd.path=echo
2337
tools.one-noport.conf.general=conf-general

commands/upload/upload.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,13 @@ func runProgramAction(pm *packagemanager.PackageManager,
235235
if verify {
236236
uploadProperties.Set("upload.verify", uploadProperties.Get("upload.params.verify"))
237237
uploadProperties.Set("program.verify", uploadProperties.Get("program.params.verify"))
238+
uploadProperties.Set("erase.verify", uploadProperties.Get("erase.params.verify"))
239+
uploadProperties.Set("bootloader.verify", uploadProperties.Get("bootloader.params.verify"))
238240
} else {
239241
uploadProperties.Set("upload.verify", uploadProperties.Get("upload.params.noverify"))
240242
uploadProperties.Set("program.verify", uploadProperties.Get("program.params.noverify"))
243+
uploadProperties.Set("erase.verify", uploadProperties.Get("erase.params.noverify"))
244+
uploadProperties.Set("bootloader.verify", uploadProperties.Get("bootloader.params.noverify"))
241245
}
242246

243247
if !burnBootloader {

commands/upload/upload_test.go

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -136,25 +136,36 @@ func TestUploadPropertiesComposition(t *testing.T) {
136136
programmer string
137137
burnBootloader bool
138138
expected string
139+
expected2 string
139140
}
140141

142+
cwdPath, err := paths.Getwd()
143+
require.NoError(t, err)
144+
cwd := cwdPath.String()
145+
141146
tests := []test{
142-
// classic upload, requires port
143-
{buildPath1, "alice:avr:board1", "port", "", false, "conf-board1 conf-general conf-upload $$VERBOSE-VERIFY$$ protocol port -bspeed testdata/build_path_1/sketch.ino.hex"},
144-
{buildPath1, "alice:avr:board1", "", "", false, "FAIL"},
145-
// classic upload, no port
146-
{buildPath1, "alice:avr:board2", "port", "", false, "conf-board1 conf-general conf-upload $$VERBOSE-VERIFY$$ protocol -bspeed testdata/build_path_1/sketch.ino.hex"},
147-
{buildPath1, "alice:avr:board2", "", "", false, "conf-board1 conf-general conf-upload $$VERBOSE-VERIFY$$ protocol -bspeed testdata/build_path_1/sketch.ino.hex"},
148-
149-
// upload with programmer, requires port
150-
{buildPath1, "alice:avr:board1", "port", "progr1", false, "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ progprotocol port -bspeed testdata/build_path_1/sketch.ino.hex"},
151-
{buildPath1, "alice:avr:board1", "", "progr1", false, "FAIL"},
152-
// upload with programmer, no port
153-
{buildPath1, "alice:avr:board1", "port", "progr2", false, "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ prog2protocol -bspeed testdata/build_path_1/sketch.ino.hex"},
154-
{buildPath1, "alice:avr:board1", "", "progr2", false, "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ prog2protocol -bspeed testdata/build_path_1/sketch.ino.hex"},
155-
// upload with programmer, require port through extra params
156-
{buildPath1, "alice:avr:board1", "port", "progr3", false, "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ prog3protocol port -bspeed testdata/build_path_1/sketch.ino.hex"},
157-
{buildPath1, "alice:avr:board1", "", "progr3", false, "FAIL"},
147+
// 0: classic upload, requires port
148+
{buildPath1, "alice:avr:board1", "port", "", false, "conf-board1 conf-general conf-upload $$VERBOSE-VERIFY$$ protocol port -bspeed testdata/build_path_1/sketch.ino.hex", ""},
149+
{buildPath1, "alice:avr:board1", "", "", false, "FAIL", ""},
150+
// 2: classic upload, no port
151+
{buildPath1, "alice:avr:board2", "port", "", false, "conf-board1 conf-general conf-upload $$VERBOSE-VERIFY$$ protocol -bspeed testdata/build_path_1/sketch.ino.hex", ""},
152+
{buildPath1, "alice:avr:board2", "", "", false, "conf-board1 conf-general conf-upload $$VERBOSE-VERIFY$$ protocol -bspeed testdata/build_path_1/sketch.ino.hex", ""},
153+
154+
// 4: upload with programmer, requires port
155+
{buildPath1, "alice:avr:board1", "port", "progr1", false, "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ progprotocol port -bspeed testdata/build_path_1/sketch.ino.hex", ""},
156+
{buildPath1, "alice:avr:board1", "", "progr1", false, "FAIL", ""},
157+
// 6: upload with programmer, no port
158+
{buildPath1, "alice:avr:board1", "port", "progr2", false, "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ prog2protocol -bspeed testdata/build_path_1/sketch.ino.hex", ""},
159+
{buildPath1, "alice:avr:board1", "", "progr2", false, "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ prog2protocol -bspeed testdata/build_path_1/sketch.ino.hex", ""},
160+
// 8: upload with programmer, require port through extra params
161+
{buildPath1, "alice:avr:board1", "port", "progr3", false, "conf-board1 conf-general conf-program $$VERBOSE-VERIFY$$ prog3protocol port -bspeed testdata/build_path_1/sketch.ino.hex", ""},
162+
{buildPath1, "alice:avr:board1", "", "progr3", false, "FAIL", ""},
163+
164+
// 10: burn bootloader, require port
165+
{buildPath1, "alice:avr:board1", "port", "", true, "FAIL", ""}, // requires programmer
166+
{buildPath1, "alice:avr:board1", "port", "progr1", true,
167+
"ERASE conf-board1 conf-general conf-erase $$VERBOSE-VERIFY$$ genprog1protocol port -bspeed",
168+
"BURN conf-board1 conf-general conf-bootloader $$VERBOSE-VERIFY$$ genprog1protocol port -bspeed -F0xFF " + cwd + "/testdata/hardware/alice/avr/bootloaders/niceboot/niceboot.hex"},
158169
}
159170
for i, test := range tests {
160171
t.Run(fmt.Sprintf("SubTest%02d", i), func(t *testing.T) {
@@ -178,8 +189,19 @@ func TestUploadPropertiesComposition(t *testing.T) {
178189
require.Error(t, err)
179190
} else {
180191
require.NoError(t, err)
181-
out := strings.TrimSpace(outStream.String())
182-
require.Equal(t, strings.ReplaceAll(test.expected, "$$VERBOSE-VERIFY$$", "quiet noverify"), out)
192+
out := strings.Split(outStream.String(), "\n")
193+
// With verbose disable, the upload will output at least 2 lines:
194+
// - the output of the command (1 or 2 lines)
195+
// - an empty line
196+
if test.expected2 != "" {
197+
require.Len(t, out, 3)
198+
} else {
199+
require.Len(t, out, 2)
200+
}
201+
require.Equal(t, strings.ReplaceAll(test.expected, "$$VERBOSE-VERIFY$$", "quiet noverify"), out[0])
202+
if test.expected2 != "" {
203+
require.Equal(t, strings.ReplaceAll(test.expected2, "$$VERBOSE-VERIFY$$", "quiet noverify"), out[1])
204+
}
183205
}
184206
})
185207
t.Run(fmt.Sprintf("SubTest%02d-WithVerifyAndVerbose", i), func(t *testing.T) {
@@ -204,13 +226,21 @@ func TestUploadPropertiesComposition(t *testing.T) {
204226
} else {
205227
require.NoError(t, err)
206228
out := strings.Split(outStream.String(), "\n")
207-
// With verbose enabled, the upload will output 3 lines:
208-
// - the command line that the cli is going to run
209-
// - the output of the command
229+
// With verbose enabled, the upload will output at least 3 lines:
230+
// - the first command line that the cli is going to run
231+
// - the output of the first command
232+
// - OPTIONAL: the second command line that the cli is going to run
233+
// - OPTIONAL: the output of the second command
210234
// - an empty line
211-
// we are interested in the second line
212-
require.Len(t, out, 3)
235+
if test.expected2 != "" {
236+
require.Len(t, out, 5)
237+
} else {
238+
require.Len(t, out, 3)
239+
}
213240
require.Equal(t, strings.ReplaceAll(test.expected, "$$VERBOSE-VERIFY$$", "verbose verify"), out[1])
241+
if test.expected2 != "" {
242+
require.Equal(t, strings.ReplaceAll(test.expected2, "$$VERBOSE-VERIFY$$", "verbose verify"), out[3])
243+
}
214244
}
215245
})
216246
}

0 commit comments

Comments
 (0)