summary refs log tree commit diff
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2023-07-13 09:01:02 +0200
committerJan Tojnar <jtojnar@gmail.com>2023-07-13 19:12:22 +0200
commitd08e84b3be26b302686cd6a93d1e9791547350fe (patch)
tree24c68579f0f4b26cae7257a3dcac2fba805957ff
parentb9c867fdad9678b68342ee79b924a54692ca3fbc (diff)
downloadnixpkgs-d08e84b3be26b302686cd6a93d1e9791547350fe.tar
nixpkgs-d08e84b3be26b302686cd6a93d1e9791547350fe.tar.gz
nixpkgs-d08e84b3be26b302686cd6a93d1e9791547350fe.tar.bz2
nixpkgs-d08e84b3be26b302686cd6a93d1e9791547350fe.tar.lz
nixpkgs-d08e84b3be26b302686cd6a93d1e9791547350fe.tar.xz
nixpkgs-d08e84b3be26b302686cd6a93d1e9791547350fe.tar.zst
nixpkgs-d08e84b3be26b302686cd6a93d1e9791547350fe.zip
upower: Add installed tests
-rw-r--r--nixos/tests/installed-tests/default.nix1
-rw-r--r--nixos/tests/installed-tests/upower.nix9
-rw-r--r--pkgs/os-specific/linux/upower/default.nix46
-rw-r--r--pkgs/os-specific/linux/upower/installed-tests-path.patch56
4 files changed, 110 insertions, 2 deletions
diff --git a/nixos/tests/installed-tests/default.nix b/nixos/tests/installed-tests/default.nix
index 78a6325a245..e87edb2007e 100644
--- a/nixos/tests/installed-tests/default.nix
+++ b/nixos/tests/installed-tests/default.nix
@@ -107,5 +107,6 @@ in
   malcontent = callInstalledTest ./malcontent.nix {};
   ostree = callInstalledTest ./ostree.nix {};
   pipewire = callInstalledTest ./pipewire.nix {};
+  upower = callInstalledTest ./upower.nix {};
   xdg-desktop-portal = callInstalledTest ./xdg-desktop-portal.nix {};
 }
diff --git a/nixos/tests/installed-tests/upower.nix b/nixos/tests/installed-tests/upower.nix
new file mode 100644
index 00000000000..a8e777a5552
--- /dev/null
+++ b/nixos/tests/installed-tests/upower.nix
@@ -0,0 +1,9 @@
+{ pkgs, makeInstalledTest, ... }:
+
+makeInstalledTest {
+  tested = pkgs.upower;
+
+  testConfig = {
+    services.upower.enable = true;
+  };
+}
diff --git a/pkgs/os-specific/linux/upower/default.nix b/pkgs/os-specific/linux/upower/default.nix
index ac41ab5023f..8772c081e03 100644
--- a/pkgs/os-specific/linux/upower/default.nix
+++ b/pkgs/os-specific/linux/upower/default.nix
@@ -2,6 +2,7 @@
 , stdenv
 , fetchFromGitLab
 , fetchpatch
+, makeWrapper
 , pkg-config
 , rsync
 , libxslt
@@ -23,13 +24,14 @@
 , useIMobileDevice ? true
 , libimobiledevice
 , withDocs ? (stdenv.buildPlatform == stdenv.hostPlatform)
