From 2b5cc5da3ea1f8898cb29c60ee6b2fd67bc437a4 Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Thu, 31 Mar 2022 19:31:14 +0100 Subject: [PATCH] arm/oeqa: add basic runfvp test cases Add rudimentary but functional test cases for runfvp. Signed-off-by: Ross Burton Signed-off-by: Jon Mason --- meta-arm/lib/oeqa/selftest/cases/runfvp.py | 51 +++++++++++++++++++ .../oeqa/selftest/cases/tests/auto-basic.json | 3 ++ .../oeqa/selftest/cases/tests/auto-basic.sh | 11 ++++ .../selftest/cases/tests/auto-parameters.json | 7 +++ .../lib/oeqa/selftest/cases/tests/mock-fvp.py | 22 ++++++++ .../selftest/cases/tests/test-parameter.json | 6 +++ .../selftest/cases/tests/test-parameters.py | 1 + 7 files changed, 101 insertions(+) create mode 100644 meta-arm/lib/oeqa/selftest/cases/runfvp.py create mode 100644 meta-arm/lib/oeqa/selftest/cases/tests/auto-basic.json create mode 100755 meta-arm/lib/oeqa/selftest/cases/tests/auto-basic.sh create mode 100644 meta-arm/lib/oeqa/selftest/cases/tests/auto-parameters.json create mode 100755 meta-arm/lib/oeqa/selftest/cases/tests/mock-fvp.py create mode 100644 meta-arm/lib/oeqa/selftest/cases/tests/test-parameter.json create mode 120000 meta-arm/lib/oeqa/selftest/cases/tests/test-parameters.py diff --git a/meta-arm/lib/oeqa/selftest/cases/runfvp.py b/meta-arm/lib/oeqa/selftest/cases/runfvp.py new file mode 100644 index 00000000..5b06ca8e --- /dev/null +++ b/meta-arm/lib/oeqa/selftest/cases/runfvp.py @@ -0,0 +1,51 @@ +import os +import pathlib +import subprocess + +from oeqa.selftest.case import OESelftestTestCase + +runfvp = pathlib.Path(__file__).parents[5] / "scripts" / "runfvp" +testdir = pathlib.Path(__file__).parent / "tests" + +class RunFVPTests(OESelftestTestCase): + def setUpLocal(self): + self.assertTrue(runfvp.exists()) + + def run_fvp(self, *args, should_succeed=True): + """ + Call runfvp passing any arguments. If check is True verify return stdout + on exit code 0 or fail the test, otherwise return the CompletedProcess + instance. + """ + # Put the test directory in PATH so that any mock FVPs are found first + newenv = {"PATH": str(testdir) + ":" + os.environ["PATH"]} + cli = [runfvp,] + list(args) + print(f"Calling {cli}") + ret = subprocess.run(cli, env=newenv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) + if should_succeed: + self.assertEqual(ret.returncode, 0, f"runfvp exit {ret.returncode}, output: {ret.stdout}") + return ret.stdout + else: + self.assertNotEqual(ret.returncode, 0, f"runfvp exit {ret.returncode}, output: {ret.stdout}") + return ret.stdout + + def test_help(self): + output = self.run_fvp("--help") + self.assertIn("Run images in a FVP", output) + + def test_bad_options(self): + self.run_fvp("--this-is-an-invalid-option", should_succeed=False) + + def test_run_auto_tests(self): + newenv = {"PATH": str(testdir) + ":" + os.environ["PATH"]} + + cases = list(testdir.glob("auto-*.json")) + if not cases: + self.fail("No tests found") + for case in cases: + with self.subTest(case=case.stem): + self.run_fvp(case) + + def test_fvp_options(self): + # test-parameter sets one argument, add another manually + self.run_fvp(testdir / "test-parameter.json", "--", "--parameter", "board.dog=woof") diff --git a/meta-arm/lib/oeqa/selftest/cases/tests/auto-basic.json b/meta-arm/lib/oeqa/selftest/cases/tests/auto-basic.json new file mode 100644 index 00000000..476eb572 --- /dev/null +++ b/meta-arm/lib/oeqa/selftest/cases/tests/auto-basic.json @@ -0,0 +1,3 @@ +{ + "exe": "auto-basic.sh" +} diff --git a/meta-arm/lib/oeqa/selftest/cases/tests/auto-basic.sh b/meta-arm/lib/oeqa/selftest/cases/tests/auto-basic.sh new file mode 100755 index 00000000..ea9abac1 --- /dev/null +++ b/meta-arm/lib/oeqa/selftest/cases/tests/auto-basic.sh @@ -0,0 +1,11 @@ +#! /bin/sh + +set -e -u + +if [ $# = 0 ]; then + echo No arguments as expected + exit 0 +else + echo Unexpected arguments: $* + exit 1 +fi diff --git a/meta-arm/lib/oeqa/selftest/cases/tests/auto-parameters.json b/meta-arm/lib/oeqa/selftest/cases/tests/auto-parameters.json new file mode 100644 index 00000000..0c7d4ef9 --- /dev/null +++ b/meta-arm/lib/oeqa/selftest/cases/tests/auto-parameters.json @@ -0,0 +1,7 @@ +{ + "exe": "test-parameters.py", + "parameters": { + "board.cow": "moo", + "board.dog": "woof" + } +} diff --git a/meta-arm/lib/oeqa/selftest/cases/tests/mock-fvp.py b/meta-arm/lib/oeqa/selftest/cases/tests/mock-fvp.py new file mode 100755 index 00000000..2213c9f0 --- /dev/null +++ b/meta-arm/lib/oeqa/selftest/cases/tests/mock-fvp.py @@ -0,0 +1,22 @@ +#! /usr/bin/env python3 + +import argparse +import sys + +def do_test_parameters(args): + if not args.parameter or set(args.parameter) != set(("board.cow=moo", "board.dog=woof")): + print(f"Unexpected arguments: {args}") + sys.exit(1) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("-C", "--parameter", action="append") + args = parser.parse_args() + + function = "do_" + parser.prog.replace("-", "_").replace(".py", "") + if function in locals(): + locals()[function](args) + else: + print(f"Unknown mock mode {parser.prog}") + sys.exit(1) diff --git a/meta-arm/lib/oeqa/selftest/cases/tests/test-parameter.json b/meta-arm/lib/oeqa/selftest/cases/tests/test-parameter.json new file mode 100644 index 00000000..9b565f27 --- /dev/null +++ b/meta-arm/lib/oeqa/selftest/cases/tests/test-parameter.json @@ -0,0 +1,6 @@ +{ + "exe": "test-parameters.py", + "parameters": { + "board.cow": "moo" + } +} diff --git a/meta-arm/lib/oeqa/selftest/cases/tests/test-parameters.py b/meta-arm/lib/oeqa/selftest/cases/tests/test-parameters.py new file mode 120000 index 00000000..c734eeca --- /dev/null +++ b/meta-arm/lib/oeqa/selftest/cases/tests/test-parameters.py @@ -0,0 +1 @@ +mock-fvp.py \ No newline at end of file