8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek Copyright (C) 2016 Red Hat
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek This program is free software; you can redistribute it and/or modify
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek it under the terms of the GNU General Public License as published by
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek (at your option) any later version.
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek This program is distributed in the hope that it will be useful,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek GNU General Public License for more details.
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek You should have received a copy of the GNU General Public License
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek /* if the cb receives flags not in this set, test fails */
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozekstatic void test_timeout(struct tevent_context *ev,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "The test timed out!\n");
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozekstatic struct inotify_test_ctx *common_setup(TALLOC_CTX *mem_ctx)
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek ctx = talloc_zero(mem_ctx, struct inotify_test_ctx);
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek ctx->fail_te = tevent_add_timer(ctx->tctx->ev, ctx,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Unable to queue fallback timer!\n");
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek ctx->filename = talloc_strdup(ctx, "test_inotify.XXXXXX");
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek ctx->dirname = talloc_strdup(ctx, "test_inotify_dir.XXXXXX");
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek ctx->filename = talloc_asprintf(ctx, "%s/testfile", ctx->dirname);
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek struct inotify_test_ctx *ctx = talloc_get_type_abort(*state,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozekstatic int inotify_test_dir_teardown(void **state)
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek struct inotify_test_ctx *ctx = talloc_get_type_abort(*state,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozekstatic void file_mod_op(struct tevent_context *ev,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek struct inotify_test_ctx *test_ctx = talloc_get_type_abort(ptr,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozekstatic void check_and_set_threshold(struct inotify_test_ctx *test_ctx,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek if (test_ctx->exp_flags != 0 && !(test_ctx->exp_flags & flags)) {
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozekstatic int inotify_set_threshold_cb(const char *filename,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek struct inotify_test_ctx *test_ctx = talloc_get_type_abort(pvt,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozekstatic int inotify_threshold_cb(const char *filename,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek struct inotify_test_ctx *test_ctx = talloc_get_type_abort(pvt,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek/* Test that running two modifications fires the callback twice */
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek struct inotify_test_ctx *test_ctx = talloc_get_type_abort(*state,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek ctx = snotify_create(test_ctx, test_ctx->tctx->ev, SNOTIFY_WATCH_DIR,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek te = tevent_add_timer(test_ctx->tctx->ev, test_ctx,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Unable to queue file update!\n");
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek te = tevent_add_timer(test_ctx->tctx->ev, test_ctx,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Unable to queue file update!\n");
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozekstatic void file_mv_op(struct tevent_context *ev,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek struct inotify_test_ctx *test_ctx = talloc_get_type_abort(ptr,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek char src_tmp_file[] = "test_inotify_src.XXXXXX";
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek ret = rename(src_tmp_file, test_ctx->filename);
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek struct inotify_test_ctx *test_ctx = talloc_get_type_abort(*state,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek ctx = snotify_create(test_ctx, test_ctx->tctx->ev, SNOTIFY_WATCH_DIR,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek te = tevent_add_timer(test_ctx->tctx->ev, test_ctx,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Unable to queue file update!\n");
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozekstatic void file_del_add_op(struct tevent_context *ev,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek struct inotify_test_ctx *test_ctx = talloc_get_type_abort(ptr,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek struct inotify_test_ctx *test_ctx = talloc_get_type_abort(*state,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek ctx = snotify_create(test_ctx, test_ctx->tctx->ev, SNOTIFY_WATCH_DIR,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek te = tevent_add_timer(test_ctx->tctx->ev, test_ctx,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Unable to queue file update!\n");
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozekstatic void test_inotify_file_moved_in(void **state)
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek struct inotify_test_ctx *test_ctx = talloc_get_type_abort(*state,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek ctx = snotify_create(test_ctx, test_ctx->tctx->ev, SNOTIFY_WATCH_DIR,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek te = tevent_add_timer(test_ctx->tctx->ev, test_ctx,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Unable to queue file update!\n");
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozekstatic void file_del_op(struct tevent_context *ev,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek struct inotify_test_ctx *test_ctx = talloc_get_type_abort(ptr,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozekstatic void check_threshold_cb(struct tevent_context *ev,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek struct inotify_test_ctx *test_ctx = talloc_get_type_abort(ptr,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek /* tests that no more callbacks were issued and exactly one
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek * was caught for both requests
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek struct inotify_test_ctx *test_ctx = talloc_get_type_abort(*state,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek struct timeval delay = { .tv_sec = 1, .tv_usec = 0 };
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek ctx = snotify_create(test_ctx, test_ctx->tctx->ev, SNOTIFY_WATCH_DIR,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek te = tevent_add_timer(test_ctx->tctx->ev, test_ctx,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Unable to queue file update!\n");
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek te = tevent_add_timer(test_ctx->tctx->ev, test_ctx,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Unable to queue file update!\n");
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek te = tevent_add_timer(test_ctx->tctx->ev, test_ctx,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Unable to queue file update!\n");
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek cmocka_unit_test_setup_teardown(test_inotify_mv,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek cmocka_unit_test_setup_teardown(test_inotify_mod,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek cmocka_unit_test_setup_teardown(test_inotify_del_add,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek cmocka_unit_test_setup_teardown(test_inotify_file_moved_in,
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek cmocka_unit_test_setup_teardown(test_inotify_delay,
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
8cfb42e1985550e99585d311f68087d414932806Jakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);