|
| 1 | +#!/bin/bash |
| 2 | +set -xe |
| 3 | + |
| 4 | +TEMPDIR=$(mktemp -d) |
| 5 | + |
| 6 | +mkdir $TEMPDIR/mnt |
| 7 | + |
| 8 | +cleanup() { |
| 9 | + # Ignore errors in cleanup. |
| 10 | + set +e |
| 11 | + umount -l -q $TEMPDIR/mnt |
| 12 | + rm -rf $TEMPDIR |
| 13 | + # Kill descendants, but not itself. |
| 14 | + trap '' SIGTERM |
| 15 | + kill -- -$(ps -o pgid= $$ | tr -d ' ') |
| 16 | + trap - SIGTERM |
| 17 | +} |
| 18 | + |
| 19 | +trap cleanup EXIT |
| 20 | + |
| 21 | +cp -rv $1 $TEMPDIR |
| 22 | + |
| 23 | +cat > $TEMPDIR/storage/registered.json << EOF |
| 24 | +[ |
| 25 | + { |
| 26 | + "mac": [82, 84, 0, 18, 52, 86], |
| 27 | + "group": 0, |
| 28 | + "row": 1, |
| 29 | + "col": 1, |
| 30 | + "curr_action": null, |
| 31 | + "curr_progress": null, |
| 32 | + "next_action": "shutdown", |
| 33 | + "image": "contestant" |
| 34 | + } |
| 35 | +] |
| 36 | +EOF |
| 37 | + |
| 38 | +if ! ip link show br-pixie; then |
| 39 | + ip link add br-pixie type bridge |
| 40 | + ip link set dev br-pixie up |
| 41 | + ip addr add 10.0.0.1/8 brd 10.255.255.255 dev br-pixie |
| 42 | +fi |
| 43 | + |
| 44 | +RUST_BACKTRACE=short RUST_LOG=debug ./pixie-server/target/debug/pixie-server -s $TEMPDIR/storage & |
| 45 | + |
| 46 | +run_qemu() { |
| 47 | + OVMF=/usr/share/OVMF/OVMF_CODE_4M.fd |
| 48 | + if ! [ -e $OVMF ] |
| 49 | + then |
| 50 | + OVMF=/usr/share/edk2/x64/OVMF_CODE.4m.fd |
| 51 | + fi |
| 52 | + qemu-system-x86_64 \ |
| 53 | + -nographic \ |
| 54 | + -enable-kvm \ |
| 55 | + -cpu host -smp cores=2 \ |
| 56 | + -m 1G \ |
| 57 | + -drive if=pflash,format=raw,file=$OVMF \ |
| 58 | + -drive file=$TEMPDIR/disk.img,if=none,id=nvm,format=raw \ |
| 59 | + -device nvme,serial=deadbeef,drive=nvm \ |
| 60 | + -nic bridge,mac=52:54:00:12:34:56,br=br-pixie,model=virtio-net-pci |
| 61 | +} |
| 62 | + |
| 63 | +truncate -s 8G $TEMPDIR/disk.img |
| 64 | +mkfs.ext4 $TEMPDIR/disk.img |
| 65 | +DEV=$(losetup --show --find $TEMPDIR/disk.img) |
| 66 | +mount $DEV $TEMPDIR/mnt |
| 67 | +cp ./pixie-server/target/debug/pixie-server $TEMPDIR/mnt |
| 68 | +umount $TEMPDIR/mnt |
| 69 | +losetup -d $DEV |
| 70 | + |
| 71 | +curl 'http://localhost:8080/admin/curr_action/all/store' |
| 72 | +run_qemu |
| 73 | + |
| 74 | +rm -f $TEMPDIR/disk.img |
| 75 | +truncate -s 8G $TEMPDIR/disk.img |
| 76 | + |
| 77 | +curl 'http://localhost:8080/admin/curr_action/all/flash' |
| 78 | +run_qemu |
| 79 | + |
| 80 | +DEV=$(losetup --show --find $TEMPDIR/disk.img) |
| 81 | +mount $DEV $TEMPDIR/mnt |
| 82 | +if [ "$(md5sum $TEMPDIR/mnt/pixie-server | cut -f 1 -d ' ')" != "$(md5sum ./pixie-server/target/debug/pixie-server | cut -f 1 -d ' ')" ]; then |
| 83 | + echo "pixie-server does not contain the expected content" |
| 84 | + exit 1 |
| 85 | +fi |
| 86 | +umount $TEMPDIR/mnt |
| 87 | +losetup -d $DEV |
0 commit comments