summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-event
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-06-28 00:03:51 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-06-28 00:05:14 +0900
commitc7b5a5a7360984df4524ffac5e443e12814448d5 (patch)
tree3d3c8d20c0651fc81504ecbf7ff28fece24ae5af /src/libsystemd/sd-event
parent067fc917026fd1fe601de0198c5ea7b3ba782d1e (diff)
downloadsystemd-c7b5a5a7360984df4524ffac5e443e12814448d5.tar.gz
test: add another test for inotify event source
The test case is for issue #23826.
Diffstat (limited to 'src/libsystemd/sd-event')
-rw-r--r--src/libsystemd/sd-event/test-event.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/libsystemd/sd-event/test-event.c b/src/libsystemd/sd-event/test-event.c
index ea29def3d5..cc3b84cf46 100644
--- a/src/libsystemd/sd-event/test-event.c
+++ b/src/libsystemd/sd-event/test-event.c
@@ -757,4 +757,56 @@ TEST(inotify_self_destroy) {
assert_se(sd_event_loop(e) >= 0);
}
+struct inotify_process_buffered_data_context {
+ const char *path[2];
+ unsigned i;
+};
+
+static int inotify_process_buffered_data_handler(sd_event_source *s, const struct inotify_event *ev, void *userdata) {
+ struct inotify_process_buffered_data_context *c = ASSERT_PTR(userdata);
+ const char *description;
+
+ assert_se(sd_event_source_get_description(s, &description) >= 0);
+
+ assert_se(c->i < 2);
+ assert_se(streq(c->path[c->i], description));
+ c->i++;
+
+ return 1;
+}
+
+TEST(inotify_process_buffered_data) {
+ _cleanup_(rm_rf_physical_and_freep) char *p = NULL, *q = NULL;
+ _cleanup_(sd_event_source_unrefp) sd_event_source *a = NULL, *b = NULL;
+ _cleanup_(sd_event_unrefp) sd_event *e = NULL;
+ _cleanup_free_ char *z = NULL;
+
+ /* For issue #23826 */
+
+ assert_se(sd_event_default(&e) >= 0);
+
+ assert_se(mkdtemp_malloc("/tmp/test-inotify-XXXXXX", &p) >= 0);
+ assert_se(mkdtemp_malloc("/tmp/test-inotify-XXXXXX", &q) >= 0);
+
+ struct inotify_process_buffered_data_context context = {
+ .path = { p, q },
+ };
+
+ assert_se(sd_event_add_inotify(e, &a, p, IN_CREATE, inotify_process_buffered_data_handler, &context) >= 0);
+ assert_se(sd_event_add_inotify(e, &b, q, IN_CREATE, inotify_process_buffered_data_handler, &context) >= 0);
+
+ assert_se(z = path_join(p, "aaa"));
+ assert_se(touch(z) >= 0);
+ z = mfree(z);
+ assert_se(z = path_join(q, "bbb"));
+ assert_se(touch(z) >= 0);
+ z = mfree(z);
+
+ assert_se(sd_event_run(e, 10 * USEC_PER_SEC) > 0);
+ assert_se(sd_event_prepare(e) > 0); /* issue #23826: this was 0. */
+ assert_se(sd_event_dispatch(e) > 0);
+ assert_se(sd_event_prepare(e) == 0);
+ assert_se(sd_event_wait(e, 0) == 0);
+}
+
DEFINE_TEST_MAIN(LOG_DEBUG);