|
13 | 13 | # software without disclosing the source code of your own applications. To purchase
|
14 | 14 | # a commercial license, send an email to [email protected].
|
15 | 15 | import os
|
| 16 | +import hashlib |
| 17 | +import tempfile |
| 18 | +import shutil |
16 | 19 | from pathlib import Path
|
17 | 20 |
|
18 | 21 | import pytest
|
@@ -195,3 +198,143 @@ def test_compile_and_upload_combo_with_custom_build_path(run_command, data_dir,
|
195 | 198 | assert f"Compile {sketch_name} for {board.fqbn} successful" in traces
|
196 | 199 | assert f"Upload {sketch_path} on {board.fqbn} started" in traces
|
197 | 200 | assert "Upload successful" in traces
|
| 201 | + |
| 202 | + |
| 203 | +def test_compile_and_upload_combo_sketch_with_pde_extension(run_command, data_dir, detected_boards, wait_for_board): |
| 204 | + assert run_command("update") |
| 205 | + |
| 206 | + sketch_name = "CompileAndUploadPdeSketch" |
| 207 | + sketch_path = Path(data_dir, sketch_name) |
| 208 | + |
| 209 | + # Create a test sketch |
| 210 | + assert run_command(f"sketch new {sketch_path}") |
| 211 | + |
| 212 | + # Renames sketch file to pde |
| 213 | + sketch_file = Path(sketch_path, f"{sketch_name}.ino").rename(sketch_path / f"{sketch_name}.pde") |
| 214 | + |
| 215 | + for board in detected_boards: |
| 216 | + # Install core |
| 217 | + core = ":".join(board.fqbn.split(":")[:2]) |
| 218 | + assert run_command(f"core install {core}") |
| 219 | + |
| 220 | + # Build sketch and upload from folder |
| 221 | + wait_for_board() |
| 222 | + res = run_command(f"compile --clean -b {board.fqbn} -u -p {board.address} {sketch_path}") |
| 223 | + assert res.ok |
| 224 | + assert "Sketches with .pde extension are deprecated, please rename the following files to .ino" in res.stderr |
| 225 | + assert str(sketch_file) in res.stderr |
| 226 | + |
| 227 | + # Build sketch and upload from file |
| 228 | + wait_for_board() |
| 229 | + res = run_command(f"compile --clean -b {board.fqbn} -u -p {board.address} {sketch_file}") |
| 230 | + assert res.ok |
| 231 | + assert "Sketches with .pde extension are deprecated, please rename the following files to .ino" in res.stderr |
| 232 | + assert str(sketch_file) in res.stderr |
| 233 | + |
| 234 | + |
| 235 | +def test_upload_sketch_with_pde_extension(run_command, data_dir, detected_boards, wait_for_board): |
| 236 | + assert run_command("update") |
| 237 | + |
| 238 | + sketch_name = "UploadPdeSketch" |
| 239 | + sketch_path = Path(data_dir, sketch_name) |
| 240 | + |
| 241 | + # Create a test sketch |
| 242 | + assert run_command(f"sketch new {sketch_path}") |
| 243 | + |
| 244 | + # Renames sketch file to pde |
| 245 | + sketch_file = Path(sketch_path, f"{sketch_name}.ino").rename(sketch_path / f"{sketch_name}.pde") |
| 246 | + |
| 247 | + for board in detected_boards: |
| 248 | + # Install core |
| 249 | + core = ":".join(board.fqbn.split(":")[:2]) |
| 250 | + assert run_command(f"core install {core}") |
| 251 | + |
| 252 | + # Compile sketch first |
| 253 | + assert run_command(f"compile --clean -b {board.fqbn} {sketch_path}") |
| 254 | + |
| 255 | + # Upload from sketch folder |
| 256 | + wait_for_board() |
| 257 | + assert run_command(f"upload -b {board.fqbn} -p {board.address} {sketch_path}") |
| 258 | + |
| 259 | + # Upload from sketch file |
| 260 | + wait_for_board() |
| 261 | + assert run_command(f"upload -b {board.fqbn} -p {board.address} {sketch_file}") |
| 262 | + |
| 263 | + # Upload from build folder |
| 264 | + sketch_path_md5 = hashlib.md5(bytes(sketch_path)).hexdigest().upper() |
| 265 | + build_dir = Path(tempfile.gettempdir(), f"arduino-sketch-{sketch_path_md5}") |
| 266 | + wait_for_board() |
| 267 | + res = run_command(f"upload -b {board.fqbn} -p {board.address} --input-dir {build_dir}") |
| 268 | + assert ( |
| 269 | + "Sketches with .pde extension are deprecated, please rename the following files to .ino:" not in res.stderr |
| 270 | + ) |
| 271 | + |
| 272 | + # Upload from binary file |
| 273 | + wait_for_board() |
| 274 | + # We don't need a specific file when using the --input-file flag to upload since |
| 275 | + # it's just used to calculate the directory, so it's enough to get a random file |
| 276 | + # that's inside that directory |
| 277 | + binary_file = next(build_dir.glob(f"{sketch_name}.pde.*")) |
| 278 | + res = run_command(f"upload -b {board.fqbn} -p {board.address} --input-file {binary_file}") |
| 279 | + assert ( |
| 280 | + "Sketches with .pde extension are deprecated, please rename the following files to .ino:" not in res.stderr |
| 281 | + ) |
| 282 | + |
| 283 | + |
| 284 | +def test_upload_with_input_dir_containing_multiple_binaries(run_command, data_dir, detected_boards, wait_for_board): |
| 285 | + # This tests verifies the behaviour outlined in this issue: |
| 286 | + # https://github.com/arduino/arduino-cli/issues/765#issuecomment-699678646 |
| 287 | + assert run_command("update") |
| 288 | + |
| 289 | + # Create a two different sketches |
| 290 | + sketch_one_name = "UploadMultipleBinariesSketchOne" |
| 291 | + sketch_one_path = Path(data_dir, sketch_one_name) |
| 292 | + assert run_command(f"sketch new {sketch_one_path}") |
| 293 | + |
| 294 | + sketch_two_name = "UploadMultipleBinariesSketchTwo" |
| 295 | + sketch_two_path = Path(data_dir, sketch_two_name) |
| 296 | + assert run_command(f"sketch new {sketch_two_path}") |
| 297 | + |
| 298 | + for board in detected_boards: |
| 299 | + # Install core |
| 300 | + core = ":".join(board.fqbn.split(":")[:2]) |
| 301 | + assert run_command(f"core install {core}") |
| 302 | + |
| 303 | + # Compile both sketches and copy binaries in the same directory same build directory |
| 304 | + assert run_command(f"compile --clean -b {board.fqbn} {sketch_one_path}") |
| 305 | + assert run_command(f"compile --clean -b {board.fqbn} {sketch_two_path}") |
| 306 | + |
| 307 | + sketch_path_md5 = hashlib.md5(bytes(sketch_one_path)).hexdigest().upper() |
| 308 | + build_dir_one = Path(tempfile.gettempdir(), f"arduino-sketch-{sketch_path_md5}") |
| 309 | + |
| 310 | + sketch_path_md5 = hashlib.md5(bytes(sketch_two_path)).hexdigest().upper() |
| 311 | + build_dir_two = Path(tempfile.gettempdir(), f"arduino-sketch-{sketch_path_md5}") |
| 312 | + |
| 313 | + # Copy binaries to same folder |
| 314 | + binaries_dir = Path(data_dir, "build", "BuiltBinaries") |
| 315 | + shutil.copytree(build_dir_one, binaries_dir, dirs_exist_ok=True) |
| 316 | + shutil.copytree(build_dir_two, binaries_dir, dirs_exist_ok=True) |
| 317 | + |
| 318 | + wait_for_board() |
| 319 | + # Verifies upload fails because multiple binaries are found |
| 320 | + res = run_command(f"upload -b {board.fqbn} -p {board.address} --input-dir {binaries_dir}") |
| 321 | + assert res.failed |
| 322 | + assert ( |
| 323 | + "Error during Upload: " |
| 324 | + + "retrieving build artifacts: " |
| 325 | + + "autodetect build artifact: " |
| 326 | + + "multiple build artifacts found:" |
| 327 | + in res.stderr |
| 328 | + ) |
| 329 | + |
| 330 | + # Copy binaries to folder with same name of a sketch |
| 331 | + binaries_dir = Path(data_dir, "build", "UploadMultipleBinariesSketchOne") |
| 332 | + shutil.copytree(build_dir_one, binaries_dir, dirs_exist_ok=True) |
| 333 | + shutil.copytree(build_dir_two, binaries_dir, dirs_exist_ok=True) |
| 334 | + |
| 335 | + wait_for_board() |
| 336 | + # Verifies upload is successful using the binaries with the same name of the containing folder |
| 337 | + res = run_command(f"upload -b {board.fqbn} -p {board.address} --input-dir {binaries_dir}") |
| 338 | + assert ( |
| 339 | + "Sketches with .pde extension are deprecated, please rename the following files to .ino:" not in res.stderr |
| 340 | + ) |
0 commit comments