diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e47c1658..bd1f5c1f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,6 +1,10 @@ name: Rust -on: [push, pull_request] +on: + pull_request: + branches: [master] + push: + branches: [master] jobs: clippy: diff --git a/run_test.sh b/run_test.sh new file mode 100755 index 00000000..1acedd16 --- /dev/null +++ b/run_test.sh @@ -0,0 +1,87 @@ +#!/bin/bash +set -xe + +TEMPDIR=$(mktemp -d) + +mkdir $TEMPDIR/mnt + +cleanup() { + # Ignore errors in cleanup. + set +e + umount -l -q $TEMPDIR/mnt + rm -rf $TEMPDIR + # Kill descendants, but not itself. + trap '' SIGTERM + kill -- -$(ps -o pgid= $$ | tr -d ' ') + trap - SIGTERM +} + +trap cleanup EXIT + +cp -rv $1 $TEMPDIR + +cat > $TEMPDIR/storage/registered.json << EOF +[ + { + "mac": [82, 84, 0, 18, 52, 86], + "group": 0, + "row": 1, + "col": 1, + "curr_action": null, + "curr_progress": null, + "next_action": "shutdown", + "image": "contestant" + } +] +EOF + +if ! ip link show br-pixie; then + ip link add br-pixie type bridge + ip link set dev br-pixie up + ip addr add 10.0.0.1/8 brd 10.255.255.255 dev br-pixie +fi + +RUST_BACKTRACE=short RUST_LOG=debug ./pixie-server/target/debug/pixie-server -s $TEMPDIR/storage & + +run_qemu() { + OVMF=/usr/share/OVMF/OVMF_CODE_4M.fd + if ! [ -e $OVMF ] + then + OVMF=/usr/share/edk2/x64/OVMF_CODE.4m.fd + fi + qemu-system-x86_64 \ + -nographic \ + -enable-kvm \ + -cpu host -smp cores=2 \ + -m 1G \ + -drive if=pflash,format=raw,file=$OVMF \ + -drive file=$TEMPDIR/disk.img,if=none,id=nvm,format=raw \ + -device nvme,serial=deadbeef,drive=nvm \ + -nic bridge,mac=52:54:00:12:34:56,br=br-pixie,model=virtio-net-pci +} + +truncate -s 8G $TEMPDIR/disk.img +mkfs.ext4 $TEMPDIR/disk.img +DEV=$(losetup --show --find $TEMPDIR/disk.img) +mount $DEV $TEMPDIR/mnt +cp ./pixie-server/target/debug/pixie-server $TEMPDIR/mnt +umount $TEMPDIR/mnt +losetup -d $DEV + +curl 'http://localhost:8080/admin/curr_action/all/store' +run_qemu + +rm -f $TEMPDIR/disk.img +truncate -s 8G $TEMPDIR/disk.img + +curl 'http://localhost:8080/admin/curr_action/all/flash' +run_qemu + +DEV=$(losetup --show --find $TEMPDIR/disk.img) +mount $DEV $TEMPDIR/mnt +if [ "$(md5sum $TEMPDIR/mnt/pixie-server | cut -f 1 -d ' ')" != "$(md5sum ./pixie-server/target/debug/pixie-server | cut -f 1 -d ' ')" ]; then + echo "pixie-server does not contain the expected content" + exit 1 +fi +umount $TEMPDIR/mnt +losetup -d $DEV diff --git a/test.sh b/test.sh index 5d1db709..a4be5236 100755 --- a/test.sh +++ b/test.sh @@ -3,71 +3,9 @@ set -xe # TODO: less invasive on host system -# TODO: kill server on exit -#trap "kill -- -$$" EXIT - SELFDIR="$(realpath "$(dirname "$0")")" cd "$SELFDIR" ./setup.sh -cat <storage/registered.json -[ - { - "mac": [82, 84, 0, 18, 52, 86], - "group": 0, - "row": 1, - "col": 1, - "curr_action": null, - "curr_progress": null, - "next_action": "shutdown", - "image": "contestant" - } -] -EOF - -if ! ip link show br-pixie; then - sudo ip link add br-pixie type bridge - sudo ip link set dev br-pixie up - sudo ip addr add 10.0.0.1/8 brd 10.255.255.255 dev br-pixie -fi - -sudo RUST_BACKTRACE=short RUST_LOG=debug ./pixie-server/target/debug/pixie-server & - -run_qemu() { - sudo qemu-system-x86_64 \ - -nographic \ - -enable-kvm \ - -cpu host -smp cores=2 \ - -m 1G \ - -drive if=pflash,format=raw,file=/usr/share/OVMF/OVMF_CODE_4M.fd \ - -drive file=disk.img,if=none,id=nvm,format=raw \ - -device nvme,serial=deadbeef,drive=nvm \ - -nic bridge,mac=52:54:00:12:34:56,br=br-pixie,model=virtio-net-pci -} - -truncate -s 8G disk.img -mkfs.ext4 -F disk.img -DEV=$(sudo losetup --show --find disk.img) -sudo mount $DEV /mnt -echo "hello world" | sudo tee /mnt/hello.txt -sudo umount /mnt -sudo losetup -d $DEV - -curl 'http://localhost:8080/admin/curr_action/all/store' -run_qemu - -rm -f disk.img -truncate -s 8G disk.img - -curl 'http://localhost:8080/admin/curr_action/all/flash' -run_qemu - -DEV=$(sudo losetup --show --find disk.img) -sudo mount $DEV /mnt -if [ "$(cat /mnt/hello.txt)" != "hello world" ]; then - echo "hello.txt does not contain the expected content" - exit 1 -fi -sudo umount /mnt -sudo losetup -d $DEV +setsid sudo ./run_test.sh ${SELFDIR}/storage