Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
1 change: 1 addition & 0 deletions upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func PartiallyResolve(board, file, platformPath, commandline string, extra Extra
commandline = strings.Replace(commandline, "{build.path}", filepath.ToSlash(filepath.Dir(file)), -1)
commandline = strings.Replace(commandline, "{build.project_name}", strings.TrimSuffix(filepath.Base(file), filepath.Ext(filepath.Base(file))), -1)
commandline = strings.Replace(commandline, "{runtime.platform.path}", filepath.ToSlash(platformPath), -1)
commandline = strings.Replace(commandline, "{fqbn}", board, -1)

// search for runtime variables and replace with values from Locater
var runtimeRe = regexp.MustCompile("\\{(.*?)\\}")
Expand Down
55 changes: 45 additions & 10 deletions upload/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package upload_test
package upload

import (
"log"
"strings"
"testing"

"github.com/arduino/arduino-create-agent/upload"
homedir "github.com/mitchellh/go-homedir"
"github.com/sirupsen/logrus"
)
Expand All @@ -36,11 +35,11 @@ var TestSerialData = []struct {
Name string
Port string
Commandline string
Extra upload.Extra
Extra Extra
}{
{
"leonardo", "/dev/ttyACM0",
`"$HOME/.arduino-create/avrdude/6.3.0-arduino6/bin/avrdude" "-C$HOME/.arduino-create/avrdude/6.3.0-arduino6/etc/avrdude.conf" -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D "-Uflash:w:./upload_test.hex:i"`, upload.Extra{Use1200bpsTouch: true, WaitForUploadPort: true}},
`"$HOME/.arduino-create/avrdude/6.3.0-arduino6/bin/avrdude" "-C$HOME/.arduino-create/avrdude/6.3.0-arduino6/etc/avrdude.conf" -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D "-Uflash:w:./upload_test.hex:i"`, Extra{Use1200bpsTouch: true, WaitForUploadPort: true}},
}

func TestSerial(t *testing.T) {
Expand All @@ -51,7 +50,7 @@ func TestSerial(t *testing.T) {

for _, test := range TestSerialData {
commandline := strings.Replace(test.Commandline, "$HOME", home, -1)
err := upload.Serial(test.Port, commandline, test.Extra, logger)
err := Serial(test.Port, commandline, test.Extra, logger)
log.Println(err)
}
}
Expand All @@ -61,17 +60,53 @@ var TestResolveData = []struct {
File string
PlatformPath string
Commandline string
Extra upload.Extra
Extra Extra
Result string
}{
{"arduino:avr:leonardo", "./upload_test.hex", "",
`"{runtime.tools.avrdude.path}/bin/avrdude" "-C{runtime.tools.avrdude.path}/etc/avrdude.conf" -v {upload.verify} -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"`, upload.Extra{Use1200bpsTouch: true, WaitForUploadPort: true},
`"$loc$loc{runtime.tools.avrdude.path}/bin/avrdude" "-C{runtime.tools.avrdude.path}/etc/avrdude.conf" -v $loc{upload.verify} -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D "-Uflash:w:./upload_test.hex:i"`},
{"arduino:avr:leonardo",
"./upload_test.hex",
"",
`{runtime.tools.avrdude.path}/bin/avrdude -C{runtime.tools.avrdude.path}/etc/avrdude.conf -v {upload.verify} -patmega32u4 -cavr109 -P{serial.port} -b57600 -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"`,
Extra{Use1200bpsTouch: true, WaitForUploadPort: true},
`$loc$loc{runtime.tools.avrdude.path}/bin/avrdude -C{runtime.tools.avrdude.path}/etc/avrdude.conf -v $loc{upload.verify} -patmega32u4 -cavr109 -P$loc{serial.port} -b57600 -D "-Uflash:w:./upload_test.hex:i"`,
},
{"arduino:renesas_uno:unor4wifi",
"UpdateFirmware.bin",
"",
`{runtime.tools.arduino-fwuploader.path}/arduino-fwuploader firmware flash -a {serial.port} -b {fqbn} -v --retries 5"`,
Extra{Use1200bpsTouch: true, WaitForUploadPort: true},
`$loc{runtime.tools.arduino-fwuploader.path}/arduino-fwuploader firmware flash -a $loc{serial.port} -b arduino:renesas_uno:unor4wifi -v --retries 5"`,
},
}

func TestResolve(t *testing.T) {
for _, test := range TestResolveData {
result, _ := upload.PartiallyResolve(test.Board, test.File, test.PlatformPath, test.Commandline, test.Extra, mockTools{})
result, _ := PartiallyResolve(test.Board, test.File, test.PlatformPath, test.Commandline, test.Extra, mockTools{})
if result != test.Result {
t.Error("expected " + test.Result + ", got " + result)
continue
}
}
}

var TestFixupData = []struct {
Port string
Commandline string
Result string
}{
{"/dev/ttyACM0",
`{runtime.tools.avrdude.path}/bin/avrdude -C{runtime.tools.avrdude.path}/etc/avrdude.conf -v {upload.verify} -patmega32u4 -cavr109 -P{serial.port} -b57600 -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"`,
`{runtime.tools.avrdude.path}/bin/avrdude -C{runtime.tools.avrdude.path}/etc/avrdude.conf -v {upload.verify} -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"`,
},
{"/dev/cu.usbmodemDC5475C5557C2",
`{runtime.tools.arduino-fwuploader.path}/arduino-fwuploader firmware flash -a {serial.port} -b arduino:renesas_uno:unor4wifi -v --retries 5"`,
`{runtime.tools.arduino-fwuploader.path}/arduino-fwuploader firmware flash -a /dev/cu.usbmodemDC5475C5557C2 -b arduino:renesas_uno:unor4wifi -v --retries 5"`,
},
}

func TestFixupPort(t *testing.T) {
for _, test := range TestFixupData {
result := fixupPort(test.Port, test.Commandline)
if result != test.Result {
t.Error("expected " + test.Result + ", got " + result)
continue
Expand Down