Skip to content

Commit 27948c5

Browse files
committed
ci: add qemu test mechanism
Add a mechanism to test behaviours don't relate to hardware. These can be effectively tested without need of the target platform using qemu. This uses Python and pytest. Specific tests to follow. For now, this is just the raw test that will need to be run manually, and depends on the developer already having built a disk-ufs.img by hand using the instructions in README.md. Automation and integration into GitHub Actions will follow. How-to documentation would be useful but would be superseded by that automation and integration, so this is omitted for now. Signed-off-by: Robie Basak <[email protected]>
1 parent 5a9d819 commit 27948c5

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

ci/qemu_test.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""Tests that are entirely qemu based, so do not require test hardware"""
2+
3+
import os
4+
import signal
5+
import subprocess
6+
import tempfile
7+
8+
import pexpect
9+
import pytest
10+
11+
12+
@pytest.fixture
13+
def vm():
14+
"""A pexpect.spawn object attached to the serial console of a VM freshly
15+
booting with a CoW base of disk-ufs.img"""
16+
with tempfile.TemporaryDirectory() as tmpdir:
17+
qcow_path = os.path.join(tmpdir, "disk1.qcow")
18+
subprocess.run(
19+
[
20+
"qemu-img",
21+
"create",
22+
"-b",
23+
os.path.join(os.getcwd(), "disk-ufs.img"),
24+
"-f",
25+
"qcow",
26+
"-F",
27+
"raw",
28+
qcow_path,
29+
],
30+
check=True,
31+
)
32+
child = pexpect.spawn(
33+
"qemu-system-aarch64",
34+
[
35+
"-cpu",
36+
"cortex-a57",
37+
"-m",
38+
"2048",
39+
"-M",
40+
"virt",
41+
"-drive",
42+
f"if=none,file={qcow_path},format=qcow,id=disk1",
43+
"-device",
44+
"virtio-scsi-pci,id=scsi1",
45+
"-device",
46+
"scsi-hd,bus=scsi1.0,drive=disk1,physical_block_size=4096,logical_block_size=4096",
47+
"-nographic",
48+
"-bios",
49+
"/usr/share/AAVMF/AAVMF_CODE.fd",
50+
],
51+
)
52+
yield child
53+
54+
# No need to be nice; that would take time
55+
child.kill(signal.SIGKILL)
56+
57+
# If this blocks then we have a problem. Better to hang than build up
58+
# excess qemu processes that won't die.
59+
child.wait()

0 commit comments

Comments
 (0)