samples: zephyr: Separate build commands
Instead of just having the build commands part of the test execution,
separate them into a separate value. This will facilitate having an
option that doesn't actually build the tests, but extracts them from an
archive.
Signed-off-by: David Brown <david.brown@linaro.org>
diff --git a/samples/zephyr/mcutests/mcutests.go b/samples/zephyr/mcutests/mcutests.go
index bd26a53..159ab77 100644
--- a/samples/zephyr/mcutests/mcutests.go
+++ b/samples/zephyr/mcutests/mcutests.go
@@ -13,8 +13,10 @@
ShortName: "good-rsa",
Tests: []OneTest{
{
- Commands: [][]string{
+ Build: [][]string{
{"make", "test-good-rsa"},
+ },
+ Commands: [][]string{
{"make", "flash_boot"},
},
Expect: "Unable to find bootable image",
@@ -44,8 +46,10 @@
ShortName: "good-ecdsa",
Tests: []OneTest{
{
- Commands: [][]string{
+ Build: [][]string{
{"make", "test-good-ecdsa"},
+ },
+ Commands: [][]string{
{"make", "flash_boot"},
},
Expect: "Unable to find bootable image",
@@ -75,8 +79,10 @@
ShortName: "overwrite",
Tests: []OneTest{
{
- Commands: [][]string{
+ Build: [][]string{
{"make", "test-overwrite"},
+ },
+ Commands: [][]string{
{"make", "flash_boot"},
},
Expect: "Unable to find bootable image",
@@ -106,8 +112,10 @@
ShortName: "bad-rsa-upgrade",
Tests: []OneTest{
{
- Commands: [][]string{
+ Build: [][]string{
{"make", "test-bad-rsa-upgrade"},
+ },
+ Commands: [][]string{
{"make", "flash_boot"},
},
Expect: "Unable to find bootable image",
@@ -137,8 +145,10 @@
ShortName: "bad-ecdsa-upgrade",
Tests: []OneTest{
{
- Commands: [][]string{
+ Build: [][]string{
{"make", "test-bad-ecdsa-upgrade"},
+ },
+ Commands: [][]string{
{"make", "flash_boot"},
},
Expect: "Unable to find bootable image",
@@ -168,8 +178,10 @@
ShortName: "no-bootcheck",
Tests: []OneTest{
{
- Commands: [][]string{
+ Build: [][]string{
{"make", "test-no-bootcheck"},
+ },
+ Commands: [][]string{
{"make", "flash_boot"},
},
Expect: "Unable to find bootable image",
@@ -199,8 +211,10 @@
ShortName: "wrong-rsa",
Tests: []OneTest{
{
- Commands: [][]string{
+ Build: [][]string{
{"make", "test-wrong-rsa"},
+ },
+ Commands: [][]string{
{"make", "flash_boot"},
},
Expect: "Unable to find bootable image",
@@ -230,8 +244,10 @@
ShortName: "wrong-ecdsa",
Tests: []OneTest{
{
- Commands: [][]string{
+ Build: [][]string{
{"make", "test-wrong-ecdsa"},
+ },
+ Commands: [][]string{
{"make", "flash_boot"},
},
Expect: "Unable to find bootable image",
@@ -259,6 +275,7 @@
}
type OneTest struct {
+ Build [][]string
Commands [][]string
Expect string
}
diff --git a/samples/zephyr/run-tests.go b/samples/zephyr/run-tests.go
index 9b57664..8124f9f 100644
--- a/samples/zephyr/run-tests.go
+++ b/samples/zephyr/run-tests.go
@@ -41,6 +41,8 @@
// Output from this test run is written to the given log file.
var logOut = flag.String("logout", "tests.log", "Log file to write to")
+var preBuilt = flag.String("prebuilt", "", "Name of file with prebuilt tests")
+
func main() {
err := run()
if err != nil {
@@ -69,13 +71,20 @@
fmt.Fprintf(lg, "---- Running %q\n", group.Name)
for _, test := range group.Tests {
- for _, cmd := range test.Commands {
- fmt.Printf(" %s\n", cmd)
- fmt.Fprintf(lg, "---- Run: %s\n", cmd)
- err = runCommand(cmd, lg)
+ if *preBuilt == "" {
+ // No prebuilt, build the tests
+ // ourselves.
+ err = runCommands(test.Build, lg)
if err != nil {
return err
}
+ } else {
+ panic("TODO")
+ }
+
+ err = runCommands(test.Commands, lg)
+ if err != nil {
+ return err
}
err = expect(lg, lines, test.Expect)
@@ -91,6 +100,20 @@
return nil
}
+// Run a set of commands
+func runCommands(cmds [][]string, lg io.Writer) error {
+ for _, cmd := range cmds {
+ fmt.Printf(" %s\n", cmd)
+ fmt.Fprintf(lg, "---- Run: %s\n", cmd)
+ err := runCommand(cmd, lg)
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
// Run a single command.
func runCommand(cmd []string, lg io.Writer) error {
c := exec.Command(cmd[0], cmd[1:]...)