aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael Albinus2026-01-17 11:40:31 +0100
committerMichael Albinus2026-01-17 11:40:31 +0100
commitab77b4b60ca1837e2da5147e6604cd2020567b80 (patch)
tree2904dc0a52c8c96bc44efca75dec15b2d250a114 /test
parent6287637ccd9f66a219844231380ab9873d049c6e (diff)
downloademacs-ab77b4b60ca1837e2da5147e6604cd2020567b80.tar.gz
emacs-ab77b4b60ca1837e2da5147e6604cd2020567b80.zip
New D-Bus functions to support systemd inhibitor locks
* doc/misc/dbus.texi (Top): Add "Inhibitor Locks" submenu. Remove trailing period from chapter and section titles. (Inhibitor Locks): New node. * etc/NEWS: New D-Bus functions to support systemd inhibitor locks. Presentational fixes and improvements. * src/dbusbind.c (xd_registered_inhibitor_locks): New variable. (Fdbus_make_inhibitor_lock, Fdbus_close_inhibitor_lock) (Fdbus_registered_inhibitor_locks): New DEFUNs. (Bug#79963) (syms_of_dbusbind_for_pdumper): Initialize `xd_registered_inhibitor_locks'. (syms_of_dbusbind): Declare subroutines `Sdbus_make_inhibitor_lock', `Sdbus_close_inhibitor_lock' and `Sdbus_registered_inhibitor_locks'. Declare symbol `Qdbus_call_method'. staticpro `xd_registered_inhibitor_locks'. * test/lisp/net/dbus-tests.el (dbus--test-systemd-service) (dbus--test-systemd-path, dbus--test-systemd-manager-interface): New defconsts. (dbus-test10-inhibitor-locks): New test.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/net/dbus-tests.el93
1 files changed, 93 insertions, 0 deletions
diff --git a/test/lisp/net/dbus-tests.el b/test/lisp/net/dbus-tests.el
index e529e02ed9b..b34ce3381c7 100644
--- a/test/lisp/net/dbus-tests.el
+++ b/test/lisp/net/dbus-tests.el
@@ -48,6 +48,15 @@
48(defconst dbus--test-interface "org.gnu.Emacs.TestDBus.Interface" 48(defconst dbus--test-interface "org.gnu.Emacs.TestDBus.Interface"
49 "Test interface.") 49 "Test interface.")
50 50
51(defconst dbus--test-systemd-service "org.freedesktop.login1"
52 "Systemd service.")
53
54(defconst dbus--test-systemd-path "/org/freedesktop/login1"
55 "Systemd object path.")
56
57(defconst dbus--test-systemd-manager-interface "org.freedesktop.login1.Manager"
58 "Systemd Manager interface.")
59
51(defun dbus--test-availability (bus) 60(defun dbus--test-availability (bus)
52 "Test availability of D-Bus BUS." 61 "Test availability of D-Bus BUS."
53 (should (dbus-list-names bus)) 62 (should (dbus-list-names bus))
@@ -2295,6 +2304,90 @@ The argument EXPECTED-ARGS is a list of expected arguments for the method."
2295 ;; Cleanup. 2304 ;; Cleanup.
2296 (dbus-unregister-service :session dbus--test-service))) 2305 (dbus-unregister-service :session dbus--test-service)))
2297 2306
2307(ert-deftest dbus-test10-inhibitor-locks ()
2308 "Check `dbus-*-inhibitor-locks'."
2309 :tags '(:expensive-test)
2310 (skip-unless dbus--test-enabled-system-bus)
2311 (skip-unless (dbus-ping :system dbus--test-systemd-service 1000))
2312
2313 (let (lock1 lock2)
2314 ;; Create inhibitor lock.
2315 (setq lock1 (dbus-make-inhibitor-lock "sleep" "Test delay"))
2316 (should (natnump lock1))
2317 ;; The lock is reported by systemd.
2318 (should
2319 (member
2320 (list "sleep" "Emacs" "Test delay" "delay" (user-uid) (emacs-pid))
2321 (dbus-call-method
2322 :system dbus--test-systemd-service dbus--test-systemd-path
2323 dbus--test-systemd-manager-interface "ListInhibitors")))
2324 ;; The lock is registered internally.
2325 (should
2326 (member
2327 (list lock1 "sleep" "Test delay" nil)
2328 (dbus-registered-inhibitor-locks)))
2329 ;; There exist a file descriptor.
2330 (when (file-directory-p (format "/proc/%d/fd" (emacs-pid)))
2331 (should (file-symlink-p (format "/proc/%d/fd/%d" (emacs-pid) lock1))))
2332
2333 ;; It is not possible to modify registered inhibitor locks on Lisp level.
2334 (setcar (assoc lock1 (dbus-registered-inhibitor-locks)) 'malicious)
2335 (should (assoc lock1 (dbus-registered-inhibitor-locks)))
2336 (should-not (assoc 'malicious (dbus-registered-inhibitor-locks)))
2337
2338 ;; Creating it again returns the same inhibitor lock.
2339 (should (= lock1 (dbus-make-inhibitor-lock "sleep" "Test delay")))
2340
2341 ;; Create another inhibitor lock.
2342 (setq lock2 (dbus-make-inhibitor-lock "sleep" "Test block" 'block))
2343 (should (natnump lock2))
2344 (should-not (= lock1 lock2))
2345 ;; The lock is reported by systemd.
2346 (should
2347 (member
2348 (list "sleep" "Emacs" "Test block" "block" (user-uid) (emacs-pid))
2349 (dbus-call-method
2350 :system dbus--test-systemd-service dbus--test-systemd-path
2351 dbus--test-systemd-manager-interface "ListInhibitors")))
2352 ;; The lock is registered internally.
2353 (should
2354 (member
2355 (list lock2 "sleep" "Test block" t)
2356 (dbus-registered-inhibitor-locks)))
2357 ;; There exist a file descriptor.
2358 (when (file-directory-p (format "/proc/%d/fd" (emacs-pid)))
2359 (should (file-symlink-p (format "/proc/%d/fd/%d" (emacs-pid) lock2))))
2360
2361 ;; Close the first inhibitor lock.
2362 (should (dbus-close-inhibitor-lock lock1))
2363 ;; The internal registration has gone.
2364 (should-not
2365 (member
2366 (list lock1 "sleep" "Test delay" nil)
2367 (dbus-registered-inhibitor-locks)))
2368 ;; The file descriptor has been deleted.
2369 (when (file-directory-p (format "/proc/%d/fd" (emacs-pid)))
2370 (should-not (file-symlink-p (format "/proc/%d/fd/%d" (emacs-pid) lock1))))
2371
2372 ;; Closing it again is a noop.
2373 (should-not (dbus-close-inhibitor-lock lock1))
2374
2375 ;; Creating it again returns (another?) inhibitor lock.
2376 (setq lock1 (dbus-make-inhibitor-lock "sleep" "Test delay"))
2377 (should (natnump lock1))
2378 ;; The lock is registered internally.
2379 (should
2380 (member
2381 (list lock1 "sleep" "Test delay" nil)
2382 (dbus-registered-inhibitor-locks)))
2383 ;; There exist a file descriptor.
2384 (when (file-directory-p (format "/proc/%d/fd" (emacs-pid)))
2385 (should (file-symlink-p (format "/proc/%d/fd/%d" (emacs-pid) lock1))))
2386
2387 ;; Close the inhibitor locks.
2388 (should (dbus-close-inhibitor-lock lock1))
2389 (should (dbus-close-inhibitor-lock lock2))))
2390
2298(defun dbus-test-all (&optional interactive) 2391(defun dbus-test-all (&optional interactive)
2299 "Run all tests for \\[dbus]." 2392 "Run all tests for \\[dbus]."
2300 (interactive "p") 2393 (interactive "p")