1 { system ? builtins.currentSystem,
3 pkgs ? import ../.. { inherit system config; }
6 with import ../lib/testing-python.nix { inherit system pkgs; };
14 { imports = [ ./common/user-account.nix ./common/x11.nix ];
15 hardware.graphics.enable = true;
16 virtualisation.memorySize = 384;
18 systemPackages = [ pkgs.armagetronad ];
19 variables.XAUTHORITY = "/home/${user}/.Xauthority";
21 test-support.displayManager.auto.user = user;
26 name = "armagetronad";
27 meta = with pkgs.lib.maintainers; {
28 maintainers = [ numinit ];
36 services.armagetronad.servers = {
39 name = "Smoke Test High Rubber Server";
42 SERVER_OPTIONS = "High Rubber server made to run smoke tests.";
48 "NixOS Smoke Test Server"
55 name = "Smoke Test sty+ct+ap Server";
56 package = pkgs.armagetronad."0.2.9-sty+ct+ap".dedicated;
59 SERVER_OPTIONS = "sty+ct+ap server made to run smoke tests.";
65 "NixOS Smoke Test sty+ct+ap Server"
72 name = "Smoke Test trunk Server";
73 package = pkgs.armagetronad."0.4".dedicated;
76 SERVER_OPTIONS = "0.4 server made to run smoke tests.";
82 "NixOS Smoke Test 0.4 Server"
96 xdoScript = pkgs.writeText "${name}.xdo" text;
97 in "${pkgs.xdotool}/bin/xdotool ${xdoScript}";
102 from collections import namedtuple
104 class Client(namedtuple('Client', ('node', 'name'))):
105 def send(self, *keys):
107 self.node.send_key(key)
109 def send_on(self, text, *keys):
110 self.node.wait_for_text(text)
113 Server = namedtuple('Server', ('node', 'name', 'address', 'port', 'welcome', 'attacker', 'victim', 'coredump_delay'))
115 # Clients and their in-game names
117 Client(client1, 'Arduino'),
118 Client(client2, 'SmOoThIcE')
123 Server(server, 'high-rubber', 'server', 4534, 'NixOS Smoke Test Server', 'SmOoThIcE', 'Arduino', 8),
124 Server(server, 'sty', 'server', 4535, 'NixOS Smoke Test sty+ct+ap Server', 'Arduino', 'SmOoThIcE', 8),
125 Server(server, 'trunk', 'server', 4536, 'NixOS Smoke Test 0.4 Server', 'Arduino', 'SmOoThIcE', 8)
129 Runs a command as the client user.
132 return "su - ${user} -c " + shlex.quote(cmd)
137 Takes screenshots on all clients.
139 def take_screenshots(screenshot_idx):
140 for client in clients:
141 client.node.screenshot(f"screen_{client.name}_{screenshot_idx}")
142 return screenshot_idx + 1
144 # Wait for the servers to come up.
147 srv.node.wait_for_unit(f"armagetronad-{srv.name}")
148 srv.node.wait_until_succeeds(f"ss --numeric --udp --listening | grep -q {srv.port}")
150 # Make sure console commands work through the named pipe we created.
153 f"echo 'say Testing!' >> /var/lib/armagetronad/{srv.name}/input"
156 f"echo 'say Testing again!' >> /var/lib/armagetronad/{srv.name}/input"
158 srv.node.wait_until_succeeds(
159 f"journalctl -u armagetronad-{srv.name} -e | grep -q 'Admin: Testing!'"
161 srv.node.wait_until_succeeds(
162 f"journalctl -u armagetronad-{srv.name} -e | grep -q 'Admin: Testing again!'"
166 Sets up a client, waiting for the given barrier on completion.
168 def client_setup(client, servers, barrier):
169 client.node.wait_for_x()
171 # Configure Armagetron.
173 run("mkdir -p ~/.armagetronad/var"),
174 run(f"echo 'PLAYER_1 {client.name}' >> ~/.armagetronad/var/autoexec.cfg")
176 for idx, srv in enumerate(servers):
178 run(f"echo 'BOOKMARK_{idx+1}_ADDRESS {srv.address}' >> ~/.armagetronad/var/autoexec.cfg"),
179 run(f"echo 'BOOKMARK_{idx+1}_NAME {srv.name}' >> ~/.armagetronad/var/autoexec.cfg"),
180 run(f"echo 'BOOKMARK_{idx+1}_PORT {srv.port}' >> ~/.armagetronad/var/autoexec.cfg")
184 client.node.succeed(run("ulimit -c unlimited; armagetronad >&2 & disown"))
185 client.node.wait_until_succeeds(
187 "${xdo "create_new_win-select_main_window" ''
188 search --onlyvisible --name "Armagetron Advanced"
190 windowactivate --sync
195 # Get through the tutorial.
196 client.send_on('Language Settings', 'ret')
197 client.send_on('First Setup', 'ret')
198 client.send_on('Welcome to Armagetron Advanced', 'ret')
199 client.send_on('round 1', 'esc')
200 client.send_on('Menu', 'up', 'up', 'ret')
201 client.send_on('We hope you', 'ret')
202 client.send_on('Armagetron Advanced', 'ret')
203 client.send_on('Play Game', 'ret')
205 # Online > LAN > Network Setup > Mates > Server Bookmarks
206 client.send_on('Multiplayer', 'down', 'down', 'down', 'down', 'ret')
210 # Get to the Server Bookmarks screen on both clients. This takes a while so do it asynchronously.
211 barrier = threading.Barrier(len(clients) + 1, timeout=240)
212 for client in clients:
213 threading.Thread(target=client_setup, args=(client, servers, barrier)).start()
216 # Main testing loop. Iterates through each server bookmark and connects to them in sequence.
217 # Assumes that the game is currently on the Server Bookmarks screen.
219 screenshot_idx = take_screenshots(screenshot_idx)
221 # Connect both clients at once, one second apart.
222 for client in clients:
226 # Wait for clients to connect
227 for client in clients:
228 srv.node.wait_until_succeeds(
229 f"journalctl -u armagetronad-{srv.name} -e | grep -q '{client.name}.*entered the game'"
232 # Wait for the match to start
233 srv.node.wait_until_succeeds(
234 f"journalctl -u armagetronad-{srv.name} -e | grep -q 'Admin: {srv.welcome}'"
236 srv.node.wait_until_succeeds(
237 f"journalctl -u armagetronad-{srv.name} -e | grep -q 'Admin: https://nixos.org'"
239 srv.node.wait_until_succeeds(
240 f"journalctl -u armagetronad-{srv.name} -e | grep -q 'Go (round 1 of 10)'"
244 srv.node.sleep(srv.coredump_delay)
246 # Turn the attacker player's lightcycle left
247 attacker = next(client for client in clients if client.name == srv.attacker)
248 victim = next(client for client in clients if client.name == srv.victim)
249 attacker.send('left')
250 screenshot_idx = take_screenshots(screenshot_idx)
253 srv.node.wait_until_succeeds(
254 f"journalctl -u armagetronad-{srv.name} -e | grep -q '{attacker.name} core dumped {victim.name}'"
256 screenshot_idx = take_screenshots(screenshot_idx)
258 # Disconnect both clients from the server
259 for client in clients:
261 client.send_on('Menu', 'up', 'up', 'ret')
262 srv.node.wait_until_succeeds(
263 f"journalctl -u armagetronad-{srv.name} -e | grep -q '{client.name}.*left the game'"
267 for client in clients:
268 client.send_on('Server Bookmarks', 'down')
273 f"systemctl stop armagetronad-{srv.name}"
275 srv.node.wait_until_fails(f"ss --numeric --udp --listening | grep -q {srv.port}")