mirror of
https://git.yoctoproject.org/meta-arm
synced 2026-07-17 04:07:18 +00:00
arm/oeqa: add basic runfvp test cases
Add rudimentary but functional test cases for runfvp. Signed-off-by: Ross Burton <ross.burton@arm.com> Signed-off-by: Jon Mason <jon.mason@arm.com>
This commit is contained in:
@@ -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")
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"exe": "auto-basic.sh"
|
||||||
|
}
|
||||||
+11
@@ -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
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"exe": "test-parameters.py",
|
||||||
|
"parameters": {
|
||||||
|
"board.cow": "moo",
|
||||||
|
"board.dog": "woof"
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
@@ -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)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"exe": "test-parameters.py",
|
||||||
|
"parameters": {
|
||||||
|
"board.cow": "moo"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
mock-fvp.py
|
||||||
Reference in New Issue
Block a user