summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Hilhorst <git@hilhorst.be>2021-12-30 11:04:36 +0100
committerGitHub <noreply@github.com>2021-12-30 11:04:36 +0100
commit59c187f2c3ebd0c19a3e029b1ede3c0aeeb1fc81 (patch)
treefd51d8541056ae1fc891efe738585c330c1d5981
parent0630d5c38180af29fc40323ed485e0e9d4b2c9a3 (diff)
parent5e29d3ce2e1ac2a4fa454ca1c2ec9ecd2a79260e (diff)
Merge pull request #148217 from Synthetica9/pulseaudio-test
-rw-r--r--nixos/tests/all-tests.nix1
-rw-r--r--nixos/tests/pulseaudio.nix71
2 files changed, 72 insertions, 0 deletions
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index 09cd26a76692..63a990d3d810 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -398,6 +398,7 @@ in
proxy = handleTest ./proxy.nix {};
prowlarr = handleTest ./prowlarr.nix {};
pt2-clone = handleTest ./pt2-clone.nix {};
+ pulseaudio = discoverTests (import ./pulseaudio.nix);
qboot = handleTestOn ["x86_64-linux" "i686-linux"] ./qboot.nix {};
quorum = handleTest ./quorum.nix {};
rabbitmq = handleTest ./rabbitmq.nix {};
diff --git a/nixos/tests/pulseaudio.nix b/nixos/tests/pulseaudio.nix
new file mode 100644
index 000000000000..4e2ce679acd7
--- /dev/null
+++ b/nixos/tests/pulseaudio.nix
@@ -0,0 +1,71 @@
+let
+ mkTest = { systemWide ? false }:
+ import ./make-test-python.nix ({ pkgs, lib, ... }:
+ let
+ testFile = pkgs.fetchurl {
+ url =
+ "https://file-examples-com.github.io/uploads/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 systemWide "-systemWide"}";
+ meta = with pkgs.lib.maintainers; {
+ maintainers = [ synthetica ] ++ pkgs.pulseaudio.meta.maintainers;
+ };
+
+ machine = { ... }:
+
+ {
+ imports = [ ./common/wayland-cage.nix ];
+ hardware.pulseaudio = {
+ enable = true;
+ support32Bit = true;
+ inherit systemWide;
+ };
+
+ environment.systemPackages = [ testers.testPlay pkgs.pavucontrol ]
+ ++ lib.optional pkgs.stdenv.isx86_64 testers.testPlay32;
+ } // lib.optionalAttrs systemWide {
+ users.users.alice.extraGroups = [ "audio" ];
+ 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")
+
+ # Pavucontrol only loads when Pulseaudio is running. If it isn't, the
+ # text "Playback" (one of the tabs) will never show.
+ machine.send_chars("pavucontrol\n")
+ machine.wait_for_text("Playback")
+ machine.screenshot("Pavucontrol")
+ '';
+ });
+in builtins.mapAttrs (key: val: mkTest val) {
+ user = { systemWide = false; };
+ system = { systemWide = true; };
+}