Edit changelog a little for clarity and conciseness
[tor.git] / src / test / test_util_process.c
blob45c22ef47fc0060bb688e90ff70f89e825f83963
1 /* Copyright (c) 2010-2016, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 #define UTIL_PROCESS_PRIVATE
5 #include "orconfig.h"
6 #include "or.h"
8 #include "test.h"
10 #include "util_process.h"
12 #include "log_test_helpers.h"
14 #ifndef _WIN32
15 #define NS_MODULE util_process
17 static void
18 temp_callback(int r, void *s)
20 (void)r;
21 (void)s;
24 static void
25 test_util_process_set_waitpid_callback(void *ignored)
27 (void)ignored;
28 waitpid_callback_t *res1 = NULL, *res2 = NULL;
29 int previous_log = setup_capture_of_logs(LOG_WARN);
30 pid_t pid = (pid_t)42;
32 res1 = set_waitpid_callback(pid, temp_callback, NULL);
33 tt_assert(res1);
35 res2 = set_waitpid_callback(pid, temp_callback, NULL);
36 tt_assert(res2);
37 expect_log_msg("Replaced a waitpid monitor on pid 42. That should be "
38 "impossible.\n");
40 done:
41 teardown_capture_of_logs(previous_log);
42 clear_waitpid_callback(res1);
43 clear_waitpid_callback(res2);
46 static void
47 test_util_process_clear_waitpid_callback(void *ignored)
49 (void)ignored;
50 waitpid_callback_t *res;
51 int previous_log = setup_capture_of_logs(LOG_WARN);
52 pid_t pid = (pid_t)43;
54 clear_waitpid_callback(NULL);
56 res = set_waitpid_callback(pid, temp_callback, NULL);
57 clear_waitpid_callback(res);
58 expect_no_log_entry();
60 #if 0
61 /* No. This is use-after-free. We don't _do_ that. XXXX */
62 clear_waitpid_callback(res);
63 expect_log_msg("Couldn't remove waitpid monitor for pid 43.\n");
64 #endif
66 done:
67 teardown_capture_of_logs(previous_log);
69 #endif /* _WIN32 */
71 #ifndef _WIN32
72 #define TEST(name) { #name, test_util_process_##name, 0, NULL, NULL }
73 #else
74 #define TEST(name) { #name, NULL, TT_SKIP, NULL, NULL }
75 #endif
77 struct testcase_t util_process_tests[] = {
78 TEST(set_waitpid_callback),
79 TEST(clear_waitpid_callback),
80 END_OF_TESTCASES