Commit f15a010e authored by David Brown's avatar David Brown Committed by David Brown
Browse files

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: default avatarDavid Brown <david.brown@linaro.org>
parent c997a607
Loading
Loading
Loading
Loading
+25 −8
Changes for samples/zephyr/mcutests/mcutests.go: 25 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -13,8 +13,10 @@ var Tests = []struct {
		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 @@ var Tests = []struct {
		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 @@ var Tests = []struct {
		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 @@ var Tests = []struct {
		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 @@ var Tests = []struct {
		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 @@ var Tests = []struct {
		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 @@ var Tests = []struct {
		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 @@ var Tests = []struct {
		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 @@ var Tests = []struct {
}

type OneTest struct {
	Build    [][]string
	Commands [][]string
	Expect   string
}
+27 −4
Changes for samples/zephyr/run-tests.go: 27 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ var logIn = flag.String("login", "/tmp/zephyr.out", "File name of terminal log f
// 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 @@ func run() error {
		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 @@ func run() error {
	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:]...)