1let
2 mkTest =
3 {
4 systemWide ? false,
5 fullVersion ? false,
6 }:
7 import ./make-test-python.nix (
8 { pkgs, lib, ... }:
9 let
10 testFile = pkgs.fetchurl {
11 url = "https://file-examples.com/storage/fe5947fd2362fc197a3c2df/2017/11/file_example_MP3_700KB.mp3";
12 hash = "sha256-+iggJW8s0/LfA/okfXsB550/55Q0Sq3OoIzuBrzOPJQ=";
13 };
14
15 makeTestPlay =
16 key:
17 { sox, alsa-utils }:
18 pkgs.writeScriptBin key ''
19 set -euxo pipefail
20 ${sox}/bin/play ${testFile}
21 ${sox}/bin/sox ${testFile} -t wav - | ${alsa-utils}/bin/aplay
22 touch /tmp/${key}_success
23 '';
24
25 testers = builtins.mapAttrs makeTestPlay {
26 testPlay = { inherit (pkgs) sox alsa-utils; };
27 testPlay32 = { inherit (pkgs.pkgsi686Linux) sox alsa-utils; };
28 };
29 in
30 {
31 name = "pulseaudio${lib.optionalString fullVersion "Full"}${lib.optionalString systemWide "-systemWide"}";
32 meta = with pkgs.lib.maintainers; {
33 maintainers = [ synthetica ] ++ pkgs.pulseaudio.meta.maintainers;
34 };
35
36 nodes.machine =
37 { ... }:
38
39 {
40 imports = [ ./common/wayland-cage.nix ];
41 services.pulseaudio = {
42 enable = true;
43 support32Bit = true;
44 inherit systemWide;
45 }
46 // lib.optionalAttrs fullVersion {
47 package = pkgs.pulseaudioFull;
48 };
49
50 environment.systemPackages = [
51 testers.testPlay
52 pkgs.pavucontrol
53 ]
54 ++ lib.optional pkgs.stdenv.hostPlatform.isx86_64 testers.testPlay32;
55 }
56 // lib.optionalAttrs systemWide {
57 users.users.alice.extraGroups = [ "pulse-access" ];
58 systemd.services.pulseaudio.wantedBy = [ "multi-user.target" ];
59 };
60
61 enableOCR = true;
62
63 testScript =
64 { ... }:
65 ''
66 machine.wait_until_succeeds("pgrep xterm")
67 machine.wait_for_text("alice@machine")
68
69 machine.send_chars("testPlay \n")
70 machine.wait_for_file("/tmp/testPlay_success")
71 ${lib.optionalString pkgs.stdenv.hostPlatform.isx86_64 ''
72 machine.send_chars("testPlay32 \n")
73 machine.wait_for_file("/tmp/testPlay32_success")
74 ''}
75 machine.screenshot("testPlay")
76
77 ${lib.optionalString (!systemWide) ''
78 machine.send_chars("pacmd info && touch /tmp/pacmd_success\n")
79 machine.wait_for_file("/tmp/pacmd_success")
80 ''}
81
82 # Pavucontrol only loads when Pulseaudio is running. If it isn't, the
83 # text "Dummy Output" (sound device name) will never show.
84 machine.send_chars("pavucontrol\n")
85 machine.wait_for_text("Dummy Output")
86 machine.screenshot("Pavucontrol")
87 '';
88 }
89 );
90in
91builtins.mapAttrs (key: val: mkTest val) {
92 user = {
93 systemWide = false;
94 fullVersion = false;
95 };
96 system = {
97 systemWide = true;
98 fullVersion = false;
99 };
100 userFull = {
101 systemWide = false;
102 fullVersion = true;
103 };
104 systemFull = {
105 systemWide = true;
106 fullVersion = true;
107 };
108}