1212// modify or otherwise use the software for commercial activities involving the
1313// Arduino software without disclosing the source code of your own applications.
1414// To purchase a commercial license, send an email to license@arduino.cc.
15-
1615package debug
1716
1817import (
1918 "fmt"
19+ "runtime"
2020 "strings"
2121 "testing"
2222
@@ -29,7 +29,7 @@ import (
2929var customHardware = paths .New ("testdata" , "custom_hardware" )
3030var dataDir = paths .New ("testdata" , "data_dir" , "packages" )
3131var sketch = "hello"
32- var sketchPath = paths .New ("testdata" , sketch ). String ()
32+ var sketchPath = paths .New ("testdata" , sketch )
3333
3434func TestGetCommandLine (t * testing.T ) {
3535 pm := packagemanager .NewPackageManager (nil , nil , nil , nil )
@@ -40,52 +40,56 @@ func TestGetCommandLine(t *testing.T) {
4040 req := & dbg.DebugConfigReq {
4141 Instance : & dbg.Instance {Id : 1 },
4242 Fqbn : "arduino-test:samd:arduino_zero_edbg" ,
43- SketchPath : sketchPath ,
43+ SketchPath : sketchPath . String () ,
4444 Port : "none" ,
4545 }
46- packageName := strings .Split (req .Fqbn , ":" )[0 ]
47- processor := strings .Split (req .Fqbn , ":" )[1 ]
48- // This boardFamily variable is necessary for this particular board as it is represented in the core as 2 separated
49- // boards, to expose the programming port and the debug (edbg) port. So we point at the same openocd configuration
50- // variant for upload in both cases
51- boardFamily := "arduino_zero"
5246
53- goldCommand := []string {
54- fmt .Sprintf ("%s/%s/tools/arm-none-eabi-gcc/7-2017q4/bin//arm-none-eabi-gdb" , dataDir , packageName ),
55- fmt .Sprintf ("-ex" ),
56- fmt .Sprintf ("target extended-remote | %s/%s/tools/openocd/0.10.0-arduino7/bin/openocd" , dataDir , packageName ) + " " +
57- fmt .Sprintf ("-s \" %s/%s/tools/openocd/0.10.0-arduino7/share/openocd/scripts/\" " , dataDir , packageName ) + " " +
58- fmt .Sprintf ("--file \" %s/%s/%s/variants/%s/openocd_scripts/arduino_zero.cfg\" -c \" gdb_port pipe\" -c \" telnet_port 0\" -c init -c halt" , customHardware , packageName , processor , boardFamily ),
59- fmt .Sprintf ("%s/%s.%s.elf" , sketchPath , sketch , strings .ReplaceAll (req .Fqbn , ":" , "." )),
47+ goldCommand := fmt .Sprintf ("%s/arduino-test/tools/arm-none-eabi-gcc/7-2017q4/bin//arm-none-eabi-gdb" , dataDir ) +
48+ " -ex target extended-remote |" +
49+ fmt .Sprintf (" %s/arduino-test/tools/openocd/0.10.0-arduino7/bin/openocd" , dataDir ) +
50+ fmt .Sprintf (" -s \" %s/arduino-test/tools/openocd/0.10.0-arduino7/share/openocd/scripts/\" " , dataDir ) +
51+ fmt .Sprintf (" --file \" %s/arduino-test/samd/variants/arduino_zero/openocd_scripts/arduino_zero.cfg\" " , customHardware ) +
52+ fmt .Sprintf (" -c \" gdb_port pipe\" -c \" telnet_port 0\" -c init -c halt %s/hello.arduino-test.samd.arduino_zero_edbg.elf" , sketchPath )
53+
54+ if runtime .GOOS == "windows" {
55+ goldCommand = fmt .Sprintf ("%s\\ arduino-test\\ tools\\ arm-none-eabi-gcc\\ 7-2017q4/bin//arm-none-eabi-gdb.exe" , dataDir ) +
56+ " -ex target extended-remote |" +
57+ fmt .Sprintf (" %s\\ arduino-test\\ tools\\ openocd\\ 0.10.0-arduino7/bin/openocd.exe" , dataDir ) +
58+ fmt .Sprintf (" -s \" %s\\ arduino-test\\ tools\\ openocd\\ 0.10.0-arduino7/share/openocd/scripts/\" " , dataDir ) +
59+ fmt .Sprintf (" --file \" %s\\ arduino-test\\ samd/variants/arduino_zero/openocd_scripts/arduino_zero.cfg\" " , customHardware ) +
60+ fmt .Sprintf (" -c \" gdb_port pipe\" -c \" telnet_port 0\" -c init -c halt %s/hello.arduino-test.samd.arduino_zero_edbg.elf" , sketchPath )
6061 }
6162
6263 command , err := getCommandLine (req , pm )
6364 assert .Nil (t , err )
64- assert .Equal (t , goldCommand , command )
65+ assert .Equal (t , goldCommand , strings . Join ( command [:], " " ) )
6566
6667 // Other samd boards such as mkr1000 can be debugged using an external tool such as Atmel ICE connected to
6768 // the board debug port
6869 req2 := & dbg.DebugConfigReq {
6970 Instance : & dbg.Instance {Id : 1 },
7071 Fqbn : "arduino-test:samd:mkr1000" ,
71- SketchPath : sketchPath ,
72+ SketchPath : sketchPath . String () ,
7273 Port : "none" ,
7374 }
74- packageName2 := strings .Split (req2 .Fqbn , ":" )[0 ]
75- processor2 := strings .Split (req2 .Fqbn , ":" )[1 ]
76- name2 := strings .Split (req2 .Fqbn , ":" )[2 ]
7775
78- goldCommand2 := []string {
79- fmt .Sprintf ("%s/%s/tools/arm-none-eabi-gcc/7-2017q4/bin//arm-none-eabi-gdb" , dataDir , packageName2 ),
80- fmt .Sprintf ("-ex" ),
81- fmt .Sprintf ("target extended-remote | %s/%s/tools/openocd/0.10.0-arduino7/bin/openocd" , dataDir , packageName2 ) + " " +
82- fmt .Sprintf ("-s \" %s/%s/tools/openocd/0.10.0-arduino7/share/openocd/scripts/\" " , dataDir , packageName2 ) + " " +
83- fmt .Sprintf ("--file \" %s/%s/%s/variants/%s/openocd_scripts/arduino_zero.cfg\" -c \" gdb_port pipe\" -c \" telnet_port 0\" -c init -c halt" , customHardware , packageName2 , processor2 , name2 ),
84- fmt .Sprintf ("%s/%s.%s.elf" , sketchPath , sketch , strings .ReplaceAll (req2 .Fqbn , ":" , "." )),
76+ goldCommand2 := fmt .Sprintf ("%s/arduino-test/tools/arm-none-eabi-gcc/7-2017q4/bin//arm-none-eabi-gdb" , dataDir ) +
77+ " -ex target extended-remote |" +
78+ fmt .Sprintf (" %s/arduino-test/tools/openocd/0.10.0-arduino7/bin/openocd" , dataDir ) +
79+ fmt .Sprintf (" -s \" %s/arduino-test/tools/openocd/0.10.0-arduino7/share/openocd/scripts/\" " , dataDir ) +
80+ fmt .Sprintf (" --file \" %s/arduino-test/samd/variants/mkr1000/openocd_scripts/arduino_zero.cfg\" " , customHardware ) +
81+ fmt .Sprintf (" -c \" gdb_port pipe\" -c \" telnet_port 0\" -c init -c halt %s/hello.arduino-test.samd.mkr1000.elf" , sketchPath )
82+
83+ if runtime .GOOS == "windows" {
84+ goldCommand2 = fmt .Sprintf ("%s\\ arduino-test\\ tools\\ arm-none-eabi-gcc\\ 7-2017q4/bin//arm-none-eabi-gdb.exe" , dataDir ) +
85+ " -ex target extended-remote |" +
86+ fmt .Sprintf (" %s\\ arduino-test\\ tools\\ openocd\\ 0.10.0-arduino7/bin/openocd.exe" , dataDir ) +
87+ fmt .Sprintf (" -s \" %s\\ arduino-test\\ tools\\ openocd\\ 0.10.0-arduino7/share/openocd/scripts/\" " , dataDir ) +
88+ fmt .Sprintf (" --file \" %s\\ arduino-test\\ samd/variants/mkr1000/openocd_scripts/arduino_zero.cfg\" " , customHardware ) +
89+ fmt .Sprintf (" -c \" gdb_port pipe\" -c \" telnet_port 0\" -c init -c halt %s/hello.arduino-test.samd.mkr1000.elf" , sketchPath )
8590 }
8691
8792 command2 , err := getCommandLine (req2 , pm )
8893 assert .Nil (t , err )
89- assert .Equal (t , goldCommand2 , command2 )
90-
94+ assert .Equal (t , goldCommand2 , strings .Join (command2 [:], " " ))
9195}
0 commit comments