From b65df52c79adf0168144db88a79b7c007b5890a3 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 31 Oct 2023 12:31:57 +0100 Subject: [PATCH] debug: Enforce programmer selection (#2394) * debug: Enforce programmer selection * Fixed unit tests * Increase code coverage --- commands/debug/debug_info.go | 17 +++++++++-------- commands/debug/debug_test.go | 16 ++++++++++++++++ .../arduino-test/samd/programmers.txt | 1 + 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 commands/debug/testdata/custom_hardware/arduino-test/samd/programmers.txt 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 diff --git a/commands/debug/debug_test.go b/commands/debug/debug_test.go index 0b99a105c64..c140a380a6c 100644 --- a/commands/debug/debug_test.go +++ b/commands/debug/debug_test.go @@ -63,6 +63,21 @@ 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) + } + + { + // 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) commandToTest := strings.Join(command, " ") @@ -76,6 +91,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