about summary refs log tree commit diff
path: root/nixos/tests/pulseaudio.nix
blob: dc8e33ccd559cad27f363ae5ae257e0270264318 (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
let
  mkTest = { systemWide ? false , fullVersion ? false }:
    import ./make-test-python.nix ({ pkgs, lib, ... }:
      let
        testFile = pkgs.fetchurl {
          url =
            "https://file-examples.com/storage/fe5947fd2362fc197a3c2df/2017/11/file_example_MP3_700KB.mp3";
          hash = "sha256-+iggJW8s0/LfA/okfXsB550/55Q0Sq3OoIzuBrzOPJQ=";
        };

        makeTestPlay = key:
          { sox, alsa-utils }:
          pkgs.writeScriptBin key ''
            set -euxo pipefail
            ${sox}/bin/play ${testFile}
            ${sox}/bin/sox ${testFile} -t wav - | ${alsa-utils}/bin/aplay
            touch /tmp/${key}_success
          '';

        testers = builtins.mapAttrs makeTestPlay {
          testPlay = { inherit (pkgs) sox alsa-utils; };
          testPlay32 = { inherit (pkgs.pkgsi686Linux) sox alsa-utils; };
        };
      in {
        name = "pulseaudio${lib.optionalString fullVersion "Full"}${lib.optionalString systemWide "-systemWide"}";
        meta = with pkgs.lib.maintainers; {
          maintainers = [ synthetica ] ++ pkgs.pulseaudio.meta.maintainers;
        };

        nodes.machine = { ... }:

          {
            imports = [ ./common/wayland-cage.nix ];
            hardware.pulseaudio = {
              enable = true;
              support32Bit = true;
              inherit systemWide;
            } // lib.optionalAttrs fullVersion {
              package = pkgs.pulseaudioFull;
            };

            environment.systemPackages = [ testers.testPlay pkgs.pavucontrol ]
              ++ lib.optional pkgs.stdenv.isx86_64 testers.testPlay32;
          } // lib.optionalAttrs systemWide {
            users.users.alice.extraGroups = [ "pulse-access" ];
            systemd.services.pulseaudio.wantedBy = [ "multi-user.target" ];
          };

        enableOCR = true;

        testScript = { ... }: ''
          machine.wait_until_succeeds("pgrep xterm")
          machine.wait_for_text("alice@machine")

          machine.send_chars("testPlay \n")
          machine.wait_for_file("/tmp/testPlay_success")
          ${lib.optionalString pkgs.stdenv.isx86_64 ''
            machine.send_chars("testPlay32 \n")
            machine.wait_for_file("/tmp/testPlay32_success")
          ''}
          machine.screenshot("testPlay")

          ${lib.optionalString (!systemWide) ''
            machine.send_chars("pacmd info && touch /tmp/pacmd_success\n")
            machine.wait_for_file("/tmp/pacmd_success")
          ''}

          # Pavucontrol only loads when Pulseaudio is running. If it isn't, the
          # text "Dummy Output" (sound device name) will never show.
          machine.send_chars("pavucontrol\n")
          machine.wait_for_text("Dummy Output")
          machine.screenshot("Pavucontrol")
        '';
      });
in builtins.mapAttrs (key: val: mkTest val) {
  user = { systemWide = false; fullVersion = false; };
  system = { systemWide = true; fullVersion = false; };
  userFull = { systemWide = false; fullVersion = true; };
  systemFull = { systemWide = true; fullVersion = true; };
}