diff --git a/checks/blocksize.nix b/checks/blocksize.nix new file mode 100644 index 0000000..8f8bb1f --- /dev/null +++ b/checks/blocksize.nix @@ -0,0 +1,67 @@ +{ lib, nixosTest, imageSize, blockSize, diskSizeMiB }: +let + serial = "awawawawawa"; + diskFile = "/tmp/block-file.img"; + byDiskPath = "/dev/disk/by-id/usb-QEMU_QEMU_HARDDISK_${serial}-0:0"; +in nixosTest { + name = "blocksize-bs${toString blockSize}-image${toString imageSize}-diskMiB${ + toString diskSizeMiB + }"; + + nodes.machine = { pkgs, lib, ... }: + with lib; { + imports = [ ]; + + users.users = { + admin = { + isNormalUser = true; + extraGroups = [ "wheel" ]; + }; + }; + + environment.systemPackages = with pkgs; [ caligula ]; + virtualisation.qemu.options = + [ "-drive" "if=none,id=usbstick,format=raw,file=${diskFile}" ] + ++ [ "-usb" ] ++ [ "-device" "usb-ehci,id=ehci" ] ++ [ + "-device" + "usb-storage,bus=ehci.0,drive=usbstick,serial=${serial},physical_block_size=${ + builtins.toString blockSize + }" + ]; + /* virtualisation.qemu.drives = [{ + name = "non-default-filesystem"; + file = fsImage; + }]; + */ + }; + + testScript = with lib; '' + import os + + print("Creating file image at ${diskFile}") + os.system("dd bs=1M count=${ + toString diskSizeMiB + } if=/dev/urandom of=${diskFile}") + + ${readFile ./common.py} + + machine.start() + machine.wait_for_unit('default.target') + print(machine.execute('stat $(readlink -f ${byDiskPath})', check_output=True)[1]) + try: + machine.succeed('dd if=/dev/urandom of=/tmp/input.iso bs=1 count=${ + toString imageSize + }') + with subtest("executes successfully"): + machine.succeed('caligula burn /tmp/input.iso --force -o $(readlink -f ${byDiskPath}) --hash skip --compression auto --interactive never') + + with subtest("burns correctly"): + machine.succeed('dd if=${byDiskPath} of=/tmp/written.iso bs=1 count=${ + toString imageSize + }') + machine.succeed('diff -s /tmp/input.iso /tmp/written.iso') + + finally: + print_logs(machine) + ''; +} diff --git a/checks/default.nix b/checks/default.nix index 51e76d4..07b1654 100644 --- a/checks/default.nix +++ b/checks/default.nix @@ -5,15 +5,34 @@ let inherit system; overlays = [ self.overlays.default ]; }; -in { + lib = pkgs.lib; +in with lib; +{ headless = pkgs.callPackage ./headless { }; smoke-test-simple = pkgs.callPackage ./smoke-test-simple { }; } // -(if system == "x86_64-linux" then { - autoescalate-doas = - pkgs.callPackage ./autoescalate { escalationTool = "doas"; }; - autoescalate-sudo = - pkgs.callPackage ./autoescalate { escalationTool = "sudo"; }; -} else +(if system == "x86_64-linux" then + { + autoescalate-doas = + pkgs.callPackage ./autoescalate { escalationTool = "doas"; }; + autoescalate-sudo = + pkgs.callPackage ./autoescalate { escalationTool = "sudo"; }; + } // + + # blocksize alignment tests + (let + MiB = 1048576; + parameters = cartesianProduct { + blockSize = [ 512 1024 2048 4096 8192 ]; + imageSize = [ (10 * MiB) (10 * MiB + 51) ]; + }; + in listToAttrs (map ({ imageSize, blockSize }: rec { + name = value.name; + value = pkgs.callPackage ./blocksize.nix { + inherit lib blockSize imageSize; + diskSizeMiB = 64; + }; + }) parameters)) +else { }) diff --git a/checks/headless/default.nix b/checks/headless/default.nix index 72c20ca..3f358d4 100644 --- a/checks/headless/default.nix +++ b/checks/headless/default.nix @@ -1,7 +1,8 @@ { lib, caligula, runCommand }: runCommand "caligula-headless-test" { buildInputs = [ caligula ]; - isoInnerHash = "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986"; + isoInnerHash = + "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986"; meta.timeout = 10; } '' caligula burn ${./input.iso.gz} \