Commit 5e8dbb99 authored by David Brown's avatar David Brown Committed by David Brown
Browse files

samples: zephyr: Split out tests from test runner

Move the list of tests to run from the test runner itself into its own
package.  The test can be invoked the same way (Go will find the go.mod
at the top of mcuboot), but this will make it easier to separate a test
runner from a test builder.

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent d662caac
Loading
Loading
Loading
Loading
+255 −0
Changes for samples/zephyr/mcutests/mcutests.go: 255 added lines, 0 removed lines.
Original line number Diff line number Diff line
// Package mcutests
package mcutests // github.com/JuulLabs-OSS/mcuboot/samples/zephyr/mcutests

// The main driver of this consists of a series of tests.  Each test
// then contains a series of commands and expect results.
var Tests = []struct {
	Name  string
	Tests []OneTest
}{
	{
		Name: "Good RSA",
		Tests: []OneTest{
			{
				Commands: [][]string{
					{"make", "test-good-rsa"},
					{"make", "flash_boot"},
				},
				Expect: "Unable to find bootable image",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello1"},
				},
				Expect: "Hello World from hello1",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello2"},
				},
				Expect: "Hello World from hello2",
			},
			{
				Commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				Expect: "Hello World from hello1",
			},
		},
	},
	{
		Name: "Good ECDSA",
		Tests: []OneTest{
			{
				Commands: [][]string{
					{"make", "test-good-ecdsa"},
					{"make", "flash_boot"},
				},
				Expect: "Unable to find bootable image",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello1"},
				},
				Expect: "Hello World from hello1",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello2"},
				},
				Expect: "Hello World from hello2",
			},
			{
				Commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				Expect: "Hello World from hello1",
			},
		},
	},
	{
		Name: "Overwrite",
		Tests: []OneTest{
			{
				Commands: [][]string{
					{"make", "test-overwrite"},
					{"make", "flash_boot"},
				},
				Expect: "Unable to find bootable image",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello1"},
				},
				Expect: "Hello World from hello1",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello2"},
				},
				Expect: "Hello World from hello2",
			},
			{
				Commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				Expect: "Hello World from hello2",
			},
		},
	},
	{
		Name: "Bad RSA",
		Tests: []OneTest{
			{
				Commands: [][]string{
					{"make", "test-bad-rsa-upgrade"},
					{"make", "flash_boot"},
				},
				Expect: "Unable to find bootable image",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello1"},
				},
				Expect: "Hello World from hello1",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello2"},
				},
				Expect: "Hello World from hello1",
			},
			{
				Commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				Expect: "Hello World from hello1",
			},
		},
	},
	{
		Name: "Bad RSA",
		Tests: []OneTest{
			{
				Commands: [][]string{
					{"make", "test-bad-ecdsa-upgrade"},
					{"make", "flash_boot"},
				},
				Expect: "Unable to find bootable image",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello1"},
				},
				Expect: "Hello World from hello1",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello2"},
				},
				Expect: "Hello World from hello1",
			},
			{
				Commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				Expect: "Hello World from hello1",
			},
		},
	},
	{
		Name: "No bootcheck",
		Tests: []OneTest{
			{
				Commands: [][]string{
					{"make", "test-no-bootcheck"},
					{"make", "flash_boot"},
				},
				Expect: "Unable to find bootable image",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello1"},
				},
				Expect: "Hello World from hello1",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello2"},
				},
				Expect: "Hello World from hello1",
			},
			{
				Commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				Expect: "Hello World from hello1",
			},
		},
	},
	{
		Name: "Wrong RSA",
		Tests: []OneTest{
			{
				Commands: [][]string{
					{"make", "test-wrong-rsa"},
					{"make", "flash_boot"},
				},
				Expect: "Unable to find bootable image",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello1"},
				},
				Expect: "Hello World from hello1",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello2"},
				},
				Expect: "Hello World from hello1",
			},
			{
				Commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				Expect: "Hello World from hello1",
			},
		},
	},
	{
		Name: "Wrong ECDSA",
		Tests: []OneTest{
			{
				Commands: [][]string{
					{"make", "test-wrong-ecdsa"},
					{"make", "flash_boot"},
				},
				Expect: "Unable to find bootable image",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello1"},
				},
				Expect: "Hello World from hello1",
			},
			{
				Commands: [][]string{
					{"make", "flash_hello2"},
				},
				Expect: "Hello World from hello1",
			},
			{
				Commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				Expect: "Hello World from hello1",
			},
		},
	},
}

type OneTest struct {
	Commands [][]string
	Expect   string
}
+8 −259
Changes for samples/zephyr/run-tests.go: 8 added lines, 259 removed lines.
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import (
	"os/exec"
	"strings"
	"time"

	"github.com/JuulLabs-OSS/mcuboot/samples/zephyr/mcutests"
)

// logIn gives the pathname of the log output from the Zephyr device.
@@ -39,259 +41,6 @@ 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")

