Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrate TestUploadWithInputDirContainingMultipleBinaries from test_up…
…load.py to upload_test.go
  • Loading branch information
MatteoPologruto committed Dec 13, 2022
commit a84b98c746af49a684b09531bcba4d697ac6b9f3
59 changes: 59 additions & 0 deletions internal/integrationtest/upload/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,62 @@ func TestUploadSketchWithPdeExtension(t *testing.T) {
require.Contains(t, string(stderr), "Sketches with .pde extension are deprecated, please rename the following files to .ino:")
}
}

func TestUploadWithInputDirContainingMultipleBinaries(t *testing.T) {
if os.Getenv("CI") != "" {
t.Skip("VMs have no serial ports")
}

env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

// This tests verifies the behaviour outlined in this issue:
// https://github.com/arduino/arduino-cli/issues/765#issuecomment-699678646
_, _, err := cli.Run("update")
require.NoError(t, err)

// Create two different sketches
sketchOneName := "UploadMultipleBinariesSketchOne"
sketchOnePath := cli.SketchbookDir().Join(sketchOneName)
_, _, err = cli.Run("sketch", "new", sketchOnePath.String())
require.NoError(t, err)

sketchTwoName := "UploadMultipleBinariesSketchTwo"
sketchTwoPath := cli.SketchbookDir().Join(sketchTwoName)
_, _, err = cli.Run("sketch", "new", sketchTwoPath.String())
require.NoError(t, err)

for _, board := range detectedBoards(t, cli) {
// Install core
_, _, err = cli.Run("core", "install", board.core)
require.NoError(t, err)

// Compile both sketches and copy binaries in the same build directory
binariesDir := cli.SketchbookDir().Join("build", "BuiltBinaries")
_, _, err = cli.Run("compile", "--clean", "-b", board.fqbn, sketchOnePath.String(), "--build-path", binariesDir.String())
require.NoError(t, err)
stdout, _, err := cli.Run("compile", "--clean", "-b", board.fqbn, sketchTwoPath.String(), "--format", "json")
require.NoError(t, err)
buildDirTwo := requirejson.Parse(t, stdout).Query(".builder_result | .build_path").String()
buildDirTwo = strings.Trim(strings.ReplaceAll(buildDirTwo, "\\\\", "\\"), "\"")
require.NoError(t, paths.New(buildDirTwo).Join(sketchTwoName+".ino.bin").CopyTo(binariesDir.Join(sketchTwoName+".ino.bin")))

waitForBoard(t, cli)
// Verifies upload fails because multiple binaries are found
_, stderr, err := cli.Run("upload", "-b", board.fqbn, "-p", board.address, "--input-dir", binariesDir.String())
require.Error(t, err)
require.Contains(t, string(stderr), "Error during Upload: ")
require.Contains(t, string(stderr), "Error finding build artifacts: ")
require.Contains(t, string(stderr), "autodetect build artifact: ")
require.Contains(t, string(stderr), "multiple build artifacts found:")

// Copy binaries to folder with same name of a sketch
binariesDirSketch := cli.SketchbookDir().Join("build", "UploadMultipleBinariesSketchOne")
require.NoError(t, binariesDir.CopyDirTo(binariesDirSketch))

waitForBoard(t, cli)
// Verifies upload is successful using the binaries with the same name of the containing folder
_, _, err = cli.Run("upload", "-b", board.fqbn, "-p", board.address, "--input-dir", binariesDirSketch.String())
require.NoError(t, err)
}
}
59 changes: 0 additions & 59 deletions test/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,65 +42,6 @@ def test_upload_after_attach(run_command, data_dir, detected_boards):
assert run_command(["upload", sketch_path])


def test_upload_with_input_dir_containing_multiple_binaries(run_command, data_dir, detected_boards, wait_for_board):
# This tests verifies the behaviour outlined in this issue:
# https://github.com/arduino/arduino-cli/issues/765#issuecomment-699678646
assert run_command(["update"])

# Create a two different sketches
sketch_one_name = "UploadMultipleBinariesSketchOne"
sketch_one_path = Path(data_dir, sketch_one_name)
assert run_command(["sketch", "new", sketch_one_path])

sketch_two_name = "UploadMultipleBinariesSketchTwo"
sketch_two_path = Path(data_dir, sketch_two_name)
assert run_command(["sketch", "new", sketch_two_path])

for board in detected_boards:
# Install core
core = ":".join(board.fqbn.split(":")[:2])
assert run_command(["core", "install", core])

# Compile both sketches and copy binaries in the same directory same build directory
res = run_command(["compile", "--clean", "-b", board.fqbn, sketch_one_path, "--format", "json"])
assert res.ok
data = json.loads(res.stdout)
build_dir_one = Path(data["builder_result"]["build_path"])
res = run_command(["compile", "--clean", "-b", board.fqbn, sketch_two_path, "--format", "json"])
assert res.ok
data = json.loads(res.stdout)
build_dir_two = Path(data["builder_result"]["build_path"])

# Copy binaries to same folder
binaries_dir = Path(data_dir, "build", "BuiltBinaries")
shutil.copytree(build_dir_one, binaries_dir, dirs_exist_ok=True)
shutil.copytree(build_dir_two, binaries_dir, dirs_exist_ok=True)

wait_for_board()
# Verifies upload fails because multiple binaries are found
res = run_command(["upload", "-b", board.fqbn, "-p", board.address, "--input-dir", binaries_dir])
assert res.failed
assert (
"Error during Upload: "
+ "Error finding build artifacts: "
+ "autodetect build artifact: "
+ "multiple build artifacts found:"
in res.stderr
)

# Copy binaries to folder with same name of a sketch
binaries_dir = Path(data_dir, "build", "UploadMultipleBinariesSketchOne")
shutil.copytree(build_dir_one, binaries_dir, dirs_exist_ok=True)
shutil.copytree(build_dir_two, binaries_dir, dirs_exist_ok=True)

wait_for_board()
# Verifies upload is successful using the binaries with the same name of the containing folder
res = run_command(["upload", "-b", board.fqbn, "-p", board.address, "--input-dir", binaries_dir])
assert (
"Sketches with .pde extension are deprecated, please rename the following files to .ino:" not in res.stderr
)


def test_compile_and_upload_combo_sketch_with_mismatched_casing(run_command, data_dir, detected_boards, wait_for_board):
assert run_command(["update"])

Expand Down