1 /* Copyright (c) 2010-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
5 #include "core/or/or.h"
9 #include "lib/process/waitpid.h"
11 #include "test/log_test_helpers.h"
16 temp_callback(int r
, void *s
)
23 test_util_process_set_waitpid_callback(void *ignored
)
26 waitpid_callback_t
*res1
= NULL
, *res2
= NULL
;
27 setup_full_capture_of_logs(LOG_WARN
);
28 pid_t pid
= (pid_t
)42;
30 res1
= set_waitpid_callback(pid
, temp_callback
, NULL
);
33 res2
= set_waitpid_callback(pid
, temp_callback
, NULL
);
35 expect_single_log_msg(
36 "Replaced a waitpid monitor on pid 42. That should be "
40 teardown_capture_of_logs();
41 clear_waitpid_callback(res1
);
42 clear_waitpid_callback(res2
);
46 test_util_process_clear_waitpid_callback(void *ignored
)
49 waitpid_callback_t
*res
;
50 setup_capture_of_logs(LOG_WARN
);
51 pid_t pid
= (pid_t
)43;
53 clear_waitpid_callback(NULL
);
55 res
= set_waitpid_callback(pid
, temp_callback
, NULL
);
56 clear_waitpid_callback(res
);
57 expect_no_log_entry();
60 /* No. This is use-after-free. We don't _do_ that. XXXX */
61 clear_waitpid_callback(res
);
62 expect_log_msg("Couldn't remove waitpid monitor for pid 43.\n");
66 teardown_capture_of_logs();
68 #endif /* !defined(_WIN32) */
72 #define TEST(name) { (#name), test_util_process_##name, 0, NULL, NULL }
74 #define TEST(name) { (#name), NULL, TT_SKIP, NULL, NULL }
76 #endif /* !defined(COCCI) */
78 struct testcase_t util_process_tests
[] = {
79 TEST(set_waitpid_callback
),
80 TEST(clear_waitpid_callback
),