// The main driver of this consists of a series of tests.  Each test
// then contains a series of commands and expect results.
var tests = []struct {
	name  string
	tests []oneTest
}{
	{
		name: "Good RSA",
		tests: []oneTest{
			{
				commands: [][]string{
					{"make", "test-good-rsa"},
					{"make", "flash_boot"},
				},
				expect: "Unable to find bootable image",
			},
			{
				commands: [][]string{
					{"make", "flash_hello1"},
				},
				expect: "Hello World from hello1",
			},
			{
				commands: [][]string{
					{"make", "flash_hello2"},
				},
				expect: "Hello World from hello2",
			},
			{
				commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				expect: "Hello World from hello1",
			},
		},
	},
	{
		name: "Good ECDSA",
		tests: []oneTest{
			{
				commands: [][]string{
					{"make", "test-good-ecdsa"},
					{"make", "flash_boot"},
				},
				expect: "Unable to find bootable image",
			},
			{
				commands: [][]string{
					{"make", "flash_hello1"},
				},
				expect: "Hello World from hello1",
			},
			{
				commands: [][]string{
					{"make", "flash_hello2"},
				},
				expect: "Hello World from hello2",
			},
			{
				commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				expect: "Hello World from hello1",
			},
		},
	},
	{
		name: "Overwrite",
		tests: []oneTest{
			{
				commands: [][]string{
					{"make", "test-overwrite"},
					{"make", "flash_boot"},
				},
				expect: "Unable to find bootable image",
			},
			{
				commands: [][]string{
					{"make", "flash_hello1"},
				},
				expect: "Hello World from hello1",
			},
			{
				commands: [][]string{
					{"make", "flash_hello2"},
				},
				expect: "Hello World from hello2",
			},
			{
				commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				expect: "Hello World from hello2",
			},
		},
	},
	{
		name: "Bad RSA",
		tests: []oneTest{
			{
				commands: [][]string{
					{"make", "test-bad-rsa-upgrade"},
					{"make", "flash_boot"},
				},
				expect: "Unable to find bootable image",
			},
			{
				commands: [][]string{
					{"make", "flash_hello1"},
				},
				expect: "Hello World from hello1",
			},
			{
				commands: [][]string{
					{"make", "flash_hello2"},
				},
				expect: "Hello World from hello1",
			},
			{
				commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				expect: "Hello World from hello1",
			},
		},
	},
	{
		name: "Bad RSA",
		tests: []oneTest{
			{
				commands: [][]string{
					{"make", "test-bad-ecdsa-upgrade"},
					{"make", "flash_boot"},
				},
				expect: "Unable to find bootable image",
			},
			{
				commands: [][]string{
					{"make", "flash_hello1"},
				},
				expect: "Hello World from hello1",
			},
			{
				commands: [][]string{
					{"make", "flash_hello2"},
				},
				expect: "Hello World from hello1",
			},
			{
				commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				expect: "Hello World from hello1",
			},
		},
	},
	{
		name: "No bootcheck",
		tests: []oneTest{
			{
				commands: [][]string{
					{"make", "test-no-bootcheck"},
					{"make", "flash_boot"},
				},
				expect: "Unable to find bootable image",
			},
			{
				commands: [][]string{
					{"make", "flash_hello1"},
				},
				expect: "Hello World from hello1",
			},
			{
				commands: [][]string{
					{"make", "flash_hello2"},
				},
				expect: "Hello World from hello1",
			},
			{
				commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				expect: "Hello World from hello1",
			},
		},
	},
	{
		name: "Wrong RSA",
		tests: []oneTest{
			{
				commands: [][]string{
					{"make", "test-wrong-rsa"},
					{"make", "flash_boot"},
				},
				expect: "Unable to find bootable image",
			},
			{
				commands: [][]string{
					{"make", "flash_hello1"},
				},
				expect: "Hello World from hello1",
			},
			{
				commands: [][]string{
					{"make", "flash_hello2"},
				},
				expect: "Hello World from hello1",
			},
			{
				commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				expect: "Hello World from hello1",
			},
		},
	},
	{
		name: "Wrong ECDSA",
		tests: []oneTest{
			{
				commands: [][]string{
					{"make", "test-wrong-ecdsa"},
					{"make", "flash_boot"},
				},
				expect: "Unable to find bootable image",
			},
			{
				commands: [][]string{
					{"make", "flash_hello1"},
				},
				expect: "Hello World from hello1",
			},
			{
				commands: [][]string{
					{"make", "flash_hello2"},
				},
				expect: "Hello World from hello1",
			},
			{
				commands: [][]string{
					{"pyocd", "commander", "-c", "reset"},
				},
				expect: "Hello World from hello1",
			},
		},
	},
}

type oneTest struct {
	commands [][]string
	expect   string
}

func main() {
	err := run()
	if err != nil {
@@ -314,13 +63,13 @@ func run() error {
	lg := bufio.NewWriter(logFile)
	defer lg.Flush()

	for _, group := range tests {
		fmt.Printf("Running %q\n", group.name)
	for _, group := range mcutests.Tests {
		fmt.Printf("Running %q\n", group.Name)
		fmt.Fprintf(lg, "-------------------------------------\n")
		fmt.Fprintf(lg, "---- Running %q\n", group.name)
		fmt.Fprintf(lg, "---- Running %q\n", group.Name)

		for _, test := range group.tests {
			for _, cmd := range test.commands {
		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)
@@ -329,7 +78,7 @@ func run() error {
				}
			}

			err = expect(lg, lines, test.expect)
			err = expect(lg, lines, test.Expect)
			if err != nil {
				return err
			}