Bump copyright date to 2019
[tor.git] / src / test / test_util_process.c
blob4d04eb6dfc71024dd225ac223218c9463b2b776e
1 /* Copyright (c) 2010-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 #define UTIL_PROCESS_PRIVATE
5 #include "orconfig.h"
6 #include "core/or/or.h"
8 #include "test/test.h"
10 #include "lib/process/waitpid.h"
12 #include "test/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 setup_full_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_single_log_msg(
38 "Replaced a waitpid monitor on pid 42. That should be "
39 "impossible.\n");
41 done:
42 teardown_capture_of_logs();
43 clear_waitpid_callback(res1);
44 clear_waitpid_callback(res2);
47 static void
48 test_util_process_clear_waitpid_callback(void *ignored)
50 (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();
61 #if 0
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");
65 #endif
67 done:
68 teardown_capture_of_logs();
70 #endif /* !defined(_WIN32) */
72 #ifndef _WIN32
73 #define TEST(name) { #name, test_util_process_##name, 0, NULL, NULL }
74 #else
75 #define TEST(name) { #name, NULL, TT_SKIP, NULL, NULL }
76 #endif
78 struct testcase_t util_process_tests[] = {
79 TEST(set_waitpid_callback),
80 TEST(clear_waitpid_callback),
81 END_OF_TESTCASES