at 24.11-pre 5.2 kB view raw
1{ system ? builtins.currentSystem, 2 config ? {}, 3 pkgs ? import ../.. { inherit system config; } 4}: 5 6with import ../lib/testing-python.nix { inherit system pkgs; }; 7 8let 9 lib = pkgs.lib; 10 qemu-common = import ../lib/qemu-common.nix { inherit lib pkgs; }; 11 12 mkStartCommand = { 13 memory ? 2048, 14 cdrom ? null, 15 usb ? null, 16 pxe ? null, 17 uboot ? false, 18 uefi ? false, 19 extraFlags ? [], 20 }: let 21 qemu = qemu-common.qemuBinary pkgs.qemu_test; 22 23 flags = [ 24 "-m" (toString memory) 25 "-netdev" ("user,id=net0" + (lib.optionalString (pxe != null) ",tftp=${pxe},bootfile=netboot.ipxe")) 26 "-device" ("virtio-net-pci,netdev=net0" + (lib.optionalString (pxe != null && uefi) ",romfile=${pkgs.ipxe}/ipxe.efirom")) 27 ] ++ lib.optionals (cdrom != null) [ 28 "-cdrom" cdrom 29 ] ++ lib.optionals (usb != null) [ 30 "-device" "usb-ehci" 31 "-drive" "id=usbdisk,file=${usb},if=none,readonly" 32 "-device" "usb-storage,drive=usbdisk" 33 ] ++ lib.optionals (pxe != null) [ 34 "-boot" "order=n" 35 ] ++ lib.optionals uefi [ 36 "-drive" "if=pflash,format=raw,unit=0,readonly=on,file=${pkgs.OVMF.firmware}" 37 "-drive" "if=pflash,format=raw,unit=1,readonly=on,file=${pkgs.OVMF.variables}" 38 ] ++ extraFlags; 39 40 flagsStr = lib.concatStringsSep " " flags; 41 in "${qemu} ${flagsStr}"; 42 43 iso = 44 (import ../lib/eval-config.nix { 45 inherit system; 46 modules = [ 47 ../modules/installer/cd-dvd/installation-cd-minimal.nix 48 ../modules/testing/test-instrumentation.nix 49 ]; 50 }).config.system.build.isoImage; 51 52 sd = 53 (import ../lib/eval-config.nix { 54 inherit system; 55 modules = [ 56 ../modules/installer/sd-card/sd-image-x86_64.nix 57 ../modules/testing/test-instrumentation.nix 58 { sdImage.compressImage = false; } 59 ]; 60 }).config.system.build.sdImage; 61 62 makeBootTest = name: config: 63 let 64 startCommand = mkStartCommand config; 65 in 66 makeTest { 67 name = "boot-" + name; 68 nodes = { }; 69 testScript = 70 '' 71 machine = create_machine("${startCommand}") 72 machine.start() 73 machine.wait_for_unit("multi-user.target") 74 machine.succeed("nix store verify --no-trust -r --option experimental-features nix-command /run/current-system") 75 76 with subtest("Check whether the channel got installed correctly"): 77 machine.succeed("nix-instantiate --dry-run '<nixpkgs>' -A hello") 78 machine.succeed("nix-env --dry-run -iA nixos.procps") 79 80 machine.shutdown() 81 ''; 82 }; 83 84 makeNetbootTest = name: extraConfig: 85 let 86 config = (import ../lib/eval-config.nix { 87 inherit system; 88 modules = 89 [ ../modules/installer/netboot/netboot.nix 90 ../modules/testing/test-instrumentation.nix 91 { key = "serial"; } 92 ]; 93 }).config; 94 ipxeBootDir = pkgs.symlinkJoin { 95 name = "ipxeBootDir"; 96 paths = [ 97 config.system.build.netbootRamdisk 98 config.system.build.kernel 99 config.system.build.netbootIpxeScript 100 ]; 101 }; 102 startCommand = mkStartCommand ({ 103 pxe = ipxeBootDir; 104 } // extraConfig); 105 in 106 makeTest { 107 name = "boot-netboot-" + name; 108 nodes = { }; 109 testScript = '' 110 machine = create_machine("${startCommand}") 111 machine.start() 112 machine.wait_for_unit("multi-user.target") 113 machine.shutdown() 114 ''; 115 }; 116in { 117 uefiCdrom = makeBootTest "uefi-cdrom" { 118 uefi = true; 119 cdrom = "${iso}/iso/${iso.isoName}"; 120 }; 121 122 uefiUsb = makeBootTest "uefi-usb" { 123 uefi = true; 124 usb = "${iso}/iso/${iso.isoName}"; 125 }; 126 127 uefiNetboot = makeNetbootTest "uefi" { 128 uefi = true; 129 }; 130} // lib.optionalAttrs (pkgs.stdenv.hostPlatform.system == "x86_64-linux") { 131 biosCdrom = makeBootTest "bios-cdrom" { 132 cdrom = "${iso}/iso/${iso.isoName}"; 133 }; 134 135 biosUsb = makeBootTest "bios-usb" { 136 usb = "${iso}/iso/${iso.isoName}"; 137 }; 138 139 biosNetboot = makeNetbootTest "bios" {}; 140 141 ubootExtlinux = let 142 sdImage = "${sd}/sd-image/${sd.imageName}"; 143 mutableImage = "/tmp/linked-image.qcow2"; 144 145 startCommand = mkStartCommand { 146 extraFlags = [ 147 "-bios" "${pkgs.ubootQemuX86}/u-boot.rom" 148 "-machine" "type=pc,accel=tcg" 149 "-drive" "file=${mutableImage},if=virtio" 150 ]; 151 }; 152 in makeTest { 153 name = "boot-uboot-extlinux"; 154 nodes = { }; 155 testScript = '' 156 import os 157 158 # Create a mutable linked image backed by the read-only SD image 159 if os.system("qemu-img create -f qcow2 -F raw -b ${sdImage} ${mutableImage}") != 0: 160 raise RuntimeError("Could not create mutable linked image") 161 162 machine = create_machine("${startCommand}") 163 machine.start() 164 machine.wait_for_unit("multi-user.target") 165 machine.succeed("nix store verify -r --no-trust --option experimental-features nix-command /run/current-system") 166 machine.shutdown() 167 ''; 168 169 # kernel can't find rootfs after boot - investigate? 170 meta.broken = true; 171 }; 172}