Merge pull request #72860 from worldofpeace/port-gnome3y-tests

Port gnome3 like tests to python and udisks2
This commit is contained in:
worldofpeace 2019-11-07 00:43:58 +00:00 committed by GitHub
commit a46c78142e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 262 additions and 277 deletions

View File

@ -48,7 +48,6 @@ in
clickhouse = handleTest ./clickhouse.nix {};
cloud-init = handleTest ./cloud-init.nix {};
codimd = handleTest ./codimd.nix {};
colord = handleTest ./colord.nix {};
containers-bridge = handleTest ./containers-bridge.nix {};
containers-ephemeral = handleTest ./containers-ephemeral.nix {};
containers-extra_veth = handleTest ./containers-extra_veth.nix {};
@ -88,27 +87,21 @@ in
firewall = handleTest ./firewall.nix {};
fish = handleTest ./fish.nix {};
flannel = handleTestOn ["x86_64-linux"] ./flannel.nix {};
flatpak = handleTest ./flatpak.nix {};
flatpak-builder = handleTest ./flatpak-builder.nix {};
fluentd = handleTest ./fluentd.nix {};
fontconfig-default-fonts = handleTest ./fontconfig-default-fonts.nix {};
fsck = handleTest ./fsck.nix {};
fwupd = handleTestOn ["x86_64-linux"] ./fwupd.nix {}; # libsmbios is unsupported on aarch64
gdk-pixbuf = handleTest ./gdk-pixbuf.nix {};
gotify-server = handleTest ./gotify-server.nix {};
gitea = handleTest ./gitea.nix {};
gitlab = handleTest ./gitlab.nix {};
gitolite = handleTest ./gitolite.nix {};
gjs = handleTest ./gjs.nix {};
glib-networking = handleTest ./glib-networking.nix {};
glusterfs = handleTest ./glusterfs.nix {};
gnome3-xorg = handleTest ./gnome3-xorg.nix {};
gnome3 = handleTest ./gnome3.nix {};
gnome-photos = handleTest ./gnome-photos.nix {};
installed-tests = pkgs.recurseIntoAttrs (handleTest ./installed-tests {});
gocd-agent = handleTest ./gocd-agent.nix {};
gocd-server = handleTest ./gocd-server.nix {};
google-oslogin = handleTest ./google-oslogin {};
graphene = handleTest ./graphene.nix {};
grafana = handleTest ./grafana.nix {};
graphite = handleTest ./graphite.nix {};
graylog = handleTest ./graylog.nix {};
@ -216,7 +209,6 @@ in
os-prober = handleTestOn ["x86_64-linux"] ./os-prober.nix {};
osquery = handleTest ./osquery.nix {};
osrm-backend = handleTest ./osrm-backend.nix {};
ostree = handleTest ./ostree.nix {};
overlayfs = handleTest ./overlayfs.nix {};
packagekit = handleTest ./packagekit.nix {};
pam-oath-login = handleTest ./pam-oath-login.nix {};
@ -291,7 +283,6 @@ in
wireguard-generated = handleTest ./wireguard/generated.nix {};
wordpress = handleTest ./wordpress.nix {};
xautolock = handleTest ./xautolock.nix {};
xdg-desktop-portal = handleTest ./xdg-desktop-portal.nix {};
xfce = handleTest ./xfce.nix {};
xfce4-14 = handleTest ./xfce4-14.nix {};
xmonad = handleTest ./xmonad.nix {};

View File

@ -1,18 +0,0 @@
# run installed tests
import ./make-test.nix ({ pkgs, ... }:
{
name = "colord";
meta = {
maintainers = pkgs.colord.meta.maintainers;
};
machine = { pkgs, ... }: {
environment.systemPackages = with pkgs; [ gnome-desktop-testing ];
};
testScript = ''
$machine->succeed("gnome-desktop-testing-runner -d '${pkgs.colord.installedTests}/share'");
'';
})

