Skip to content

Commit e43112c

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 527b974 commit e43112c

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

ci/qemu_test.py

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

0 commit comments

Comments
 (0)