-
Notifications
You must be signed in to change notification settings - Fork 0
/
qemu-test
executable file
·88 lines (75 loc) · 2.38 KB
/
qemu-test
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
#!/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!)
# asan Set environment variables to support address sanitizer
#
# When no argument is given, the default test suite will be executed
set -e
rm -f qemu-test-ok
# TODO use virtfs with multidevs=remap on qemu 4.2
# https://github.com/qemu/qemu/commit/1a6ed33cc56997479bbe5b48337ff8da44585bd4
KERNEL_URL="https://github.com/jluebbe/linux/releases/download/rauc-test-20210201-1/bzImage"
KERNEL_SHA256SUM="1d5e1ba27d4d1fb3da39cff3816f0dcc9e80ccdd2cbbf6965219ad5f46b5ba85"
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
QEMU_ARGS=""
BOOTNAME="system0"
for x in "$@"; do
if [ "$x" = "passthrough" ]; then
QEMU_ARGS="$QEMU_ARGS -cpu host"
elif [ "$x" = "system" ]; then
BOOTNAME="A"
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
qemu-system-x86_64 \
$QEMU_ARGS \
-machine q35 \
-m 512M \
-smp 2 \
-kernel bzImage \
-nographic -serial mon:stdio \
-no-reboot \
-virtfs local,id=rootfs,path=/,security_model=none,mount_tag=/dev/root \
-nic user,model=virtio-net-pci \
-append "loglevel=6 console=ttyS0 nandsim.id_bytes=0x20,0xa2,0x00,0x15 nandsim.parts=0x100 mtdram.total_size=32768 root=/dev/root rootfstype=9p rootflags=msize=16777216 rw init=$(pwd)/qemu-test-init rauc.slot=$BOOTNAME $*"
test -f qemu-test-ok