From a5f16dfa817f43c1ac65d2f64d279ba93d57005b Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Mon, 15 Apr 2024 22:15:27 +0100 Subject: [PATCH] convert inout test to use uevent-watch --- tests/inout/configuration.nix | 24 +++++++++++++++++------- tests/inout/script.expect | 11 +++++------ tests/inout/test.nix | 6 ++++-- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/tests/inout/configuration.nix b/tests/inout/configuration.nix index 264c5b1..cf474a6 100644 --- a/tests/inout/configuration.nix +++ b/tests/inout/configuration.nix @@ -15,6 +15,7 @@ in rec { "${modulesPath}/network" "${modulesPath}/ssh" "${modulesPath}/mount" + "${modulesPath}/mdevd.nix" ]; filesystem = dir { srv = dir {}; }; @@ -46,11 +47,20 @@ in rec { rootfsType = "jffs2"; hostname = "inout"; - services.mount_external_disk = svc.mount.build { - device = "LABEL=backup-disk"; - mountpoint = "/srv"; - fstype = "ext4"; - }; - - + services.watch_mount_srv = + let + node = "/dev/disk/by-partlabel/backup-disk"; + mount = oneshot { + name = "mount-srv"; + up = "mount -t ext2 ${node} /srv"; + down = "umount /srv"; + }; + in longrun { + name = "mount_srv"; + run = '' + ${pkgs.uevent-watch}/bin/uevent-watch -s ${mount.name} -n ${node} partname=backup-disk devtype=partition + ''; + dependencies = [ config.services.mdevd ]; + buildInputs = [ mount ]; + }; } diff --git a/tests/inout/script.expect b/tests/inout/script.expect index 3d8a5a4..35dd36e 100644 --- a/tests/inout/script.expect +++ b/tests/inout/script.expect @@ -14,9 +14,9 @@ set console_id $spawn_id expect "BusyBox" chat "#" "PS1=RE\\ADY_\\ ; stty -echo \r" -chat "READY_" "s6-rc -b -a list\r" +chat "READY_" "tail -f /run/uncaught-logs/current & \rs6-rc -b -a list\r" -chat "watch-mount" "\r" +chat "mount" "\r" set spawn_id $monitor_id chat "QEMU" "device_add usb-storage,bus=xhci.0,drive=usbstick\n" @@ -25,16 +25,15 @@ chat "(qemu)" "version\r" set spawn_id $console_id expect { - "mounted filesystem" { } + "sda: sda1" { } timeout { exit 1 } } send "\r" -chat "READY_" "s6-rc -b -a list\r" -chat "READY_" "cat /proc/mounts\r" +chat "READY_" "sleep 3; grep /srv /proc/mounts && hostname\r" expect { - "/srv" { } + "inout" { } timeout { exit 1 } } diff --git a/tests/inout/test.nix b/tests/inout/test.nix index 9e75f31..d59c564 100644 --- a/tests/inout/test.nix +++ b/tests/inout/test.nix @@ -13,13 +13,15 @@ in pkgs.runCommand "check" { socat e2fsprogs util-linux # for sfdisk, fallocate + parted ] ; } '' mkdir vm dd if=/dev/zero of=./vm/stick.e2fs bs=1M count=32 mkfs.ext2 -L backup-disk ./vm/stick.e2fs -cat <(dd if=/dev/zero bs=512 count=4) ./vm/stick.e2fs > ./vm/stick.img -echo '4,-,L,*' | sfdisk ./vm/stick.img +dd if=/dev/zero of=./vm/stick.img bs=1M count=38 +dd if=./vm/stick.e2fs of=./vm/stick.img bs=512 seek=34 conv=notrunc +parted -s ./vm/stick.img -- mklabel gpt mkpart backup-disk ext2 34s -0M ${img}/run.sh --background ./vm --flag -device --flag usb-ehci,id=xhci --flag -drive --flag if=none,id=usbstick,format=raw,file=$(pwd)/vm/stick.img expect ${./script.expect} | tee $out