new file mode 100644
@@ -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")
new file mode 100644
@@ -0,0 +1,3 @@
+{
+ "exe": "auto-basic.sh"
+}
new file mode 100755
@@ -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
new file mode 100644
@@ -0,0 +1,7 @@
+{
+ "exe": "test-parameters.py",
+ "parameters": {
+ "board.cow": "moo",
+ "board.dog": "woof"
+ }
+}
new file mode 100755
@@ -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)
new file mode 100644
@@ -0,0 +1,6 @@
+{
+ "exe": "test-parameters.py",
+ "parameters": {
+ "board.cow": "moo"
+ }
+}
new file mode 120000
@@ -0,0 +1 @@
+mock-fvp.py
\ No newline at end of file
Add rudimentary but functional test cases for runfvp. Signed-off-by: Ross Burton <ross.burton@arm.com> --- 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