1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
import asyncio
import os
import pathlib
import subprocess
import tempfile
import unittest.mock
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.
"""
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)
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):
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")
class ConfFileTests(OESelftestTestCase):
def test_no_exe(self):
from fvp import conffile
with tempfile.NamedTemporaryFile('w') as tf:
tf.write('{}')
tf.flush()
with self.assertRaises(ValueError):
conffile.load(tf.name)
def test_minimal(self):
from fvp import conffile
with tempfile.NamedTemporaryFile('w') as tf:
tf.write('{"exe": "FVP_Binary"}')
tf.flush()
conf = conffile.load(tf.name)
self.assertTrue('fvp-bindir' in conf)
self.assertTrue('fvp-bindir' in conf)
self.assertTrue("exe" in conf)
self.assertTrue("parameters" in conf)
self.assertTrue("data" in conf)
self.assertTrue("applications" in conf)
self.assertTrue("terminals" in conf)
self.assertTrue("args" in conf)
self.assertTrue("consoles" in conf)
self.assertTrue("env" in conf)
class RunnerTests(OESelftestTestCase):
def create_mock(self):
return unittest.mock.patch("subprocess.Popen")
def test_start(self):
from fvp import runner
with self.create_mock() as m:
fvp = runner.FVPRunner(self.logger)
fvp.start({
"fvp-bindir": "/usr/bin",
"exe": "FVP_Binary",
"parameters": {'foo': 'bar'},
"data": ['data1'],
"applications": {'a1': 'file'},
"terminals": {},
"args": ['--extra-arg'],
"env": {"FOO": "BAR"}
})
m.assert_called_once_with(['/usr/bin/FVP_Binary',
'--parameter', 'foo=bar',
'--data', 'data1',
'--application', 'a1=file',
'--extra-arg'],
stdin=unittest.mock.ANY,
stdout=unittest.mock.ANY,
stderr=unittest.mock.ANY,
env={"FOO":"BAR"})
@unittest.mock.patch.dict(os.environ, {"DISPLAY": ":42", "WAYLAND_DISPLAY": "wayland-42"})
def test_env_passthrough(self):
from fvp import runner
with self.create_mock() as m:
fvp = runner.FVPRunner(self.logger)
fvp.start({
"fvp-bindir": "/usr/bin",
"exe": "FVP_Binary",
"parameters": {},
"data": [],
"applications": {},
"terminals": {},
"args": [],
"env": {"FOO": "BAR"}
})
m.assert_called_once_with(['/usr/bin/FVP_Binary'],
stdin=unittest.mock.ANY,
stdout=unittest.mock.ANY,
stderr=unittest.mock.ANY,
env={"DISPLAY":":42", "FOO": "BAR", "WAYLAND_DISPLAY": "wayland-42"})
|