Skip to content

Commit f61b71f

Browse files
committed
test: add vm tests (wip)
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent 7b9e180 commit f61b71f

File tree

6 files changed

+197
-0
lines changed

6 files changed

+197
-0
lines changed

flake.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,9 @@
6767
echo "qmake: $(qmake --version)"
6868
'';
6969
};
70+
71+
checks.x86_64-linux = {
72+
qownnotes = pkgs.testers.runNixOSTest ./tests/vm/qownnotes.nix;
73+
};
7074
};
7175
}

justfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,15 @@ run-github-workflow args='format-check':
231231
[group('maintenance')]
232232
build-botan3-amalgamation:
233233
nix-build -E 'with import <nixpkgs> {}; callPackage ./scripts/botan3-amalgamation.nix {}'
234+
235+
# Run the VM tests
236+
[group('tests')]
237+
vm-test:
238+
nix build .#checks.x86_64-linux.qownnotes -L --no-link
239+
240+
# Run the interactive VM test
241+
[group('tests')]
242+
vm-test-interactive:
243+
nix build .#checks.x86_64-linux.qownnotes.driverInteractive
244+
echo "To interact with the test VM, run: start_all()"
245+
./result/bin/nixos-test-driver

tests/vm/common/auto.nix

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{ config, lib, ... }:
2+
3+
let
4+
cfg = config.test-support.displayManager.auto;
5+
in
6+
{
7+
8+
###### interface
9+
10+
options = {
11+
test-support.displayManager.auto = {
12+
enable = lib.mkOption {
13+
default = false;
14+
description = ''
15+
Whether to enable the fake "auto" display manager, which
16+
automatically logs in the user specified in the
17+
{option}`user` option. This is mostly useful for
18+
automated tests.
19+
'';
20+
};
21+
22+
user = lib.mkOption {
23+
default = "root";
24+
description = "The user account to login automatically.";
25+
};
26+
};
27+
};
28+
29+
###### implementation
30+
31+
config = lib.mkIf cfg.enable {
32+
services.xserver.displayManager.lightdm.enable = true;
33+
services.displayManager.autoLogin = {
34+
enable = true;
35+
inherit (cfg) user;
36+
};
37+
38+
# lightdm by default doesn't allow auto login for root, which is
39+
# required by some nixos tests. Override it here.
40+
security.pam.services.lightdm-autologin.text = lib.mkForce ''
41+
auth requisite pam_nologin.so
42+
auth required pam_succeed_if.so quiet
43+
auth required pam_permit.so
44+
45+
account include lightdm
46+
47+
password include lightdm
48+
49+
session include lightdm
50+
'';
51+
};
52+
}

tests/vm/common/user-account.nix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
_:
2+
3+
{
4+
users.users.alice = {
5+
isNormalUser = true;
6+
description = "Alice Foobar";
7+
password = "foobar";
8+
uid = 1000;
9+
};
10+
11+
users.users.bob = {
12+
isNormalUser = true;
13+
description = "Bob Foobar";
14+
password = "foobar";
15+
};
16+
}

tests/vm/common/x11.nix

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{ lib, ... }:
2+
3+
{
4+
imports = [
5+
./auto.nix
6+
];
7+
8+
services.xserver.enable = true;
9+
10+
# Automatically log in.
11+
test-support.displayManager.auto.enable = true;
12+
13+
# Use IceWM as the window manager.
14+
# Don't use a desktop manager.
15+
services.displayManager.defaultSession = lib.mkDefault "none+icewm";
16+
services.xserver.windowManager.icewm.enable = true;
17+
18+
# Help with OCR
19+
environment.etc."icewm/theme".text = ''
20+
Theme="gtk2/default.theme"
21+
'';
22+
}

tests/vm/qownnotes.nix

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{ lib, pkgs, ... }:
2+
3+
let
4+
qownnotesLocal = pkgs.qt6Packages.callPackage ../../default.nix { };
5+
in
6+
{
7+
name = "qownnotes";
8+
meta.maintainers = [ lib.maintainers.pbek ];
9+
10+
nodes.machine =
11+
{ ... }:
12+
13+
{
14+
imports = [
15+
./common/user-account.nix
16+
./common/x11.nix
17+
];
18+
19+
test-support.displayManager.auto.user = "alice";
20+
environment.systemPackages = [
21+
qownnotesLocal
22+
pkgs.xdotool
23+
];
24+
};
25+
26+
enableOCR = true;
27+
28+
# https://nixos.org/manual/nixos/stable/#ssec-machine-objects
29+
testScript =
30+
_:
31+
let
32+
aliceDo = cmd: ''machine.succeed("su - alice -c '${cmd}' >&2 &");'';
33+
in
34+
''
35+
with subtest("Ensure X starts"):
36+
start_all()
37+
machine.wait_for_x()
38+
39+
with subtest("Check QOwnNotes version on CLI"):
40+
${aliceDo "qownnotes --version"}
41+
42+
machine.wait_for_console_text("QOwnNotes ${qownnotesLocal.version}")
43+
44+
with subtest("Ensure QOwnNotes starts"):
45+
# start QOwnNotes window
46+
${aliceDo "qownnotes"}
47+
48+
machine.wait_for_text("Welcome to QOwnNotes")
49+
machine.screenshot("QOwnNotes-Welcome")
50+
51+
with subtest("Finish first-run wizard"):
52+
# The wizard should show up now
53+
machine.wait_for_text("Note folder")
54+
machine.send_key("ret")
55+
machine.wait_for_console_text("Note path '/home/alice/Notes' was now created.")
56+
machine.wait_for_text("Panel layout")
57+
machine.send_key("ret")
58+
machine.wait_for_text("Nextcloud")
59+
machine.send_key("ret")
60+
61+
# OCR can't detect "App metric" anymore, so we will wait for another text
62+
machine.wait_for_text("Open network settings")
63+
machine.send_key("ret")
64+
65+
# Doesn't work for non-root
66+
#machine.wait_for_window("QOwnNotes - ${pkgs.qownnotes.version}")
67+
68+
# OCR doesn't seem to be able any more to handle the main window
69+
#machine.wait_for_text("QOwnNotes - ${pkgs.qownnotes.version}")
70+
71+
# The main window should now show up
72+
machine.wait_for_open_port(22222)
73+
machine.wait_for_console_text("QOwnNotes server listening on port 22222")
74+
75+
machine.screenshot("QOwnNotes-DemoNote")
76+
77+
with subtest("Create a new note"):
78+
machine.send_key("ctrl-n")
79+
machine.sleep(1)
80+
machine.send_chars("This is a NixOS test!\n")
81+
machine.wait_until_succeeds("find /home/alice/Notes -type f | grep -qi 'Note 2'")
82+
83+
# OCR doesn't seem to be able any more to handle the main window
84+
#machine.wait_for_text("This is a NixOS test!")
85+
86+
# Doesn't work for non-root
87+
#machine.wait_for_window("- QOwnNotes - ${pkgs.qownnotes.version}")
88+
89+
machine.screenshot("QOwnNotes-NewNote")
90+
'';
91+
}

0 commit comments

Comments
 (0)