1 /* Copyright (c) 2010-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 #define UTIL_PROCESS_PRIVATE
6 #include "core/or/or.h"
10 #include "lib/process/waitpid.h"
12 #include "test/log_test_helpers.h"
15 #define NS_MODULE util_process
18 temp_callback(int r
, void *s
)
25 test_util_process_set_waitpid_callback(void *ignored
)
28 waitpid_callback_t
*res1
= NULL
, *res2
= NULL
;
29 setup_full_capture_of_logs(LOG_WARN
);
30 pid_t pid
= (pid_t
)42;
32 res1
= set_waitpid_callback(pid
, temp_callback
, NULL
);
35 res2
= set_waitpid_callback(pid
, temp_callback
, NULL
);
37 expect_single_log_msg(
38 "Replaced a waitpid monitor on pid 42. That should be "
42 teardown_capture_of_logs();
43 clear_waitpid_callback(res1
);
44 clear_waitpid_callback(res2
);
48 test_util_process_clear_waitpid_callback(void *ignored
)
51 waitpid_callback_t
*res
;
52 setup_capture_of_logs(LOG_WARN
);
53 pid_t pid
= (pid_t
)43;
55 clear_waitpid_callback(NULL
);
57 res
= set_waitpid_callback(pid
, temp_callback
, NULL
);
58 clear_waitpid_callback(res
);
59 expect_no_log_entry();
62 /* No. This is use-after-free. We don't _do_ that. XXXX */
63 clear_waitpid_callback(res
);
64 expect_log_msg("Couldn't remove waitpid monitor for pid 43.\n");
68 teardown_capture_of_logs();
70 #endif /* !defined(_WIN32) */
73 #define TEST(name) { #name, test_util_process_##name, 0, NULL, NULL }
75 #define TEST(name) { #name, NULL, TT_SKIP, NULL, NULL }
78 struct testcase_t util_process_tests
[] = {
79 TEST(set_waitpid_callback
),
80 TEST(clear_waitpid_callback
),