+, nixosTests
 }:
 
 stdenv.mkDerivation (finalAttrs: {
   pname = "upower";
   version = "1.90.2";
 
-  outputs = [ "out" "dev" ]
+  outputs = [ "out" "dev" "installedTests" ]
     ++ lib.optionals withDocs [ "devdoc" ];
 
   src = fetchFromGitLab {
@@ -44,6 +46,8 @@ stdenv.mkDerivation (finalAttrs: {
     # Remove when this is fixed upstream:
     # https://gitlab.freedesktop.org/upower/upower/-/issues/214
     ./i686-test-remove-battery-check.patch
+  ] ++ [
+    ./installed-tests-path.patch
   ];
 
   strictDeps = true;
@@ -61,6 +65,7 @@ stdenv.mkDerivation (finalAttrs: {
     gettext
     gobject-introspection
     libxslt
+    makeWrapper
     pkg-config
     rsync
   ];
@@ -72,6 +77,14 @@ stdenv.mkDerivation (finalAttrs: {
     systemd
     # Duplicate from nativeCheckInputs until https://github.com/NixOS/nixpkgs/issues/161570 is solved
     umockdev
+
+    # For installed tests.
+    (python3.withPackages (pp: [
+      pp.dbus-python
+      pp.python-dbusmock
+      pp.pygobject3
+      pp.packaging
+    ]))
   ] ++ lib.optionals useIMobileDevice [
     libimobiledevice
   ];
@@ -99,6 +112,7 @@ stdenv.mkDerivation (finalAttrs: {
     "-Dudevhwdbdir=${placeholder "out"}/lib/udev/hwdb.d"
     "-Dintrospection=${if (stdenv.buildPlatform == stdenv.hostPlatform) then "auto" else "disabled"}"
     "-Dgtk-doc=${lib.boolToString withDocs}"
+    "-Dinstalled_test_prefix=${placeholder "installedTests"}"
   ];
 
   doCheck = true;
@@ -106,6 +120,9 @@ stdenv.mkDerivation (finalAttrs: {
   postPatch = ''
     patchShebangs src/linux/integration-test.py
     patchShebangs src/linux/unittest_inspector.py
+
+    substituteInPlace src/linux/integration-test.py \
+      --replace "/usr/share/dbus-1" "$out/share/dbus-1"
   '';
 
   preCheck = ''
@@ -127,6 +144,14 @@ stdenv.mkDerivation (finalAttrs: {
     runHook postCheck
   '';
 
+  postCheck = ''
+    # Undo patchShebangs from postPatch so that it can be replaced with runtime shebang
+    # unittest_inspector.py intentionally not reverted because it would trigger
+    # meson rebuild during install and it is not used at runtime anyway.
+    sed -Ei 's~#!.+/bin/python3~#!/usr/bin/python3~' \
+      ../src/linux/integration-test.py
+  '';
+
   postInstall = ''
     # Move stuff from DESTDIR to proper location.
     # We use rsync to merge the directories.
@@ -134,7 +159,7 @@ stdenv.mkDerivation (finalAttrs: {
         rsync --archive "$DESTDIR/$dir" "$out"
         rm --recursive "$DESTDIR/$dir"
     done
-    for o in out dev; do
+    for o in out dev installedTests; do
         rsync --archive "$DESTDIR/''${!o}" "$(dirname "''${!o}")"
         rm --recursive "$DESTDIR/''${!o}"
     done
@@ -142,6 +167,17 @@ stdenv.mkDerivation (finalAttrs: {
     rmdir "$DESTDIR/nix/store" "$DESTDIR/nix" "$DESTDIR"
   '';
 
+  postFixup = ''
+    wrapProgram "$installedTests/libexec/upower/integration-test.py" \
+      --prefix GI_TYPELIB_PATH : "${lib.makeSearchPath "lib/girepository-1.0" [
+        "$out"
+        umockdev.out
+      ]}" \
+      --prefix PATH : "${lib.makeBinPath [
+        umockdev
+      ]}"
+  '';
+
   env = {
     # HACK: We want to install configuration files to $out/etc
     # but upower should read them from /etc on a NixOS system.
@@ -152,6 +188,12 @@ stdenv.mkDerivation (finalAttrs: {
     DESTDIR = "${placeholder "out"}/dest";
   };
 
+  passthru = {
+    tests = {
+      installedTests = nixosTests.installed-tests.upower;
+    };
+  };
+
   meta = with lib; {
     homepage = "https://upower.freedesktop.org/";
     changelog = "https://gitlab.freedesktop.org/upower/upower/-/blob/v${finalAttrs.version}/NEWS";
diff --git a/pkgs/os-specific/linux/upower/installed-tests-path.patch b/pkgs/os-specific/linux/upower/installed-tests-path.patch
new file mode 100644
index 00000000000..367f3eab096
--- /dev/null
+++ b/pkgs/os-specific/linux/upower/installed-tests-path.patch
@@ -0,0 +1,56 @@
+diff --git a/meson_options.txt b/meson_options.txt
+index eec3659..f064a1b 100644
+--- a/meson_options.txt
++++ b/meson_options.txt
+@@ -6,6 +6,10 @@ option('gtk-doc',
+        type : 'boolean',
+        value : 'true',
+        description : 'Build developer documentation')
++option('installed_test_prefix',
++       type: 'string',
++       value: '',
++       description: 'Prefix for installed tests')
+ option('introspection',
+        type : 'feature',
+        value : 'auto',
+diff --git a/src/meson.build b/src/meson.build
+index a2352ac..c1f25ac 100644
+--- a/src/meson.build
++++ b/src/meson.build
+@@ -85,6 +85,7 @@ install_subdir('does-not-exist', install_dir: historydir, strip_directory : true
+ 
+ cdata = configuration_data()
+ cdata.set('libexecdir', get_option('prefix') / get_option('libexecdir'))
++cdata.set('installed_test_bindir', get_option('installed_test_prefix') / 'libexec' / 'upower')
+ cdata.set('historydir', historydir)
+ 
+ configure_file(
+@@ -147,16 +148,16 @@ if os_backend == 'linux' and gobject_introspection.found()
+         'linux/integration-test.py',
+         'linux/output_checker.py',
+       ],
+-      install_dir: get_option('prefix') / get_option('libexecdir') / 'upower'
++      install_dir: get_option('installed_test_prefix') / 'libexec' / 'upower'
+     )
+     install_subdir('linux/tests/',
+-      install_dir: get_option('prefix') / get_option('libexecdir') / 'upower'
++      install_dir: get_option('installed_test_prefix') / 'libexec' / 'upower'
+     )
+ 
+     configure_file(
+       input: 'upower-integration.test.in',
+       output: 'upower-integration.test',
+-      install_dir: get_option('datadir') / 'installed-tests' / 'upower',
++      install_dir: get_option('installed_test_prefix') / 'share' / 'installed-tests' / 'upower',
+       configuration: cdata
+     )
+ endif
+diff --git a/src/upower-integration.test.in b/src/upower-integration.test.in
+index 151ded0..b0a9bec 100644
+--- a/src/upower-integration.test.in
++++ b/src/upower-integration.test.in
+@@ -1,3 +1,3 @@
+ [Test]
+ Type=session
+-Exec=@libexecdir@/upower/integration-test.py
++Exec=@installed_test_bindir@/integration-test.py