diff --git a/meta-arm/lib/oeqa/selftest/cases/runfvp.py b/meta-arm/lib/oeqa/selftest/cases/runfvp.py index 61ce2ab9..c995f89e 100644 --- a/meta-arm/lib/oeqa/selftest/cases/runfvp.py +++ b/meta-arm/lib/oeqa/selftest/cases/runfvp.py @@ -1,4 +1,3 @@ -import asyncio import os import json import pathlib @@ -17,7 +16,7 @@ class RunFVPTests(OESelftestTestCase): def setUpLocal(self): self.assertTrue(runfvp.exists()) - def run_fvp(self, *args, should_succeed=True): + def run_fvp(self, *args, env=None, 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 @@ -26,7 +25,7 @@ class RunFVPTests(OESelftestTestCase): cli = [runfvp,] + list(args) print(f"Calling {cli}") # Set cwd to testdir so that any mock FVPs are found - ret = subprocess.run(cli, cwd=testdir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) + ret = subprocess.run(cli, cwd=testdir, env=env, 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 @@ -53,6 +52,10 @@ class RunFVPTests(OESelftestTestCase): # test-parameter sets one argument, add another manually self.run_fvp(testdir / "test-parameter.json", "--", "--parameter", "board.dog=woof") + def test_fvp_environment(self): + output = self.run_fvp(testdir / "test-environment.json", env={"DISPLAY": "test_fvp_environment:42"}) + self.assertEqual(output.strip(), "Found expected DISPLAY") + @OETestTag("meta-arm") class ConfFileTests(OESelftestTestCase): def test_no_exe(self): diff --git a/meta-arm/lib/oeqa/selftest/cases/tests/mock-fvp.py b/meta-arm/lib/oeqa/selftest/cases/tests/mock-fvp.py index 2213c9f0..6cf8e454 100755 --- a/meta-arm/lib/oeqa/selftest/cases/tests/mock-fvp.py +++ b/meta-arm/lib/oeqa/selftest/cases/tests/mock-fvp.py @@ -2,12 +2,19 @@ import argparse import sys +import os 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) +def do_test_environment(args): + if os.environ.get("DISPLAY") == "test_fvp_environment:42": + print("Found expected DISPLAY") + else: + print("Got unexpected environment %s" % str(os.environ)) + sys.exit(1) if __name__ == "__main__": parser = argparse.ArgumentParser() diff --git a/meta-arm/lib/oeqa/selftest/cases/tests/test-environment.json b/meta-arm/lib/oeqa/selftest/cases/tests/test-environment.json new file mode 100644 index 00000000..6e23855b --- /dev/null +++ b/meta-arm/lib/oeqa/selftest/cases/tests/test-environment.json @@ -0,0 +1,4 @@ +{ + "fvp-bindir": ".", + "exe": "test-environment.py" +} diff --git a/meta-arm/lib/oeqa/selftest/cases/tests/test-environment.py b/meta-arm/lib/oeqa/selftest/cases/tests/test-environment.py new file mode 120000 index 00000000..c734eeca --- /dev/null +++ b/meta-arm/lib/oeqa/selftest/cases/tests/test-environment.py @@ -0,0 +1 @@ +mock-fvp.py \ No newline at end of file