1 { system ? builtins.currentSystem
3 , pkgs ? import ../.. { inherit system config; }
6 with import ../lib/testing-python.nix { inherit system pkgs; };
10 path = program: path: ''
11 with subtest("The path of ${program} should be ${path}"):
12 p = machine.succeed("type -p \"${program}\" | head -c -1")
13 assert p == "${path}", f"${program} is {p}, expected ${path}"
15 unit = name: state: ''
16 with subtest("Unit ${name} should be ${state}"):
17 if "${state}" == "active":
18 machine.wait_for_unit("${name}")
20 machine.require_unit_state("${name}", "${state}")
25 with subtest("binary should report the correct version"):
26 pkgver = "${pkgs.atop.version}"
27 ver = re.sub(r'(?s)^Version: (\d+\.\d+\.\d+).*', r'\1', machine.succeed("atop -V"))
28 assert ver == pkgver, f"Version is `{ver}`, expected `{pkgver}`"
31 if builtins.stringLength contents > 0 then ''
32 with subtest("/etc/atoprc should have the correct contents"):
33 f = machine.succeed("cat /etc/atoprc")
34 assert f == "${contents}", f"/etc/atoprc contents: '{f}', expected '${contents}'"
36 with subtest("/etc/atoprc should not be present"):
37 machine.succeed("test ! -e /etc/atoprc")
40 if present then path "atop" "/run/wrappers/bin/atop" + ''
41 with subtest("Wrapper should be setuid root"):
42 stat = machine.succeed("stat --printf '%a %u' /run/wrappers/bin/atop")
43 assert stat == "4511 0", f"Wrapper stat is {stat}, expected '4511 0'"
45 else path "atop" "/run/current-system/sw/bin/atop";
46 atopService = present:
48 unit "atop.service" "active"
50 with subtest("atop.service should write some data to /var/log/atop"):
52 def has_data_files(last: bool) -> bool:
53 files = int(machine.succeed("ls -1 /var/log/atop | wc -l"))
55 machine.log("Did not find at least one 1 data file")
57 machine.log("Will retry...")
61 with machine.nested("Waiting for data files"):
63 '' else unit "atop.service" "inactive";
64 atopRotateTimer = present:
65 unit "atop-rotate.timer" (if present then "active" else "inactive");
66 atopacctService = present:
68 unit "atopacct.service" "active"
70 with subtest("atopacct.service should enable process accounting"):
71 machine.wait_until_succeeds("test -f /run/pacct_source")
73 with subtest("atopacct.service should write data to /run/pacct_shadow.d"):
75 def has_data_files(last: bool) -> bool:
76 files = int(machine.succeed("ls -1 /run/pacct_shadow.d | wc -l"))
78 machine.log("Did not find at least one 1 data file")
80 machine.log("Will retry...")
84 with machine.nested("Waiting for data files"):
86 '' else unit "atopacct.service" "inactive";
89 unit "netatop.service" "active"
91 with subtest("The netatop kernel module should be loaded"):
92 out = machine.succeed("modprobe -n -v netatop")
93 assert out == "", f"Module should be loaded already, but modprobe would have done {out}."
95 with subtest("The netatop kernel module should be absent"):
96 machine.fail("modprobe -n -v netatop")
100 (unit "atopgpu.service" "active") + (path "atopgpud" "/run/current-system/sw/bin/atopgpud")
101 else (unit "atopgpu.service" "inactive") + ''
102 with subtest("atopgpud should not be present"):
103 machine.fail("type -p atopgpud")
111 justThePackage = makeTest {
112 name = "atop-justThePackage";
114 environment.systemPackages = [ pkgs.atop ];
116 testScript = with assertions; builtins.concatStringsSep "\n" [
121 (atopRotateTimer false)
122 (atopacctService false)
128 defaults = makeTest {
129 name = "atop-defaults";
135 testScript = with assertions; builtins.concatStringsSep "\n" [
140 (atopRotateTimer true)
141 (atopacctService true)
148 name = "atop-minimal";
152 atopService.enable = false;
153 atopRotateTimer.enable = false;
154 atopacctService.enable = false;
157 testScript = with assertions; builtins.concatStringsSep "\n" [
162 (atopRotateTimer false)
163 (atopacctService false)
170 name = "atop-netatop";
174 netatop.enable = true;
177 testScript = with assertions; builtins.concatStringsSep "\n" [
182 (atopRotateTimer true)
183 (atopacctService true)
190 name = "atop-atopgpu";
194 atopgpu.enable = true;
197 testScript = with assertions; builtins.concatStringsSep "\n" [
202 (atopRotateTimer true)
203 (atopacctService true)
209 everything = makeTest {
210 name = "atop-everything";
218 setuidWrapper.enable = true;
219 netatop.enable = true;
220 atopgpu.enable = true;
223 testScript = with assertions; builtins.concatStringsSep "\n" [
225 (atoprc "flags faf1\\ninterval 2\\n")
228 (atopRotateTimer true)
229 (atopacctService true)