at 23.05-pre 1.7 kB view raw
1import ./make-test-python.nix ({ pkgs, ... }: 2 3{ 4 name = "systemd-oomd"; 5 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"; 12 13 systemd.slices.workload = { 14 description = "Test slice for memory pressure kills"; 15 sliceConfig = { 16 MemoryAccounting = true; 17 ManagedOOMMemoryPressure = "kill"; 18 ManagedOOMMemoryPressureLimit = "10%"; 19 }; 20 }; 21 22 systemd.services.testbloat = { 23 description = "Create a lot of memory pressure"; 24 serviceConfig = { 25 Slice = "workload.slice"; 26 MemoryHigh = "5M"; 27 ExecStart = "${pkgs.coreutils}/bin/tail /dev/zero"; 28 }; 29 }; 30 31 systemd.services.testchill = { 32 description = "No memory pressure"; 33 serviceConfig = { 34 Slice = "workload.slice"; 35 MemoryHigh = "3M"; 36 ExecStart = "${pkgs.coreutils}/bin/sleep infinity"; 37 }; 38 }; 39 }; 40 41 testScript = '' 42 # Start the system. 43 machine.wait_for_unit("multi-user.target") 44 machine.succeed("oomctl") 45 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" 50 51 with subtest("Service without memory pressure should be untouched"): 52 machine.require_unit_state("testchill.service", "active") 53 ''; 54})