|
| 1 | +{ lib, nixosTest, imageSize, blockSize, diskSizeMiB }: |
| 2 | +let |
| 3 | + serial = "awawawawawa"; |
| 4 | + diskFile = "/tmp/block-file.img"; |
| 5 | + byDiskPath = "/dev/disk/by-id/usb-QEMU_QEMU_HARDDISK_${serial}-0:0"; |
| 6 | +in nixosTest { |
| 7 | + name = "blocksize-bs${toString blockSize}-image${toString imageSize}-diskMiB${ |
| 8 | + toString diskSizeMiB |
| 9 | + }"; |
| 10 | + |
| 11 | + nodes.machine = { pkgs, lib, ... }: |
| 12 | + with lib; { |
| 13 | + imports = [ ]; |
| 14 | + |
| 15 | + users.users = { |
| 16 | + admin = { |
| 17 | + isNormalUser = true; |
| 18 | + extraGroups = [ "wheel" ]; |
| 19 | + }; |
| 20 | + }; |
| 21 | + |
| 22 | + environment.systemPackages = with pkgs; [ caligula ]; |
| 23 | + virtualisation.qemu.options = |
| 24 | + [ "-drive" "if=none,id=usbstick,format=raw,file=${diskFile}" ] |
| 25 | + ++ [ "-usb" ] ++ [ "-device" "usb-ehci,id=ehci" ] ++ [ |
| 26 | + "-device" |
| 27 | + "usb-storage,bus=ehci.0,drive=usbstick,serial=${serial},physical_block_size=${ |
| 28 | + builtins.toString blockSize |
| 29 | + }" |
| 30 | + ]; |
| 31 | + /* virtualisation.qemu.drives = [{ |
| 32 | + name = "non-default-filesystem"; |
| 33 | + file = fsImage; |
| 34 | + }]; |
| 35 | + */ |
| 36 | + }; |
| 37 | + |
| 38 | + testScript = with lib; '' |
| 39 | + import os |
| 40 | +
|
| 41 | + print("Creating file image at ${diskFile}") |
| 42 | + os.system("dd bs=1M count=${ |
| 43 | + toString diskSizeMiB |
| 44 | + } if=/dev/urandom of=${diskFile}") |
| 45 | +
|
| 46 | + ${readFile ./common.py} |
| 47 | +
|
| 48 | + machine.start() |
| 49 | + machine.wait_for_unit('default.target') |
| 50 | + print(machine.execute('stat $(readlink -f ${byDiskPath})', check_output=True)[1]) |
| 51 | + try: |
| 52 | + machine.succeed('dd if=/dev/urandom of=/tmp/input.iso bs=1 count=${ |
| 53 | + toString imageSize |
| 54 | + }') |
| 55 | + with subtest("executes successfully"): |
| 56 | + machine.succeed('caligula burn /tmp/input.iso --force -o $(readlink -f ${byDiskPath}) --hash skip --compression auto --interactive never') |
| 57 | +
|
| 58 | + with subtest("burns correctly"): |
| 59 | + machine.succeed('dd if=${byDiskPath} of=/tmp/written.iso bs=1 count=${ |
| 60 | + toString imageSize |
| 61 | + }') |
| 62 | + machine.succeed('diff -s /tmp/input.iso /tmp/written.iso') |
| 63 | + |
| 64 | + finally: |
| 65 | + print_logs(machine) |
| 66 | + ''; |
| 67 | +} |
0 commit comments