Skip to content

Commit baa6206

Browse files
committed
Added more tests for upload
1 parent 4bb455b commit baa6206

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
board1.name=board1
2+
board1.conf.board=conf-board1
3+
board1.upload.tool=one
4+
board1.upload.protocol=protocol
5+
board1.upload.speed=speed
6+
7+
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
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name=Upload Test Platform (Alice)
2+
version=1.0.0
3+
4+
# Upload test 1
5+
tools.one.cmd.path=echo
6+
tools.one.conf.general=conf-general
7+
8+
tools.one.upload.conf=conf-upload
9+
tools.one.upload.params.verbose=verbose
10+
tools.one.upload.params.quiet=quiet
11+
tools.one.upload.params.verify=verify
12+
tools.one.upload.params.noverify=noverify
13+
tools.one.upload.pattern={cmd.path} {conf.board} {conf.general} {upload.conf} {upload.verbose} {upload.verify} {upload.protocol} "{serial.port}" -b{upload.speed} "{build.path}/{build.project_name}.hex"
14+
15+
# Upload test 2
16+
tools.one-noport.cmd.path=echo
17+
tools.one-noport.upload.params.verbose=verbose
18+
tools.one-noport.upload.params.quiet=quiet
19+
tools.one-noport.upload.verify=verify
20+
tools.one-noport.upload.params.noverify=noverify
21+
tools.one-noport.upload.pattern={cmd.path} {conf.general} {conf.upload} {upload.verbose} {upload.verify} {build.mcu} {upload.protocol} "{serial.port}" -b{upload.speed} "{build.path}/{build.project_name}.hex"

commands/upload/upload_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
package upload
1717

1818
import (
19+
"bytes"
1920
"fmt"
21+
"strings"
2022
"testing"
2123

2224
"github.com/arduino/arduino-cli/arduino/cores"
25+
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2326
"github.com/arduino/arduino-cli/arduino/sketches"
2427
paths "github.com/arduino/go-paths-helper"
2528
"github.com/stretchr/testify/require"
@@ -119,3 +122,74 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) {
119122
})
120123
}
121124
}
125+
126+
func TestUploadPropertiesComposition(t *testing.T) {
127+
pm := packagemanager.NewPackageManager(nil, nil, nil, nil)
128+
err := pm.LoadHardwareFromDirectory(paths.New("testdata", "hardware"))
129+
require.NoError(t, err)
130+
buildPath1 := paths.New("testdata", "build_path_1")
131+
132+
type test struct {
133+
importDir *paths.Path
134+
fqbn string
135+
port string
136+
programmer string
137+
burnBootloader bool
138+
expected string
139+
}
140+
141+
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+
}
145+
for i, test := range tests {
146+
t.Run(fmt.Sprintf("SubTest%02d", i), func(t *testing.T) {
147+
outStream := &bytes.Buffer{}
148+
errStream := &bytes.Buffer{}
149+
err := runProgramAction(
150+
pm,
151+
nil, // sketch
152+
"", // importFile
153+
test.importDir.String(), // importDir
154+
test.fqbn, // FQBN
155+
test.port, // port
156+
test.programmer, // programmer
157+
false, // verbose
158+
false, // verify
159+
test.burnBootloader, // burnBootloader
160+
outStream,
161+
errStream,
162+
)
163+
require.NoError(t, err)
164+
out := strings.TrimSpace(outStream.String())
165+
require.Equal(t, strings.ReplaceAll(test.expected, "$$VERBOSE-VERIFY$$", "quiet noverify"), out)
166+
})
167+
t.Run(fmt.Sprintf("SubTest%02d-WithVerifyAndVerbose", i), func(t *testing.T) {
168+
outStream := &bytes.Buffer{}
169+
errStream := &bytes.Buffer{}
170+
err := runProgramAction(
171+
pm,
172+
nil, // sketch
173+
"", // importFile
174+
test.importDir.String(), // importDir
175+
test.fqbn, // FQBN
176+
test.port, // port
177+
test.programmer, // programmer
178+
true, // verbose
179+
true, // verify
180+
test.burnBootloader, // burnBootloader
181+
outStream,
182+
errStream,
183+
)
184+
require.NoError(t, err)
185+
out := strings.Split(outStream.String(), "\n")
186+
// With verbose enabled, the upload will output 3 lines:
187+
// - the command line that the cli is going to run
188+
// - the output of the command
189+
// - an empty line
190+
// we are interested in the second line
191+
require.Len(t, out, 3)
192+
require.Equal(t, strings.ReplaceAll(test.expected, "$$VERBOSE-VERIFY$$", "verbose verify"), out[1])
193+
})
194+
}
195+
}

0 commit comments

Comments
 (0)