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")
108 justThePackage = makeTest {
109 name = "atop-justThePackage";
111 environment.systemPackages = [ pkgs.atop ];
113 testScript = with assertions; builtins.concatStringsSep "\n" [
118 (atopRotateTimer false)
119 (atopacctService false)
124 defaults = makeTest {
125 name = "atop-defaults";
131 testScript = with assertions; builtins.concatStringsSep "\n" [
136 (atopRotateTimer true)
137 (atopacctService true)
143 name = "atop-minimal";
147 atopService.enable = false;
148 atopRotateTimer.enable = false;
149 atopacctService.enable = false;
152 testScript = with assertions; builtins.concatStringsSep "\n" [
157 (atopRotateTimer false)
158 (atopacctService false)
164 name = "atop-netatop";
168 netatop.enable = true;
171 testScript = with assertions; builtins.concatStringsSep "\n" [
176 (atopRotateTimer true)
177 (atopacctService true)
183 name = "atop-atopgpu";
187 atopgpu.enable = true;
190 testScript = with assertions; builtins.concatStringsSep "\n" [
195 (atopRotateTimer true)
196 (atopacctService true)
201 everything = makeTest {
202 name = "atop-everthing";
210 setuidWrapper.enable = true;
211 netatop.enable = true;
212 atopgpu.enable = true;
215 testScript = with assertions; builtins.concatStringsSep "\n" [
217 (atoprc "flags faf1\\ninterval 2\\n")
220 (atopRotateTimer true)
221 (atopacctService true)