-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqemu-test
More file actions
executable file
·133 lines (116 loc) · 3.94 KB
/
Copy pathqemu-test
File metadata and controls
executable file
·133 lines (116 loc) · 3.94 KB
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
132
133
#!/bin/sh
#
# RAUC qemu test runner script
#
# Executes the RAUC test suite in a safe qemu environment with simulated root
# privileges to emulate and test virtual devices such as block devices, NAND,
# etc.
#
# Usage:
#
# ./qemu-test <argument>
#
# Optional arguments:
#
# passthrough Enable passthrough of the host's CPU features
# shell Setup qemu test system and provide an interactive shell
# system Setup qemu dummy system that behaves like a target (without reboot!)
# service-backtrace Run service under gdb and show backtrace on error (requires 'system')
# asan Set environment variables to support address sanitizer
# ssh Enable SSH access to the VM (port 2222)
# background Run the VM in the background (implies ssh, use qemu-test-stop to stop)
# test=<test> Run specified test (for use with git bisect)
#
# When no argument is given, the default test suite will be executed
set -e
rm -f qemu-test-ok
KERNEL_URL="https://github.com/jluebbe/linux/releases/download/rauc-test-20241015-1/bzImage"
KERNEL_SHA256SUM="1d645700187640c58ea3821e55723cfe1627b68fcf0f38706d7bdd93c71fa056"
check_kernel() {
if test -f bzImage && echo "$KERNEL_SHA256SUM bzImage" | sha256sum --check --status; then
return 0
fi
curl -L "$KERNEL_URL" -o bzImage.tmp
if echo "$KERNEL_SHA256SUM bzImage.tmp" | sha256sum --check --status; then
mv bzImage.tmp bzImage
else
echo "bad bzImage hash"
return 1
fi
}
check_kernel || exit 1
# make sure the tests are built
BUILD_DIR="build/"
if [ ! -d $BUILD_DIR ]; then
echo "Could not find 'build/' dir. Run 'meson setup build'."
fi
ninja -C $BUILD_DIR
if [ -z "$QEMU_BIN" ]; then
QEMU_BIN="qemu-system-x86_64"
fi
QEMU_ARGS=""
BOOTNAME="system0"
SSH=0
BACKGROUND=0
for x in "$@"; do
if [ "$x" = "passthrough" ]; then
QEMU_ARGS="$QEMU_ARGS -cpu host"
elif [ "$x" = "system" ]; then
BOOTNAME="A"
elif [ "$x" = "ssh" ]; then
SSH=1
elif [ "$x" = "background" ]; then
BACKGROUND=1
SSH=1
fi
done
if test -w /dev/kvm; then
QEMU_ARGS="$QEMU_ARGS -enable-kvm"
else
echo "/dev/kvm is not accessible, using emulation"
fi
if test -f /usr/share/qemu/qboot.rom; then
echo "found qboot, enabling"
QEMU_ARGS="$QEMU_ARGS -bios /usr/share/qemu/qboot.rom"
fi
if "$QEMU_BIN" -device help | grep -q 'name "emmc"'; then
echo "found emmc support, enabling"
truncate -s 64M qemu-test-emmc.img
QEMU_ARGS="$QEMU_ARGS -drive if=none,id=emmc-drive,file=qemu-test-emmc.img,format=raw"
QEMU_ARGS="$QEMU_ARGS -device sdhci-pci"
QEMU_ARGS="$QEMU_ARGS -device emmc,id=emmc0,drive=emmc-drive,boot-partition-size=1048576"
fi
NIC_ARGS="-nic user,model=virtio-net-pci"
if [ "$SSH" = "1" ]; then
# When QEMU v10.2.0 is widely available, we could use -hostfwd=unix: instead.
NIC_ARGS="-nic user,model=virtio-net-pci,hostfwd=tcp:127.0.0.1:2222-:22"
if [ ! -f .qemu-test-ssh-key ]; then
ssh-keygen -t ed25519 -f .qemu-test-ssh-key -N "" -C "qemu-test"
fi
if [ ! -f .qemu-test-ssh-host-key ]; then
ssh-keygen -t ed25519 -f .qemu-test-ssh-host-key -N ""
fi
fi
QEMU_ARGS="$QEMU_ARGS -qmp unix:.qemu-test-qmp,server,nowait"
if [ "$BACKGROUND" = "1" ]; then
QEMU_ARGS="$QEMU_ARGS -display none -serial file:qemu-test-log -daemonize -pidfile .qemu-test-pid"
else
QEMU_ARGS="$QEMU_ARGS -nographic -serial mon:stdio"
fi
$QEMU_BIN \
$QEMU_ARGS \
-machine q35 \
-m 1G \
-smp 2 \
-kernel bzImage \
-no-reboot \
-virtfs local,id=rootfs,path=/,security_model=none,mount_tag=/dev/root,multidevs=remap \
$NIC_ARGS \
-append "loglevel=6 console=ttyS0 nandsim.id_bytes=0x20,0xa2,0x00,0x15 nandsim.parts=0x80,0x80 mtdram.total_size=32768 root=/dev/root rootfstype=9p rootflags=msize=16777216 rw init=$(pwd)/qemu-test-init rauc.slot=$BOOTNAME $*"
if [ "$BACKGROUND" = "1" ]; then
echo "QEMU started in background (PID $(cat .qemu-test-pid))"
echo " Stop VM: ./qemu-test-stop"
echo " Log file: qemu-test-log"
else
test -f qemu-test-ok
fi