1 import ./make-test-python.nix ({ pkgs, ... }:
6 # This test is a simplified version of systemd's testsuite-55.
7 # https://github.com/systemd/systemd/blob/v251/test/units/testsuite-55.sh
8 nodes.machine = { pkgs, ... }: {
9 # Limit VM resource usage.
10 virtualisation.memorySize = 1024;
11 systemd.oomd.extraConfig.DefaultMemoryPressureDurationSec = "1s";
13 systemd.slices.workload = {
14 description = "Test slice for memory pressure kills";
16 MemoryAccounting = true;
17 ManagedOOMMemoryPressure = "kill";
18 ManagedOOMMemoryPressureLimit = "10%";
22 systemd.services.testbloat = {
23 description = "Create a lot of memory pressure";
25 Slice = "workload.slice";
27 ExecStart = "${pkgs.coreutils}/bin/tail /dev/zero";
31 systemd.services.testchill = {
32 description = "No memory pressure";
34 Slice = "workload.slice";
36 ExecStart = "${pkgs.coreutils}/bin/sleep infinity";
43 machine.wait_for_unit("multi-user.target")
44 machine.succeed("oomctl")
46 machine.succeed("systemctl start testchill.service")
47 with subtest("OOMd should kill the bad service"):
48 machine.fail("systemctl start --wait testbloat.service")
49 assert machine.get_unit_info("testbloat.service")["Result"] == "oom-kill"
51 with subtest("Service without memory pressure should be untouched"):
52 machine.require_unit_state("testchill.service", "active")