summaryrefslogtreecommitdiff
path: root/build-and-test.sh
blob: dd6cbfb204aedf046d9f24893e2db8a53f4be18f (plain)
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
#!/bin/bash

set -euo pipefail

image="$1"
cache="$2"
shift 2

echo Building image.
rm -f "$cache/ambient.tar.gz"
./ambient-build-vm --data . --cache "$cache" --image "$image" "$@"

tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT

mkdir "$tmp/files"
cat <<EOF >"$tmp/files/run-ci"
echo xyzzy
EOF
chmod +x "$tmp/files/run-ci"

tar -cf "$tmp/run-ci.tar" -C "$tmp/files" .
cp "$image" "$tmp/img.qcow2"

QVMF_FD="/usr/share/ovmf/OVMF.fd"
cp "$QVMF_FD" "$tmp/vars"

echo Testing image.
kvm \
	-m 1024 \
	-smp cpus=1 \
	-display none \
	-serial "file:/$tmp/log0" \
	-serial "file:/$tmp/log1" \
	-drive if=pflash,format=raw,unit=0,file="$QVMF_FD",readonly=on \
	-drive if=pflash,format=raw,unit=1,file="$tmp/vars" \
	-drive format=qcow2,if=virtio,file="$tmp/img.qcow2" \
	-drive format=raw,if=virtio,file="$tmp/run-ci.tar",readonly=on \
	-nodefaults

if ! grep -q '^xyzzy' "$tmp/log1" >/dev/null; then
	echo "FAILED to perform a simple CI run" 1>&2
	cat -v "$tmp/log1"
	exit 1
fi

echo "OK. $image is ready to use."