summaryrefslogtreecommitdiffstats
path: root/nixos/tests/zram-generator.nix
blob: 5f6432a78857a4d95bcb7ea13378b1dc1a837295 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
  name = "zram-generator";

  nodes = {
    single =
      { ... }:
      {
        virtualisation = {
          emptyDiskImages = [ 512 ];
        };
        zramSwap = {
          enable = true;
          priority = 10;
          algorithm = "lz4";
          swapDevices = 1;
          memoryPercent = 30;
          memoryMax = 10 * 1024 * 1024;
          writebackDevice = "/dev/vdb";
        };
      };
    machine =
      { ... }:
      {
        zramSwap = {
          enable = true;
          priority = 10;
          algorithm = "lz4";
          swapDevices = 2;
          memoryPercent = 30;
          memoryMax = 10 * 1024 * 1024;
        };
      };
  };

  testScript = ''
    single.wait_for_unit("systemd-zram-setup@zram0.service")

    machine.wait_for_unit("systemd-zram-setup@zram0.service")
    machine.wait_for_unit("systemd-zram-setup@zram1.service")
    zram = machine.succeed("zramctl --noheadings --raw")
    swap = machine.succeed("swapon --show --noheadings --raw")
    for i in range(2):
        assert f"/dev/zram{i} lz4 10M" in zram
        assert f"/dev/zram{i} partition 10M" in swap
  '';
}