View File

@ -1,20 +0,0 @@
# run installed tests
import ./make-test.nix ({ pkgs, ... }:
{
name = "flatpak-builder";
meta = {
maintainers = pkgs.flatpak-builder.meta.maintainers;
};
machine = { pkgs, ... }: {
services.flatpak.enable = true;
xdg.portal.enable = true;
environment.systemPackages = with pkgs; [ gnome-desktop-testing flatpak-builder ] ++ flatpak-builder.installedTestsDependencies;
virtualisation.diskSize = 2048;
};
testScript = ''
$machine->succeed("gnome-desktop-testing-runner -d '${pkgs.flatpak-builder.installedTests}/share' --timeout 3600");
'';
})

View File

@ -1,26 +0,0 @@
# run installed tests
import ./make-test.nix ({ pkgs, ... }:
{
name = "flatpak";
meta = {
maintainers = pkgs.flatpak.meta.maintainers;
};
machine = { pkgs, ... }: {
imports = [ ./common/x11.nix ];
services.xserver.desktopManager.gnome3.enable = true; # TODO: figure out minimal environment where the tests work
# common/x11.nix enables the auto display manager (lightdm)
services.xserver.displayManager.gdm.enable = false;
environment.gnome3.excludePackages = pkgs.gnome3.optionalPackages;
services.flatpak.enable = true;
environment.systemPackages = with pkgs; [ gnupg gnome-desktop-testing ostree python2 ];
virtualisation.memorySize = 2047;
virtualisation.diskSize = 1024;
};
testScript = ''
$machine->waitForX();
$machine->succeed("gnome-desktop-testing-runner -d '${pkgs.flatpak.installedTests}/share' --timeout 3600");
'';
})

View File

