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