From 088dd67f891553e1a27e65c97e386d0dd8dc4f64 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Thu, 12 Oct 2023 11:02:53 +0200 Subject: [PATCH] New filenotify tests * src/inotify.c (Finotify_watch_list, Finotify_allocated_p): Fix argument list. * test/lisp/filenotify-tests.el (file-notify-test04-autorevert): Use `skip-when'. (file-notify-test12-unmount, file-notify-test12-unmount-remote): New tests. --- src/inotify.c | 2 ++ test/lisp/filenotify-tests.el | 68 +++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/inotify.c b/src/inotify.c index 247d9f03055..f50b9ddcaa7 100644 --- a/src/inotify.c +++ b/src/inotify.c @@ -517,12 +517,14 @@ it invalid. */) #ifdef INOTIFY_DEBUG DEFUN ("inotify-watch-list", Finotify_watch_list, Sinotify_watch_list, 0, 0, 0, doc: /* Return a copy of the internal watch_list. */) + (void) { return Fcopy_sequence (watch_list); } DEFUN ("inotify-allocated-p", Finotify_allocated_p, Sinotify_allocated_p, 0, 0, 0, doc: /* Return non-nil, if an inotify instance is allocated. */) + (void) { return inotifyfd < 0 ? Qnil : Qt; } diff --git a/test/lisp/filenotify-tests.el b/test/lisp/filenotify-tests.el index 57099add08b..eb485a10a92 100644 --- a/test/lisp/filenotify-tests.el +++ b/test/lisp/filenotify-tests.el @@ -973,8 +973,7 @@ delivered." (setq file-notify--test-desc auto-revert-notify-watch-descriptor) ;; GKqueueFileMonitor does not report the `changed' event. - (skip-unless - (not (eq (file-notify--test-monitor) 'GKqueueFileMonitor))) + (skip-when (eq (file-notify--test-monitor) 'GKqueueFileMonitor)) ;; Check, that file notification has been used. (should auto-revert-mode) @@ -1708,6 +1707,71 @@ the file watch." (file-notify--deftest-remote file-notify-test11-symlinks "Check `file-notify-test11-symlinks' for remote files.") +(ert-deftest file-notify-test12-unmount () + "Check that file notification stop after unmounting the filesystem." + :tags '(:expensive-test) + (skip-unless (file-notify--test-local-enabled)) + ;; This test does not work for w32notify. + (skip-when (string-equal (file-notify--test-library) "w32notify")) + + (unwind-protect + (progn + (setq file-notify--test-tmpfile (file-notify--test-make-temp-name)) + ;; File monitors like kqueue insist, that the watched file + ;; exists. Directory monitors are not bound to this + ;; restriction. + (when (string-equal (file-notify--test-library) "kqueue") + (write-region + "any text" nil file-notify--test-tmpfile nil 'no-message)) + + (should + (setq file-notify--test-desc + (file-notify--test-add-watch + file-notify--test-tmpfile + '(attribute-change change) #'file-notify--test-event-handler))) + (should (file-notify-valid-p file-notify--test-desc)) + + ;; Unmounting the filesystem should stop watching. + (file-notify--test-with-actions '(stopped) + ;; We emulate unmounting by calling + ;; `file-notify-handle-event' with a corresponding event. + (file-notify-handle-event + (make-file-notify + :-event + (list file-notify--test-desc + (pcase (file-notify--test-library) + ((or "inotify" "inotifywait") '(unmount isdir)) + ((or "gfilenotify" "gio") '(unmounted)) + ("kqueue" '(revoke)) + (err (ert-fail (format "Library %s not supported" err)))) + (pcase (file-notify--test-library) + ("kqueue" (file-local-name file-notify--test-tmpfile)) + (_ (file-local-name file-notify--test-tmpdir))) + ;; In the inotify case, there is a 4th slot `cookie'. + ;; Since it is unused for `unmount', we ignore it. + ) + :-callback + (pcase (file-notify--test-library) + ("inotify" #'file-notify--callback-inotify) + ("gfilenotify" #'file-notify--callback-gfilenotify) + ("kqueue" #'file-notify--callback-kqueue) + ((or "inotifywait" "gio") #'file-notify-callback) + (err (ert-fail (format "Library %s not supported" err))))))) + + ;; The watch has been stopped. + (should-not (file-notify-valid-p file-notify--test-desc)) + + ;; The environment shall be cleaned up. + (when (string-equal (file-notify--test-library) "kqueue") + (delete-file file-notify--test-tmpfile)) + (file-notify--test-cleanup-p)) + + ;; Cleanup. + (file-notify--test-cleanup))) + +(file-notify--deftest-remote file-notify-test12-unmount + "Check `file-notify-test12-unmount' for remote files.") + (defun file-notify-test-all (&optional interactive) "Run all tests for \\[file-notify]." (interactive "p") -- 2.39.2