@ -1,7 +1,12 @@
import ./make-test.nix ({ lib, ... }:
import ./make-test-python.nix ({ lib, ... }:
{
name = "fontconfig-default-fonts";
meta.maintainers = with lib.maintainers; [
jtojnar
worldofpeace
];
machine = { config, pkgs, ... }: {
fonts.enableDefaultFonts = true; # Background fonts
fonts.fonts = with pkgs; [
@ -20,9 +25,9 @@ import ./make-test.nix ({ lib, ... }:
};
testScript = ''
$machine->succeed("fc-match serif | grep '\"Gentium Plus\"'");
$machine->succeed("fc-match sans-serif | grep '\"Cantarell\"'");
$machine->succeed("fc-match monospace | grep '\"Source Code Pro\"'");
$machine->succeed("fc-match emoji | grep '\"Twitter Color Emoji\"'");
machine.succeed("fc-match serif | grep '\"Gentium Plus\"'")
machine.succeed("fc-match sans-serif | grep '\"Cantarell\"'")
machine.succeed("fc-match monospace | grep '\"Source Code Pro\"'")
machine.succeed("fc-match emoji | grep '\"Twitter Color Emoji\"'")
'';
})

View File

@ -1,21 +0,0 @@
# run installed tests
import ./make-test.nix ({ pkgs, ... }: {
name = "fwupd";
meta = {
maintainers = pkgs.fwupd.meta.maintainers;
};
machine = { pkgs, ... }: {
services.fwupd.enable = true;
services.fwupd.blacklistPlugins = []; # don't blacklist test plugin
services.fwupd.enableTestRemote = true;
environment.systemPackages = with pkgs; [ gnome-desktop-testing ];
environment.variables.XDG_DATA_DIRS = [ "${pkgs.fwupd.installedTests}/share" ];
virtualisation.memorySize = 768;
};
testScript = ''
$machine->succeed("gnome-desktop-testing-runner");
'';
})

View File

@ -1,21 +0,0 @@
# run installed tests
import ./make-test.nix ({ pkgs, ... }: {
name = "gdk-pixbuf";
meta = {
maintainers = pkgs.gdk-pixbuf.meta.maintainers;
};
machine = { pkgs, ... }: {
environment.systemPackages = with pkgs; [ gnome-desktop-testing ];
environment.variables.XDG_DATA_DIRS = [ "${pkgs.gdk-pixbuf.installedTests}/share" ];
# Tests allocate a lot of memory trying to exploit a CVE
# but qemu-system-i386 has a 2047M memory limit
virtualisation.memorySize = if pkgs.stdenv.isi686 then 2047 else 4096;
};
testScript = ''
$machine->succeed("gnome-desktop-testing-runner -t 1800"); # increase timeout to 1800s
'';
})

View File

@ -1,19 +0,0 @@
# run installed tests
import ./make-test.nix ({ pkgs, ... }: {
name = "gjs";
meta = {
maintainers = pkgs.gjs.meta.maintainers;
};
machine = { pkgs, ... }: {
imports = [ ./common/x11.nix ];
environment.systemPackages = with pkgs; [ gnome-desktop-testing ];
environment.variables.XDG_DATA_DIRS = [ "${pkgs.gjs.installedTests}/share" ];
};
testScript = ''
$machine->waitForX;
$machine->succeed("gnome-desktop-testing-runner");
'';
})

View File

@ -1,17 +0,0 @@
# run installed tests
import ./make-test.nix ({ pkgs, ... }:
{
name = "glib-networking";
meta = {
maintainers = pkgs.glib-networking.meta.maintainers;
};
machine = { pkgs, ... }: {
environment.systemPackages = with pkgs; [ gnome-desktop-testing ];
};
testScript = ''
$machine->succeed("gnome-desktop-testing-runner -d '${pkgs.glib-networking.installedTests}/share'");
'';
})

View File

@ -1,42 +0,0 @@
# run installed tests
import ./make-test.nix ({ pkgs, lib, ... }:
let
# gsettings tool with access to gsettings-desktop-schemas
desktop-gsettings = with pkgs; stdenv.mkDerivation {
name = "desktop-gsettings";
dontUnpack = true;
nativeBuildInputs = [ glib wrapGAppsHook ];
buildInputs = [ gsettings-desktop-schemas ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
ln -s ${glib.bin}/bin/gsettings $out/bin/desktop-gsettings
runHook postInstall
'';
};
in
{
name = "gnome-photos";
meta = {
maintainers = pkgs.gnome-photos.meta.maintainers;
};
machine = { pkgs, ... }: {
imports = [ ./common/x11.nix ];
programs.dconf.enable = true;
services.gnome3.at-spi2-core.enable = true; # needed for dogtail
environment.systemPackages = with pkgs; [ gnome-desktop-testing desktop-gsettings ];
services.dbus.packages = with pkgs; [ gnome-photos ];
};
testScript = ''
$machine->waitForX;
# dogtail needs accessibility enabled
$machine->succeed("desktop-gsettings set org.gnome.desktop.interface toolkit-accessibility true 2>&1");
$machine->succeed("gnome-desktop-testing-runner -d '${pkgs.gnome-photos.installedTests}/share' 2>&1");
'';
})

View File

@ -1,18 +0,0 @@
# run installed tests
import ./make-test.nix ({ pkgs, ... }:
{
name = "graphene";
meta = {
maintainers = pkgs.graphene.meta.maintainers;
};
machine = { pkgs, ... }: {
environment.systemPackages = with pkgs; [ gnome-desktop-testing ];
};
testScript = ''
$machine->succeed("gnome-desktop-testing-runner -d '${pkgs.graphene.installedTests}/share'");
'';
})

View File

@ -0,0 +1,5 @@
{ pkgs, makeInstalledTest, ... }:
makeInstalledTest {
tested = pkgs.colord;
}

View File

@ -0,0 +1,77 @@
# NixOS tests for gnome-desktop-testing-runner using software
# See https://wiki.gnome.org/Initiatives/GnomeGoals/InstalledTests
{ system ? builtins.currentSystem,
config ? {},
pkgs ? import ../../.. { inherit system config; }
}:
with import ../../lib/testing-python.nix { inherit system pkgs; };
with pkgs.lib;
let
callInstalledTest = pkgs.newScope { inherit makeInstalledTest; };
makeInstalledTest =
{ # Package to test. Needs to have an installedTests output
tested
# Config to inject into machine
, testConfig ? {}
# Test script snippet to inject before gnome-desktop-testing-runner begins.
# This is useful for extra setup the environment may need before the runner begins.
, preTestScript ? ""
# Does test need X11?
, withX11 ? false
# Extra flags to pass to gnome-desktop-testing-runner.
, testRunnerFlags ? ""
}:
makeTest rec {
name = tested.name;
meta = {
maintainers = tested.meta.maintainers;
};
machine = { ... }: {
imports = [
testConfig
] ++ optional withX11 ../common/x11.nix;
environment.systemPackages = with pkgs; [ gnome-desktop-testing ];
};
testScript =
optionalString withX11 ''
machine.wait_for_x()
'' +
optionalString (preTestScript != "") ''
${preTestScript}
'' +
''
machine.succeed(
"gnome-desktop-testing-runner ${testRunnerFlags} -d '${tested.installedTests}/share'"
)
'';
};
in
{
colord = callInstalledTest ./colord.nix {};
flatpak = callInstalledTest ./flatpak.nix {};
flatpak-builder = callInstalledTest ./flatpak-builder.nix {};
fwupd = callInstalledTest ./fwupd.nix {};
gdk-pixbuf = callInstalledTest ./gdk-pixbuf.nix {};
gjs = callInstalledTest ./gjs.nix {};
glib-networking = callInstalledTest ./glib-networking.nix {};
gnome-photos = callInstalledTest ./gnome-photos.nix {};
graphene = callInstalledTest ./graphene.nix {};
ostree = callInstalledTest ./ostree.nix {};
xdg-desktop-portal = callInstalledTest ./xdg-desktop-portal.nix {};
}

View File

@ -0,0 +1,14 @@
{ pkgs, makeInstalledTest, ... }:
makeInstalledTest {
tested = pkgs.flatpak-builder;
testConfig = {
services.flatpak.enable = true;
xdg.portal.enable = true;
environment.systemPackages = with pkgs; [ flatpak-builder ] ++ flatpak-builder.installedTestsDependencies;
virtualisation.diskSize = 2048;
};
testRunnerFlags = "--timeout 3600";
}

View File

@ -0,0 +1,19 @@
{ pkgs, makeInstalledTest, ... }:
makeInstalledTest {
tested = pkgs.flatpak;
withX11 = true;
testConfig = {
services.xserver.desktopManager.gnome3.enable = true; # TODO: figure out minimal environment where the tests work
# common/x11.nix enables the auto display manager (lightdm)
services.xserver.displayManager.gdm.enable = false;
services.gnome3.core-utilities.enable = false;
services.flatpak.enable = true;
environment.systemPackages = with pkgs; [ gnupg ostree python2 ];
virtualisation.memorySize = 2047;
virtualisation.diskSize = 1024;
};
testRunnerFlags = "--timeout 3600";
}

View File

@ -0,0 +1,12 @@
{ pkgs, makeInstalledTest, ... }:
makeInstalledTest {
tested = pkgs.fwupd;
testConfig = {
services.fwupd.enable = true;
services.fwupd.blacklistPlugins = []; # don't blacklist test plugin
services.fwupd.enableTestRemote = true;
virtualisation.memorySize = 768;
};
}

View File

@ -0,0 +1,13 @@
{ pkgs, makeInstalledTest, ... }:
makeInstalledTest {
tested = pkgs.gdk-pixbuf;
testConfig = {
# Tests allocate a lot of memory trying to exploit a CVE
# but qemu-system-i386 has a 2047M memory limit
virtualisation.memorySize = if pkgs.stdenv.isi686 then 2047 else 4096;
};
testRunnerFlags = "--timeout 1800";
}

View File

@ -0,0 +1,6 @@
{ pkgs, makeInstalledTest, ... }:
makeInstalledTest {
tested = pkgs.gjs;
withX11 = true;
}

View File

@ -0,0 +1,5 @@
{ pkgs, makeInstalledTest, ... }:
makeInstalledTest {
tested = pkgs.glib-networking;
}

View File

@ -0,0 +1,35 @@
{ pkgs, makeInstalledTest, ... }:
makeInstalledTest {
tested = pkgs.gnome-photos;
withX11 = true;
testConfig = {
programs.dconf.enable = true;
services.gnome3.at-spi2-core.enable = true; # needed for dogtail
environment.systemPackages = with pkgs; [
# gsettings tool with access to gsettings-desktop-schemas
(stdenv.mkDerivation {
name = "desktop-gsettings";
dontUnpack = true;
nativeBuildInputs = [ glib wrapGAppsHook ];
buildInputs = [ gsettings-desktop-schemas ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
ln -s ${glib.bin}/bin/gsettings $out/bin/desktop-gsettings
runHook postInstall
'';
})
];
services.dbus.packages = with pkgs; [ gnome-photos ];
};
preTestScript = ''
# dogtail needs accessibility enabled
machine.succeed(
"desktop-gsettings set org.gnome.desktop.interface toolkit-accessibility true 2>&1"
)
'';
}

View File

@ -0,0 +1,5 @@
{ pkgs, makeInstalledTest, ... }:
makeInstalledTest {
tested = pkgs.graphene;
}

View File

@ -0,0 +1,23 @@
{ pkgs, lib, makeInstalledTest, ... }:
makeInstalledTest {
tested = pkgs.ostree;
# TODO: Wrap/patch the tests directly in the package
testConfig = {
environment.systemPackages = with pkgs; [
(python3.withPackages (p: with p; [ pyyaml ]))
gnupg
ostree
];
# for GJS tests
environment.variables.GI_TYPELIB_PATH = lib.makeSearchPath "lib/girepository-1.0" (with pkgs; [
gtk3
pango.out
ostree
gdk-pixbuf
atk
]);
};
}

View File

@ -0,0 +1,5 @@
{ pkgs, makeInstalledTest, ... }:
makeInstalledTest {
tested = pkgs.xdg-desktop-portal;
}

View File

@ -1,21 +0,0 @@
# run installed tests
import ./make-test.nix ({ pkgs, lib, ... }: {
name = "ostree";
meta = {
maintainers = pkgs.ostree.meta.maintainers;
};
# TODO: Wrap/patch the tests directly in the package
machine = { pkgs, ... }: {
environment.systemPackages = with pkgs; [
gnome-desktop-testing ostree gnupg (python3.withPackages (p: with p; [ pyyaml ]))
];
environment.variables.GI_TYPELIB_PATH = lib.makeSearchPath "lib/girepository-1.0" (with pkgs; [ gtk3 pango.out ostree gdk-pixbuf atk ]); # for GJS tests
};
testScript = ''
$machine->succeed("gnome-desktop-testing-runner -d ${pkgs.ostree.installedTests}/share");
'';
})

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }: {
import ./make-test-python.nix ({ pkgs, ... }: {
name = "packagekit";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ peterhoeg ];
@ -13,12 +13,14 @@ import ./make-test.nix ({ pkgs, ... }: {
};
testScript = ''
startAll;
start_all()
# send a dbus message to activate the service
$machine->succeed("dbus-send --system --type=method_call --print-reply --dest=org.freedesktop.PackageKit /org/freedesktop/PackageKit org.freedesktop.DBus.Introspectable.Introspect");
machine.succeed(
"dbus-send --system --type=method_call --print-reply --dest=org.freedesktop.PackageKit /org/freedesktop/PackageKit org.freedesktop.DBus.Introspectable.Introspect"
)
# so now it should be running
$machine->succeed("systemctl is-active packagekit.service");
machine.wait_for_unit("packagekit.service")
'';
})

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }:
import ./make-test-python.nix ({ pkgs, ... }:
let
@ -30,32 +30,40 @@ in
testScript =
''
my $stick = $machine->stateDir . "/usbstick.img";
system("xz -d < ${stick} > $stick") == 0 or die;
import lzma
$machine->succeed("udisksctl info -b /dev/vda >&2");
$machine->fail("udisksctl info -b /dev/sda1");
with lzma.open(
"${stick}"
) as data, open(machine.state_dir + "/usbstick.img", "wb") as stick:
stick.write(data.read())
machine.succeed("udisksctl info -b /dev/vda >&2")
machine.fail("udisksctl info -b /dev/sda1")
# Attach a USB stick and wait for it to show up.
$machine->sendMonitorCommand("drive_add 0 id=stick,if=none,file=$stick,format=raw");
$machine->sendMonitorCommand("device_add usb-storage,id=stick,drive=stick");
$machine->waitUntilSucceeds("udisksctl info -b /dev/sda1");
$machine->succeed("udisksctl info -b /dev/sda1 | grep 'IdLabel:.*USBSTICK'");
machine.send_monitor_command(
f"drive_add 0 id=stick,if=none,file={stick.name},format=raw"
)
machine.send_monitor_command("device_add usb-storage,id=stick,drive=stick")
machine.wait_until_succeeds("udisksctl info -b /dev/sda1")
machine.succeed("udisksctl info -b /dev/sda1 | grep 'IdLabel:.*USBSTICK'")
# Mount the stick as a non-root user and do some stuff with it.
$machine->succeed("su - alice -c 'udisksctl info -b /dev/sda1'");
$machine->succeed("su - alice -c 'udisksctl mount -b /dev/sda1'");
$machine->succeed("su - alice -c 'cat /run/media/alice/USBSTICK/test.txt'") =~ /Hello World/ or die;
$machine->succeed("su - alice -c 'echo foo > /run/media/alice/USBSTICK/bar.txt'");
machine.succeed("su - alice -c 'udisksctl info -b /dev/sda1'")
machine.succeed("su - alice -c 'udisksctl mount -b /dev/sda1'")
machine.succeed(
"su - alice -c 'cat /run/media/alice/USBSTICK/test.txt' | grep -q 'Hello World'"
)
machine.succeed("su - alice -c 'echo foo > /run/media/alice/USBSTICK/bar.txt'")
# Unmounting the stick should make the mountpoint disappear.
$machine->succeed("su - alice -c 'udisksctl unmount -b /dev/sda1'");
$machine->fail("[ -d /run/media/alice/USBSTICK ]");
machine.succeed("su - alice -c 'udisksctl unmount -b /dev/sda1'")
machine.fail("[ -d /run/media/alice/USBSTICK ]")
# Remove the USB stick.
$machine->sendMonitorCommand("device_del stick");
$machine->waitUntilFails("udisksctl info -b /dev/sda1");
$machine->fail("[ -e /dev/sda ]");
machine.send_monitor_command("device_del stick")
machine.wait_until_fails("udisksctl info -b /dev/sda1")
machine.fail("[ -e /dev/sda ]")
'';
})

View File

@ -1,17 +0,0 @@
# run installed tests
import ./make-test.nix ({ pkgs, ... }:
{
name = "xdg-desktop-portal";
meta = {
maintainers = pkgs.xdg-desktop-portal.meta.maintainers;
};
machine = { pkgs, ... }: {
environment.systemPackages = with pkgs; [ gnome-desktop-testing ];
};
testScript = ''
$machine->succeed("gnome-desktop-testing-runner -d '${pkgs.xdg-desktop-portal.installedTests}/share'");
'';
})