Skip to content

Commit ccb424c

Browse files
committed
Add discovery upload test
1 parent 967b15a commit ccb424c

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed

test/test_discovery_upload.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# This file is part of arduino-cli.
2+
#
3+
# Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
#
5+
# This software is released under the GNU General Public License version 3,
6+
# which covers the main part of arduino-cli.
7+
# The terms of this license can be found at:
8+
# https://www.gnu.org/licenses/gpl-3.0.en.html
9+
#
10+
# You can be released from the requirements of the above licenses by purchasing
11+
# a commercial license. Buying such a license is mandatory if you want to modify or
12+
# otherwise use the software for commercial activities involving the Arduino
13+
# software without disclosing the source code of your own applications. To purchase
14+
# a commercial license, send an email to [email protected].
15+
import tempfile
16+
import hashlib
17+
import shutil
18+
from pathlib import Path
19+
20+
21+
def generate_build_dir(sketch_path):
22+
sketch_path_md5 = hashlib.md5(bytes(sketch_path)).hexdigest().upper()
23+
build_dir = Path(tempfile.gettempdir(), f"arduino-sketch-{sketch_path_md5}")
24+
build_dir.mkdir(parents=True, exist_ok=True)
25+
return build_dir
26+
27+
28+
def install_fake_platform(data_dir, platform_name):
29+
platform_install_dir = Path(data_dir, "packages", "arduino", "hardware", platform_name, "4.2.0")
30+
# Install fake platform
31+
shutil.copytree(
32+
Path(__file__).parent / "testdata" / platform_name, platform_install_dir, dirs_exist_ok=True,
33+
)
34+
return platform_install_dir
35+
36+
37+
def install_fake_avrdude(data_dir):
38+
avrdude_install_dir = Path(data_dir, "packages", "arduino", "tools", "avrdude", "1.0.0")
39+
(avrdude_install_dir / "bin").mkdir(parents=True, exist_ok=True)
40+
(avrdude_install_dir / "res").mkdir(parents=True, exist_ok=True)
41+
(avrdude_install_dir / "bin" / "avrdude").touch()
42+
(avrdude_install_dir / "res" / "avrdude.conf").touch()
43+
return avrdude_install_dir
44+
45+
46+
def test_upload_sketch_without_pluggable_discovery(run_command, data_dir):
47+
assert run_command("update")
48+
49+
test_platform_arch = "platform_without_pluggable_discovery"
50+
install_fake_platform(data_dir, test_platform_arch)
51+
avrdude_install_dir = install_fake_avrdude(data_dir)
52+
avrdude_binary_path = avrdude_install_dir / "bin" / "avrdude"
53+
avrdude_config_path = avrdude_install_dir / "etc" / "avrdude.conf"
54+
55+
# Create a sketch
56+
sketch_name = "UploadSketchWithoutPluggableDiscovery"
57+
sketch_path = Path(data_dir, sketch_name)
58+
assert run_command(f"sketch new {sketch_path}")
59+
60+
# Fake compilation, we just need the folder to exist
61+
build_dir = generate_build_dir(sketch_path)
62+
63+
fqbn = "arduino:platform_without_pluggable_discovery:nessuno"
64+
65+
upload_port = "/dev/ttyACM1"
66+
res = run_command(f"upload -p {upload_port} -b {fqbn} {sketch_path} --dry-run -v --log-level info")
67+
assert res.ok
68+
69+
compiled_binary_path = build_dir / f"{sketch_name}.ino.hex"
70+
build_mcu = "atmega328p"
71+
upload_protocol = "arduino"
72+
upload_speed = "115200"
73+
74+
expected_output = (
75+
f'"{avrdude_binary_path}" '
76+
+ f'"-C{avrdude_config_path}" '
77+
+ "-v -V "
78+
+ f"-p{build_mcu} "
79+
+ f"-c{upload_protocol} "
80+
+ f'"-P{upload_port}" '
81+
+ f"-b{upload_speed} "
82+
+ f'-D "-Uflash:w:{compiled_binary_path}:i"'
83+
)
84+
85+
assert expected_output in res.stdout
86+
87+
# Upload to board that uses a 1200bps touch
88+
fqbn = "arduino:platform_without_pluggable_discovery:altra"
89+
upload_port = "/dev/ttyACM999"
90+
res = run_command(f"upload -p {upload_port} -b {fqbn} {sketch_path} --dry-run -v --log-level info")
91+
assert res.ok
92+
93+
# Port changes after touch
94+
upload_port = "/dev/ttyACM9990"
95+
expected_output = (
96+
f'"{avrdude_binary_path}" '
97+
+ f'"-C{avrdude_config_path}" '
98+
+ "-v -V "
99+
+ f"-p{build_mcu} "
100+
+ f"-c{upload_protocol} "
101+
+ f'"-P{upload_port}" '
102+
+ f"-b{upload_speed} "
103+
+ f'-D "-Uflash:w:{compiled_binary_path}:i"'
104+
)
105+
106+
assert expected_output in res.stdout
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
nessuno.name=Arduino Nessuno
2+
nessuno.vid.0=0x2341
3+
nessuno.pid.0=0x0043
4+
nessuno.vid.1=0x2341
5+
nessuno.pid.1=0x0001
6+
nessuno.vid.2=0x2A03
7+
nessuno.pid.2=0x0043
8+
nessuno.vid.3=0x2341
9+
nessuno.pid.3=0x0243
10+
nessuno.upload.tool=avrdude
11+
nessuno.upload.protocol=arduino
12+
nessuno.upload.maximum_size=32256
13+
nessuno.upload.maximum_data_size=2048
14+
nessuno.upload.speed=115200
15+
nessuno.bootloader.tool=avrdude
16+
nessuno.bootloader.low_fuses=0xFF
17+
nessuno.bootloader.high_fuses=0xDE
18+
nessuno.bootloader.extended_fuses=0xFD
19+
nessuno.bootloader.unlock_bits=0x3F
20+
nessuno.bootloader.lock_bits=0x0F
21+
nessuno.bootloader.file=optiboot/optiboot_atmega328.hex
22+
nessuno.build.mcu=atmega328p
23+
nessuno.build.f_cpu=16000000L
24+
nessuno.build.board=AVR_NESSUNO
25+
nessuno.build.core=arduino
26+
nessuno.build.variant=standard
27+
28+
altra.name=Arduino Altra
29+
altra.vid.0=0x2341
30+
altra.pid.0=0x0043
31+
altra.vid.1=0x2341
32+
altra.pid.1=0x0001
33+
altra.vid.2=0x2A03
34+
altra.pid.2=0x0043
35+
altra.vid.3=0x2341
36+
altra.pid.3=0x0243
37+
altra.upload.tool=avrdude
38+
altra.upload.protocol=arduino
39+
altra.upload.maximum_size=32256
40+
altra.upload.maximum_data_size=2048
41+
altra.upload.speed=115200
42+
altra.upload.use_1200bps_touch=true
43+
altra.upload.wait_for_upload_port=true
44+
altra.bootloader.tool=avrdude
45+
altra.bootloader.low_fuses=0xFF
46+
altra.bootloader.high_fuses=0xDE
47+
altra.bootloader.extended_fuses=0xFD
48+
altra.bootloader.unlock_bits=0x3F
49+
altra.bootloader.lock_bits=0x0F
50+
altra.bootloader.file=optiboot/optiboot_atmega328.hex
51+
altra.build.mcu=atmega328p
52+
altra.build.f_cpu=16000000L
53+
altra.build.board=AVR_ALTRA
54+
altra.build.core=arduino
55+
altra.build.variant=standard
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name=Arduino Test Boards
2+
version=4.2.0
3+
4+
tools.avrdude.path={runtime.tools.avrdude.path}
5+
tools.avrdude.cmd.path={path}/bin/avrdude
6+
tools.avrdude.config.path={path}/etc/avrdude.conf
7+
8+
tools.avrdude.upload.params.verbose=-v
9+
tools.avrdude.upload.params.quiet=-q -q
10+
tools.avrdude.upload.params.noverify=-V
11+
tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} {upload.verify} -p{build.mcu} -c{upload.protocol} "-P{serial.port}" -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"

0 commit comments

Comments
 (0)