at 18.09-beta 4.7 kB view raw
1# This module allows the test driver to connect to the virtual machine 2# via a root shell attached to port 514. 3 4{ config, lib, pkgs, ... }: 5 6with lib; 7with import ../../lib/qemu-flags.nix { inherit pkgs; }; 8 9{ 10 11 # This option is a dummy that if used in conjunction with 12 # modules/virtualisation/qemu-vm.nix gets merged with the same option defined 13 # there and only is declared here because some modules use 14 # test-instrumentation.nix but not qemu-vm.nix. 15 # 16 # One particular example are the boot tests where we want instrumentation 17 # within the images but not other stuff like setting up 9p filesystems. 18 options.virtualisation.qemu.program = mkOption { type = types.path; }; 19 20 config = { 21 22 systemd.services.backdoor = 23 { wantedBy = [ "multi-user.target" ]; 24 requires = [ "dev-hvc0.device" "dev-${qemuSerialDevice}.device" ]; 25 after = [ "dev-hvc0.device" "dev-${qemuSerialDevice}.device" ]; 26 script = 27 '' 28 export USER=root 29 export HOME=/root 30 export DISPLAY=:0.0 31 32 source /etc/profile 33 34 # Don't use a pager when executing backdoor 35 # actions. Because we use a tty, commands like systemctl 36 # or nix-store get confused into thinking they're running 37 # interactively. 38 export PAGER= 39 40 cd /tmp 41 exec < /dev/hvc0 > /dev/hvc0 42 while ! exec 2> /dev/${qemuSerialDevice}; do sleep 0.1; done 43 echo "connecting to host..." >&2 44 stty -F /dev/hvc0 raw -echo # prevent nl -> cr/nl conversion 45 echo 46 PS1= exec /bin/sh 47 ''; 48 serviceConfig.KillSignal = "SIGHUP"; 49 }; 50 51 # Prevent agetty from being instantiated on the serial device, since it 52 # interferes with the backdoor (writes to it will randomly fail 53 # with EIO). Likewise for hvc0. 54 systemd.services."serial-getty@${qemuSerialDevice}".enable = false; 55 systemd.services."serial-getty@hvc0".enable = false; 56 57 # Only use a serial console, no TTY. 58 virtualisation.qemu.consoles = [ qemuSerialDevice ]; 59 60 boot.initrd.preDeviceCommands = 61 '' 62 echo 600 > /proc/sys/kernel/hung_task_timeout_secs 63 ''; 64 65 boot.initrd.postDeviceCommands = 66 '' 67 # Using acpi_pm as a clock source causes the guest clock to 68 # slow down under high host load. This is usually a bad 69 # thing, but for VM tests it should provide a bit more 70 # determinism (e.g. if the VM runs at lower speed, then 71 # timeouts in the VM should also be delayed). 72 echo acpi_pm > /sys/devices/system/clocksource/clocksource0/current_clocksource 73 ''; 74 75 boot.postBootCommands = 76 '' 77 # Panic on out-of-memory conditions rather than letting the 78 # OOM killer randomly get rid of processes, since this leads 79 # to failures that are hard to diagnose. 80 echo 2 > /proc/sys/vm/panic_on_oom 81 82 # Coverage data is written into /tmp/coverage-data. 83 mkdir -p /tmp/xchg/coverage-data 84 ''; 85 86 # If the kernel has been built with coverage instrumentation, make 87 # it available under /proc/gcov. 88 boot.kernelModules = [ "gcov-proc" ]; 89 90 # Panic if an error occurs in stage 1 (rather than waiting for 91 # user intervention). 92 boot.kernelParams = 93 [ "console=${qemuSerialDevice}" "panic=1" "boot.panic_on_fail" ]; 94 95 # `xwininfo' is used by the test driver to query open windows. 96 environment.systemPackages = [ pkgs.xorg.xwininfo ]; 97 98 # Log everything to the serial console. 99 services.journald.extraConfig = 100 '' 101 ForwardToConsole=yes 102 MaxLevelConsole=debug 103 ''; 104 105 systemd.extraConfig = '' 106 # Don't clobber the console with duplicate systemd messages. 107 ShowStatus=no 108 # Allow very slow start 109 DefaultTimeoutStartSec=300 110 ''; 111 112 boot.consoleLogLevel = 7; 113 114 # Prevent tests from accessing the Internet. 115 networking.defaultGateway = mkOverride 150 ""; 116 networking.nameservers = mkOverride 150 [ ]; 117 118 systemd.globalEnvironment.GCOV_PREFIX = "/tmp/xchg/coverage-data"; 119 120 system.requiredKernelConfig = with config.lib.kernelConfig; [ 121 (isYes "SERIAL_8250_CONSOLE") 122 (isYes "SERIAL_8250") 123 (isEnabled "VIRTIO_CONSOLE") 124 ]; 125 126 networking.usePredictableInterfaceNames = false; 127 128 # Make it easy to log in as root when running the test interactively. 129 users.users.root.initialHashedPassword = mkOverride 150 ""; 130 131 services.xserver.displayManager.job.logToJournal = true; 132 133 # set default stateVersion to avoid warnings during eval 134 system.stateVersion = mkDefault "18.03"; 135 }; 136 137}