From 8864e5a8bbc24fa9ecc3b211c45202e79f0a98cd Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 30 Oct 2023 16:52:50 +0100 Subject: [PATCH 1/3] debug: Enforce programmer selection --- commands/debug/debug_info.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/commands/debug/debug_info.go b/commands/debug/debug_info.go index a8731ab1d6a..e32927907b1 100644 --- a/commands/debug/debug_info.go +++ b/commands/debug/debug_info.go @@ -108,14 +108,15 @@ func getDebugProperties(req *rpc.GetDebugConfigRequest, pme *packagemanager.Expl } } - if req.GetProgrammer() != "" { - if p, ok := platformRelease.Programmers[req.GetProgrammer()]; ok { - toolProperties.Merge(p.Properties) - } else if refP, ok := referencedPlatformRelease.Programmers[req.GetProgrammer()]; ok { - toolProperties.Merge(refP.Properties) - } else { - return nil, &arduino.ProgrammerNotFoundError{Programmer: req.GetProgrammer()} - } + if req.GetProgrammer() == "" { + return nil, &arduino.MissingProgrammerError{} + } + if p, ok := platformRelease.Programmers[req.GetProgrammer()]; ok { + toolProperties.Merge(p.Properties) + } else if refP, ok := referencedPlatformRelease.Programmers[req.GetProgrammer()]; ok { + toolProperties.Merge(refP.Properties) + } else { + return nil, &arduino.ProgrammerNotFoundError{Programmer: req.GetProgrammer()} } var importPath *paths.Path From d0af3b2778c291fa29fb98635e636714c8a49154 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 30 Oct 2023 18:13:43 +0100 Subject: [PATCH 2/3] Fixed unit tests --- commands/debug/debug_test.go | 9 +++++++++ .../custom_hardware/arduino-test/samd/programmers.txt | 1 + 2 files changed, 10 insertions(+) create mode 100644 commands/debug/testdata/custom_hardware/arduino-test/samd/programmers.txt diff --git a/commands/debug/debug_test.go b/commands/debug/debug_test.go index 0b99a105c64..905820bbda3 100644 --- a/commands/debug/debug_test.go +++ b/commands/debug/debug_test.go @@ -63,6 +63,14 @@ func TestGetCommandLine(t *testing.T) { pm := pmb.Build() pme, release := pm.NewExplorer() defer release() + + { + // Check programmer required + _, err := getCommandLine(req, pme) + require.Error(t, err) + } + + req.Programmer = "edbg" command, err := getCommandLine(req, pme) require.Nil(t, err) commandToTest := strings.Join(command, " ") @@ -76,6 +84,7 @@ func TestGetCommandLine(t *testing.T) { SketchPath: sketchPath.String(), Interpreter: "mi1", ImportDir: sketchPath.Join("build", "arduino-test.samd.mkr1000").String(), + Programmer: "edbg", } goldCommand2 := fmt.Sprintf("%s/arduino-test/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-gdb%s", dataDir, toolExtension) + diff --git a/commands/debug/testdata/custom_hardware/arduino-test/samd/programmers.txt b/commands/debug/testdata/custom_hardware/arduino-test/samd/programmers.txt new file mode 100644 index 00000000000..332ca0d5c51 --- /dev/null +++ b/commands/debug/testdata/custom_hardware/arduino-test/samd/programmers.txt @@ -0,0 +1 @@ +edbg.name=edbg From ad261d62a2747fb8d98bcaabdc5cd625cc35d654 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 31 Oct 2023 00:11:05 +0100 Subject: [PATCH 3/3] Increase code coverage --- commands/debug/debug_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/commands/debug/debug_test.go b/commands/debug/debug_test.go index 905820bbda3..c140a380a6c 100644 --- a/commands/debug/debug_test.go +++ b/commands/debug/debug_test.go @@ -70,6 +70,13 @@ func TestGetCommandLine(t *testing.T) { require.Error(t, err) } + { + // Check programmer not found + req.Programmer = "not-existent" + _, err := getCommandLine(req, pme) + require.Error(t, err) + } + req.Programmer = "edbg" command, err := getCommandLine(req, pme) require.Nil(t, err)