at 25.11-pre 1.8 kB view raw
1import ./make-test-python.nix ( 2 { pkgs, ... }: 3 4 { 5 name = "systemd-oomd"; 6 7 # This test is a simplified version of systemd's testsuite-55. 8 # https://github.com/systemd/systemd/blob/v251/test/units/testsuite-55.sh 9 nodes.machine = 10 { pkgs, ... }: 11 { 12 # Limit VM resource usage. 13 virtualisation.memorySize = 1024; 14 systemd.oomd.extraConfig.DefaultMemoryPressureDurationSec = "1s"; 15 16 systemd.slices.workload = { 17 description = "Test slice for memory pressure kills"; 18 sliceConfig = { 19 MemoryAccounting = true; 20 ManagedOOMMemoryPressure = "kill"; 21 ManagedOOMMemoryPressureLimit = "10%"; 22 }; 23 }; 24 25 systemd.services.testbloat = { 26 description = "Create a lot of memory pressure"; 27 serviceConfig = { 28 Slice = "workload.slice"; 29 MemoryHigh = "5M"; 30 ExecStart = "${pkgs.coreutils}/bin/tail /dev/zero"; 31 }; 32 }; 33 34 systemd.services.testchill = { 35 description = "No memory pressure"; 36 serviceConfig = { 37 Slice = "workload.slice"; 38 MemoryHigh = "3M"; 39 ExecStart = "${pkgs.coreutils}/bin/sleep infinity"; 40 }; 41 }; 42 }; 43 44 testScript = '' 45 # Start the system. 46 machine.wait_for_unit("multi-user.target") 47 machine.succeed("oomctl") 48 49 machine.succeed("systemctl start testchill.service") 50 with subtest("OOMd should kill the bad service"): 51 machine.fail("systemctl start --wait testbloat.service") 52 assert machine.get_unit_info("testbloat.service")["Result"] == "oom-kill" 53 54 with subtest("Service without memory pressure should be untouched"): 55 machine.require_unit_state("testchill.service", "active") 56 ''; 57 } 58)