Skip to content

Commit 248a796

Browse files
add configurations replace the lock tester with waitForLock
I didn't really see the benfit in a wrapper executable to test hyprlock. But I needed a way to wait until the session is locked, so I added this waitForLock programm.
1 parent 735b2e1 commit 248a796

File tree

18 files changed

+419
-390
lines changed

18 files changed

+419
-390
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ if(TESTS)
174174
add_test(
175175
NAME "Main Test"
176176
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests
177-
COMMAND lock_tester)
177+
COMMAND wait-for-lock)
178178

179-
add_dependencies(tests lock_tester)
179+
add_dependencies(tests wait-for-lock)
180180
endif()

flake.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@
5656
packages = eachSystem (system: {
5757
default = self.packages.${system}.hyprlock;
5858
inherit (pkgsFor.${system}) hyprlock;
59-
inherit (pkgsDebugFor.${system}) hyprlock-debug;
60-
inherit (pkgsFor.${system}) lock_tester;
59+
inherit (pkgsDebugFor.${system}) hyprlock-debug hyprlock-test-meta;
6160
});
6261

6362
homeManagerModules = {

nix/overlays.nix

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ in {
1919
inputs.hyprutils.overlays.default
2020
inputs.hyprwayland-scanner.overlays.default
2121
inputs.self.overlays.sdbuscpp
22-
inputs.self.overlays.lock_tester
2322
(final: prev: {
2423
hyprlock = prev.callPackage ./default.nix {
2524
stdenv = prev.gcc15Stdenv;
@@ -36,18 +35,15 @@ in {
3635
(final: prev: {
3736
hyprutils = prev.hyprutils.override {debug = true;};
3837
hyprlock-debug = prev.hyprlock.override {debug = true;};
38+
hyprlock-test-meta = prev.callPackage ./test-meta.nix {
39+
stdenv = prev.gcc14Stdenv;
40+
version = version + "+date=" + (mkDate (inputs.self.lastModifiedDate or "19700101")) + "_" + (inputs.self.shortRev or "dirty");
41+
hyprland-protocols = final.hyprland-protocols;
42+
wayland-scanner = final.wayland-scanner;
43+
};
3944
})
4045
];
4146

42-
lock_tester = final: prev: {
43-
lock_tester = prev.callPackage ./tester.nix {
44-
stdenv = prev.gcc14Stdenv;
45-
version = version + "+date=" + (mkDate (inputs.self.lastModifiedDate or "19700101")) + "_" + (inputs.self.shortRev or "dirty");
46-
hyprland-protocols = final.hyprland-protocols;
47-
wayland-scanner = final.wayland-scanner;
48-
};
49-
};
50-
5147
sdbuscpp = final: prev: {
5248
sdbus-cpp = prev.sdbus-cpp.overrideAttrs (self: super: {
5349
version = "2.0.0";

nix/tester.nix renamed to nix/test-meta.nix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
customStdenv = foldl' (acc: adapter: adapter acc) stdenv adapters;
2424
in
2525
customStdenv.mkDerivation (finalAttrs: {
26-
pname = "lock_tester";
26+
pname = "hyprlock-test-meta";
2727
inherit version;
2828

29-
#src = ../tests;
3029
src = cleanSourceWith {
3130
filter = name: _type: let
3231
baseName = baseNameOf (toString name);
@@ -55,6 +54,6 @@ in
5554
description = "Hyprlock testing utility";
5655
license = lib.licenses.bsd3;
5756
platforms = hyprlock.meta.platforms;
58-
mainProgram = "lock_tester";
57+
mainProgram = "wait-for-lock";
5958
};
6059
})

nix/tests/default.nix

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
inputs: pkgs: let
2+
inherit (pkgs) lib;
3+
inherit (lib.lists) flatten;
24
flake = inputs.self.packages.${pkgs.stdenv.hostPlatform.system};
35

46
env = {
@@ -9,19 +11,22 @@ inputs: pkgs: let
911
"XDG_CACHE_HOME" = "/tmp";
1012
};
1113

12-
envAddToSystemdRun = pkgs.lib.concatStringsSep " " (
13-
pkgs.lib.mapAttrsToList (k: v: "--setenv ${k}=${v} ") env
14+
envAddToSystemdRun = lib.concatStringsSep " " (
15+
lib.mapAttrsToList (k: v: "--setenv ${k}=${v} ") env
1416
);
17+
18+
APITRACE_RECORD = false;
19+
APITRACE_RECORD_PY = if APITRACE_RECORD then "True" else "False";
1520
in {
1621
tests = pkgs.testers.runNixOSTest {
1722
name = "hyprlock-tests";
1823

1924
nodes.machine = {pkgs, ...}: {
20-
environment.systemPackages = with pkgs; [
25+
environment.systemPackages = with pkgs; flatten [
2126
# Programs needed for tests
2227
coreutils # date command
2328
procps # pidof
24-
libinput
29+
(lib.optional APITRACE_RECORD apitrace)
2530
];
2631

2732
# Enabled by default for some reason
@@ -36,19 +41,21 @@ in {
3641

3742
programs.hyprlock = {
3843
enable = true;
39-
package = flake.hyprlock-debug;
44+
package = flake.hyprlock;
4045
};
4146

4247
networking.dhcpcd.enable = false;
4348

4449
# Disable portals
45-
xdg.portal.enable = pkgs.lib.mkForce false;
50+
xdg.portal.enable = lib.mkForce false;
4651

4752
# Autologin root into tty
4853
services.getty.autologinUser = "alice";
4954

5055
system.stateVersion = "24.11";
5156

57+
environment.etc."hyprlock/assets".source = "${flake.hyprlock-test-meta}/share/hypr/assets/";
58+
5259
users.users.alice = {
5360
isNormalUser = true;
5461
# password: abcdefghijklmnopqrstuvwxyz1234567890-=!@#$%^&*()_+[]{};\':\\"]\\|,./<>?`~äöüćńóśź
@@ -73,25 +80,36 @@ in {
7380
from pathlib import Path
7481
# Wait for tty to be up
7582
machine.wait_for_unit("multi-user.target")
76-
# Run hyprtester testing framework/suite
83+
# Startup Hyprland as the test compositor for hyprlock
7784
print("Running Hyprland")
78-
_, __ = machine.execute("systemd-run -q -u hyprland --uid $(id -u alice) -p RuntimeMaxSec=60 ${envAddToSystemdRun} ${pkgs.hyprland}/bin/Hyprland -c ${flake.lock_tester}/share/hypr/hyprland.conf", timeout=60)
79-
85+
_, __ = machine.execute("systemd-run -q -u hyprland --uid $(id -u alice) -p RuntimeMaxSec=60 ${envAddToSystemdRun} --setenv PATH=$PATH ${pkgs.hyprland}/bin/Hyprland -c ${flake.hyprlock-test-meta}/share/hypr/hyprland.conf")
8086
_, __ = machine.execute("sleep 2")
81-
_, out = machine.execute("hyprctl --instance 0 systeminfo")
82-
print(out)
83-
for hyprlock_config in Path("${flake.lock_tester}/share/hypr/configs/").iterdir():
87+
_, systeminfo = machine.execute("hyprctl --instance 0 systeminfo")
88+
print(systeminfo)
89+
90+
for hyprlock_config in Path("${flake.hyprlock-test-meta}/share/hypr/configs/").iterdir():
8491
print(f"Testing configuration file {hyprlock_config}")
85-
log_file_path = "/tmp/lock_tester_" + hyprlock_config.stem
86-
print(log_file_path)
87-
cmd = f"${pkgs.lib.getExe flake.lock_tester} --binary ${pkgs.lib.getExe flake.hyprlock-debug} --config {str(hyprlock_config)} 2>&1 >>{log_file_path}; echo $? > /tmp/exit_code"
88-
_, out = machine.execute(f"hyprctl --instance 0 dispatch exec '{cmd}'")
89-
print(out)
90-
machine.wait_for_file("/tmp/.session-locked", timeout=30)
91-
_, tester_pid = machine.execute("pidof lock_tester")
92-
print(f"Lock tester pid {tester_pid}")
93-
machine.send_chars("asdf\n") # wrong password
94-
_, __ = machine.execute("sleep 3")
92+
log_file_path = "/tmp/hyprlock_test_" + hyprlock_config.stem
93+
94+
hyprlock_cmd = f"hyprlock --config {str(hyprlock_config)} -v 2>&1 >{log_file_path}; echo $? > /tmp/exit_status"
95+
if ${APITRACE_RECORD_PY}:
96+
hyprlock_cmd = f"${lib.getExe pkgs.apitrace} trace --output {log_file_path}.trace --api egl {hyprlock_cmd}"
97+
_, __ = machine.execute(f"hyprctl --instance 0 dispatch exec '{hyprlock_cmd}'")
98+
99+
wait_for_lock_exit_status, out = machine.execute("WAYLAND_DISPLAY=wayland-1 ${flake.hyprlock-test-meta}/bin/wait-for-lock")
100+
print(f"Wait for lock exit code: {wait_for_lock_exit_status}")
101+
if wait_for_lock_exit_status != 0:
102+
break
103+
104+
_, hyprlock_pid = machine.execute("pidof hyprlock")
105+
print(f"Hyprlock pid {hyprlock_pid}")
106+
107+
# wrong password
108+
machine.send_chars("asdf\n")
109+
110+
_, __ = machine.execute("sleep 3") # default fail_timeout is 2 seconds
111+
112+
# correct password
95113
machine.send_chars("abcdefghijklmnopqrstuvwxyz1234567890-=!@#$%^&*()_+[]{};':\"]\\|,./<>?`~")
96114
machine.send_key("alt_r-a")
97115
machine.send_key("alt_r-o")
@@ -107,24 +125,34 @@ in {
107125
machine.send_key("alt_r-apostrophe")
108126
machine.send_key("z")
109127
machine.send_chars("\n")
110-
_, __ = machine.execute(f"waitpid {tester_pid}")
111-
_, exit_status = machine.execute("cat /tmp/exit_code")
112-
print(f"Lock tester exited with {exit_status}")
128+
129+
_, __ = machine.execute(f"waitpid {hyprlock_pid}")
130+
_, exit_status = machine.execute("cat /tmp/exit_status")
131+
print(f"Hyprlock exited with {exit_status}")
132+
113133
machine.copy_from_vm(log_file_path)
134+
if ${APITRACE_RECORD_PY}:
135+
machine.copy_from_vm(log_file_path + ".trace")
136+
137+
_, out = machine.execute(f"cat {log_file_path}")
138+
print(f"Hyprlock log:\n{out}")
114139
_, out = machine.execute(f"cat {log_file_path}")
115-
print(f"Lock tester log:\n{out}")
116140
117-
#machine.wait_for_file("/tmp/exit_status", timeout=30)
118-
machine.wait_for_unit("hyprland", timeout=30)
141+
if not exit_status or int(exit_status) != 0:
142+
break
143+
144+
145+
_, out = machine.execute("hyprctl --instance 0 dispatch exit")
146+
machine.wait_for_unit("hyprland", timeout=10)
119147
120-
# Copy logs to host
121-
#machine.execute('cp "$(find /tmp/hypr -name *.log | head -1)" /tmp/hyprlog')
122-
#machine.copy_from_vm("/tmp/hyprlog")
123-
#machine.copy_from_vm("/tmp/exit_status")
148+
_, exit_status = machine.execute("cat /tmp/exit_status")
149+
# For the github runner, just to make sure wen don't accidentally succeed
150+
if not exit_status.strip():
151+
_, __ = machine.execute("echo 99 >/tmp/exit_status")
152+
exit_status = "99"
124153
125-
# Print logs for visibility in CI
126-
#_, out = machine.execute("cat /tmp/hyprlog")
127-
#print(f"Hyprland logs:\n{out}")
154+
machine.copy_from_vm("/tmp/exit_status")
155+
assert int(exit_status) == 0, f"hyprlock exit code != 0 (exited with {exit_status})"
128156
129157
# Finally - shutdown
130158
machine.shutdown()

src/renderer/AsyncResourceManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "../helpers/Log.hpp"
55
#include "../helpers/MiscFunctions.hpp"
66
#include "../core/hyprlock.hpp"
7+
#include "../core/Egl.hpp"
78
#include "../config/ConfigManager.hpp"
89

910
#include <algorithm>

tests/CMakeLists.txt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.27)
22

3-
project(lock_tester DESCRIPTION "Hyprlock test suite")
3+
project(wait-for-lock DESCRIPTION "Hyprlock test suite")
44

55
include(GNUInstallDirs)
66

@@ -9,18 +9,16 @@ set(CMAKE_CXX_STANDARD 23)
99
find_package(PkgConfig REQUIRED)
1010
find_package(hyprwayland-scanner 0.4.4 REQUIRED)
1111

12-
pkg_check_modules(lock_tester_deps REQUIRED IMPORTED_TARGET
12+
pkg_check_modules(wfldeps REQUIRED IMPORTED_TARGET
1313
hyprland-protocols>=0.6.0
1414
hyprutils>=0.5.0
1515
wayland-client
1616
wayland-protocols>=1.35
1717
)
1818

19-
file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp")
19+
add_executable(wait-for-lock "waitForLock.cpp")
2020

21-
add_executable(lock_tester ${SRCFILES})
22-
23-
target_link_libraries(lock_tester PRIVATE PkgConfig::lock_tester_deps)
21+
target_link_libraries(wait-for-lock PRIVATE PkgConfig::wfldeps)
2422

2523
# protocols
2624
pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir)
@@ -29,28 +27,31 @@ pkg_get_variable(HYPRLAND_PROTOCOLS hyprland-protocols pkgdatadir)
2927
message(STATUS "Found hyprland-protocols at ${HYPRLAND_PROTOCOLS}")
3028

3129
make_directory(${CMAKE_SOURCE_DIR}/protocols)
32-
target_include_directories(lock_tester PRIVATE ${CMAKE_SOURCE_DIR}/protocols)
30+
target_include_directories(wait-for-lock PRIVATE ${CMAKE_SOURCE_DIR}/protocols)
3331

3432
# wayland client
3533
add_custom_command(
3634
OUTPUT ${CMAKE_SOURCE_DIR}/protocols/wayland.cpp
3735
${CMAKE_SOURCE_DIR}/protocols/wayland.hpp
3836
COMMAND hyprwayland-scanner --wayland-enums --client
3937
${WAYLAND_SCANNER_PKGDATA_DIR}/wayland.xml ${CMAKE_SOURCE_DIR}/protocols/)
40-
target_sources(lock_tester PRIVATE ${CMAKE_SOURCE_DIR}/protocols/wayland.cpp)
38+
target_sources(wait-for-lock PRIVATE ${CMAKE_SOURCE_DIR}/protocols/wayland.cpp)
4139

4240
# hyprland-lock-notify-v1
4341
add_custom_command(
4442
OUTPUT ${CMAKE_SOURCE_DIR}/protocols/hyprland-lock-notify-v1.cpp
4543
${CMAKE_SOURCE_DIR}/protocols/hyprland-lock-notify-v1.hpp
4644
COMMAND hyprwayland-scanner --client ${HYPRLAND_PROTOCOLS}/protocols/hyprland-lock-notify-v1.xml
4745
${CMAKE_SOURCE_DIR}/protocols/)
48-
target_sources(lock_tester PRIVATE ${CMAKE_SOURCE_DIR}/protocols/hyprland-lock-notify-v1.cpp)
46+
target_sources(wait-for-lock PRIVATE ${CMAKE_SOURCE_DIR}/protocols/hyprland-lock-notify-v1.cpp)
4947

50-
install(TARGETS lock_tester)
48+
install(TARGETS wait-for-lock)
5149

5250
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/hyprland.conf
5351
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/hypr)
5452

5553
file(GLOB_RECURSE TESTCONFIGS CONFIGURE_DEPENDS "configs/*.conf")
5654
install(FILES ${TESTCONFIGS} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/hypr/configs)
55+
56+
file(GLOB_RECURSE TESTCONFIGS CONFIGURE_DEPENDS "assets/*.png")
57+
install(FILES ${TESTCONFIGS} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/hypr/assets)

tests/assets/avatar.png

10.4 KB
Loading

tests/assets/background.png

202 KB
Loading
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ $font = Monospace
1313

1414
general {
1515
hide_cursor = false
16-
# bo doesn't work with qemu graphics
17-
screencopy_mode = 1
1816
}
1917

2018
# uncomment to enable fingerprint authentication

0 commit comments

Comments
 (0)