at master 2.0 kB view raw
1import ./make-test-python.nix ( 2 { lib, ... }: 3 4 { 5 name = "swapspace"; 6 7 meta = with lib.maintainers; { 8 maintainers = [ 9 Luflosi 10 phanirithvij 11 ]; 12 }; 13 14 nodes.machine = { 15 virtualisation.memorySize = 512; 16 17 services.swapspace = { 18 enable = true; 19 extraArgs = [ "-v" ]; 20 settings = { 21 # test outside /var/lib/swapspace 22 swappath = "/swamp"; 23 cooldown = 1; 24 }; 25 }; 26 27 swapDevices = lib.mkOverride 0 [ 28 { 29 size = 127; 30 device = "/root/swapfile"; 31 } 32 ]; 33 boot.kernel.sysctl."vm.swappiness" = 60; 34 }; 35 36 testScript = '' 37 machine.wait_for_unit("multi-user.target") 38 machine.wait_for_unit("swapspace.service") 39 machine.wait_for_unit("root-swapfile.swap") 40 41 # ensure swapspace wrapper command runs 42 machine.succeed("swapspace --inspect") 43 44 swamp = False 45 with subtest("swapspace works"): 46 machine.execute("mkdir /root/memfs") 47 machine.execute("mount -o size=2G -t tmpfs none /root/memfs") 48 i = 0 49 while i < 14: 50 print(machine.succeed("free -h")) 51 out = machine.succeed("sh -c 'swapon --show --noheadings --raw --bytes | grep /root/swapfile'") 52 row = out.split(' ') 53 # leave 1MB free to not get killed by oom 54 freebytes=int(row[2]) - int(row[3]) - 1*1024*1024 55 machine.succeed(f"dd if=/dev/random of=/root/memfs/{i} bs={freebytes} count=1") 56 machine.sleep(1) 57 out = machine.succeed("swapon --show") 58 print(out) 59 swamp = "/swamp" in out 60 if not swamp: 61 i += 1 62 else: 63 print("*"*10, "SWAPED", "*"*10) 64 machine.succeed("rm -f /root/memfs/*") 65 break 66 67 print(machine.succeed("swapspace -e -s /swamp")) 68 assert "/swamp" not in machine.execute("swapon --show") 69 assert swamp 70 ''; 71 } 72)