Loading nixos/tests/all-tests.nix +1 −0 Original line number Diff line number Diff line Loading @@ -971,6 +971,7 @@ in { swap-file-btrfs = handleTest ./swap-file-btrfs.nix {}; swap-partition = handleTest ./swap-partition.nix {}; swap-random-encryption = handleTest ./swap-random-encryption.nix {}; swapspace = handleTestOn ["aarch64-linux" "x86_64-linux"] ./swapspace.nix {}; sway = handleTest ./sway.nix {}; swayfx = handleTest ./swayfx.nix {}; switchTest = handleTest ./switch-test.nix { ng = false; }; Loading nixos/tests/swapspace.nix 0 → 100644 +69 −0 Original line number Diff line number Diff line import ./make-test-python.nix ( { pkgs, lib, ... }: { name = "swapspace"; meta = with pkgs.lib.maintainers; { maintainers = [ Luflosi phanirithvij ]; }; nodes.machine = { virtualisation.memorySize = 512; services.swapspace = { enable = true; extraArgs = [ "-v" ]; settings = { # test outside /var/lib/swapspace swappath = "/swamp"; cooldown = 1; }; }; swapDevices = lib.mkOverride 0 [ { size = 127; device = "/root/swapfile"; } ]; boot.kernel.sysctl."vm.swappiness" = 60; }; testScript = '' machine.wait_for_unit("multi-user.target") machine.wait_for_unit("swapspace.service") machine.wait_for_unit("root-swapfile.swap") swamp = False with subtest("swapspace works"): machine.execute("mkdir /root/memfs") machine.execute("mount -o size=2G -t tmpfs none /root/memfs") i = 0 while i < 14: print(machine.succeed("free -h")) out = machine.succeed("sh -c 'swapon --show --noheadings --raw --bytes | grep /root/swapfile'") row = out.split(' ') # leave 1MB free to not get killed by oom freebytes=int(row[2]) - int(row[3]) - 1*1024*1024 machine.succeed(f"dd if=/dev/random of=/root/memfs/{i} bs={freebytes} count=1") machine.sleep(1) out = machine.succeed("swapon --show") print(out) swamp = "/swamp" in out if not swamp: i += 1 else: print("*"*10, "SWAPED", "*"*10) machine.succeed("rm -f /root/memfs/*") break print(machine.succeed("swapspace -e -s /swamp")) assert "/swamp" not in machine.execute("swapon --show") assert swamp ''; } ) pkgs/tools/admin/swapspace/default.nix +14 −1 Original line number Diff line number Diff line { lib, stdenv, fetchFromGitHub, autoreconfHook, installShellFiles, util-linux, binlore, swapspace }: { lib, stdenv, fetchFromGitHub, autoreconfHook, installShellFiles, util-linux, binlore, swapspace, nixosTests, }: stdenv.mkDerivation rec { pname = "swapspace"; Loading Loading @@ -40,6 +50,9 @@ stdenv.mkDerivation rec { passthru.binlore.out = binlore.synthesize swapspace '' execer cannot bin/swapspace ''; passthru.tests = { inherit (nixosTests) swapspace; }; meta = with lib; { description = "Dynamic swap manager for Linux"; Loading Loading
nixos/tests/all-tests.nix +1 −0 Original line number Diff line number Diff line Loading @@ -971,6 +971,7 @@ in { swap-file-btrfs = handleTest ./swap-file-btrfs.nix {}; swap-partition = handleTest ./swap-partition.nix {}; swap-random-encryption = handleTest ./swap-random-encryption.nix {}; swapspace = handleTestOn ["aarch64-linux" "x86_64-linux"] ./swapspace.nix {}; sway = handleTest ./sway.nix {}; swayfx = handleTest ./swayfx.nix {}; switchTest = handleTest ./switch-test.nix { ng = false; }; Loading
nixos/tests/swapspace.nix 0 → 100644 +69 −0 Original line number Diff line number Diff line import ./make-test-python.nix ( { pkgs, lib, ... }: { name = "swapspace"; meta = with pkgs.lib.maintainers; { maintainers = [ Luflosi phanirithvij ]; }; nodes.machine = { virtualisation.memorySize = 512; services.swapspace = { enable = true; extraArgs = [ "-v" ]; settings = { # test outside /var/lib/swapspace swappath = "/swamp"; cooldown = 1; }; }; swapDevices = lib.mkOverride 0 [ { size = 127; device = "/root/swapfile"; } ]; boot.kernel.sysctl."vm.swappiness" = 60; }; testScript = '' machine.wait_for_unit("multi-user.target") machine.wait_for_unit("swapspace.service") machine.wait_for_unit("root-swapfile.swap") swamp = False with subtest("swapspace works"): machine.execute("mkdir /root/memfs") machine.execute("mount -o size=2G -t tmpfs none /root/memfs") i = 0 while i < 14: print(machine.succeed("free -h")) out = machine.succeed("sh -c 'swapon --show --noheadings --raw --bytes | grep /root/swapfile'") row = out.split(' ') # leave 1MB free to not get killed by oom freebytes=int(row[2]) - int(row[3]) - 1*1024*1024 machine.succeed(f"dd if=/dev/random of=/root/memfs/{i} bs={freebytes} count=1") machine.sleep(1) out = machine.succeed("swapon --show") print(out) swamp = "/swamp" in out if not swamp: i += 1 else: print("*"*10, "SWAPED", "*"*10) machine.succeed("rm -f /root/memfs/*") break print(machine.succeed("swapspace -e -s /swamp")) assert "/swamp" not in machine.execute("swapon --show") assert swamp ''; } )
pkgs/tools/admin/swapspace/default.nix +14 −1 Original line number Diff line number Diff line { lib, stdenv, fetchFromGitHub, autoreconfHook, installShellFiles, util-linux, binlore, swapspace }: { lib, stdenv, fetchFromGitHub, autoreconfHook, installShellFiles, util-linux, binlore, swapspace, nixosTests, }: stdenv.mkDerivation rec { pname = "swapspace"; Loading Loading @@ -40,6 +50,9 @@ stdenv.mkDerivation rec { passthru.binlore.out = binlore.synthesize swapspace '' execer cannot bin/swapspace ''; passthru.tests = { inherit (nixosTests) swapspace; }; meta = with lib; { description = "Dynamic swap manager for Linux"; Loading