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;
7
8let kernel = config.boot.kernelPackages.kernel; in
9
10{
11
12 config = {
13
14 systemd.services.backdoor =
15 { wantedBy = [ "multi-user.target" ];
16 requires = [ "dev-hvc0.device" "dev-ttyS0.device" ];
17 after = [ "dev-hvc0.device" "dev-ttyS0.device" ];
18 script =
19 ''
20 export USER=root
21 export HOME=/root
22 export DISPLAY=:0.0
23
24 source /etc/profile
25
26 # Don't use a pager when executing backdoor
27 # actions. Because we use a tty, commands like systemctl
28 # or nix-store get confused into thinking they're running
29 # interactively.
30 export PAGER=
31
32 cd /tmp
33 exec < /dev/hvc0 > /dev/hvc0
34 while ! exec 2> /dev/ttyS0; do sleep 0.1; done
35 echo "connecting to host..." >&2
36 stty -F /dev/hvc0 raw -echo # prevent nl -> cr/nl conversion
37 echo
38 PS1= exec /bin/sh
39 '';
40 serviceConfig.KillSignal = "SIGHUP";
41 };
42
43 # Prevent agetty from being instantiated on ttyS0, since it
44 # interferes with the backdoor (writes to ttyS0 will randomly fail
45 # with EIO). Likewise for hvc0.
46 systemd.services."serial-getty@ttyS0".enable = false;
47 systemd.services."serial-getty@hvc0".enable = false;
48
49 boot.initrd.preDeviceCommands =
50 ''
51 echo 600 > /proc/sys/kernel/hung_task_timeout_secs
52 '';
53
54 boot.initrd.postDeviceCommands =
55 ''
56 # Using acpi_pm as a clock source causes the guest clock to
57 # slow down under high host load. This is usually a bad
58 # thing, but for VM tests it should provide a bit more
59 # determinism (e.g. if the VM runs at lower speed, then
60 # timeouts in the VM should also be delayed).
61 echo acpi_pm > /sys/devices/system/clocksource/clocksource0/current_clocksource
62 '';
63
64 boot.postBootCommands =
65 ''
66 # Panic on out-of-memory conditions rather than letting the
67 # OOM killer randomly get rid of processes, since this leads
68 # to failures that are hard to diagnose.
69 echo 2 > /proc/sys/vm/panic_on_oom
70
71 # Coverage data is written into /tmp/coverage-data.
72 mkdir -p /tmp/xchg/coverage-data
73 '';
74
75 # If the kernel has been built with coverage instrumentation, make
76 # it available under /proc/gcov.
77 boot.kernelModules = [ "gcov-proc" ];
78
79 # Panic if an error occurs in stage 1 (rather than waiting for
80 # user intervention).
81 boot.kernelParams =
82 [ "console=ttyS0" "panic=1" "boot.panic_on_fail" ];
83
84 # `xwininfo' is used by the test driver to query open windows.
85 environment.systemPackages = [ pkgs.xorg.xwininfo ];
86
87 # Log everything to the serial console.
88 services.journald.extraConfig =
89 ''
90 ForwardToConsole=yes
91 MaxLevelConsole=debug
92 '';
93
94 # Don't clobber the console with duplicate systemd messages.
95 systemd.extraConfig = "ShowStatus=no";
96
97 boot.consoleLogLevel = 7;
98
99 # Prevent tests from accessing the Internet.
100 networking.defaultGateway = mkOverride 150 "";
101 networking.nameservers = mkOverride 150 [ ];
102
103 systemd.globalEnvironment.GCOV_PREFIX = "/tmp/xchg/coverage-data";
104
105 system.requiredKernelConfig = with config.lib.kernelConfig; [
106 (isYes "SERIAL_8250_CONSOLE")
107 (isYes "SERIAL_8250")
108 (isEnabled "VIRTIO_CONSOLE")
109 ];
110
111 networking.usePredictableInterfaceNames = false;
112
113 # Make it easy to log in as root when running the test interactively.
114 users.extraUsers.root.initialHashedPassword = mkOverride 150 "";
115
116 services.xserver.displayManager.logToJournal = true;
117
118 # Bump kdm's X server start timeout to account for heavily loaded
119 # VM host systems.
120 services.xserver.displayManager.kdm.extraConfig =
121 ''
122 [X-:*-Core]
123 ServerTimeout=240
124 '';
125
126 };
127
128}