diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-10-21 16:45:49 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-10-21 16:45:49 -0400 |
commit | a61158aa237429d046f34d9f3db5a7dc7c40ba5e (patch) | |
tree | cecc3777bec3ded26974077eca05e87fac18f5fb | |
parent | 5e9f2384cf0f97646d7ee1b9eccaab4dfe382536 (diff) | |
parent | c31791b79886dd697f02af78b86281ad6d5e407d (diff) | |
download | tor-a61158aa237429d046f34d9f3db5a7dc7c40ba5e.tar.gz tor-a61158aa237429d046f34d9f3db5a7dc7c40ba5e.zip |
Merge remote-tracking branch 'twstrike/util_process_tests'
-rw-r--r-- | src/test/include.am | 1 | ||||
-rw-r--r-- | src/test/test.c | 3 | ||||
-rw-r--r-- | src/test/test_util_process.c | 72 |
3 files changed, 75 insertions, 1 deletions
diff --git a/src/test/include.am b/src/test/include.am index 5b3c045de1..d0a819fb7f 100644 --- a/src/test/include.am +++ b/src/test/include.am @@ -102,6 +102,7 @@ src_test_test_SOURCES = \ src/test/test_tortls.c \ src/test/test_util.c \ src/test/test_util_format.c \ + src/test/test_util_process.c \ src/test/test_helpers.c \ src/test/test_dns.c \ src/test/testing_common.c \ diff --git a/src/test/test.c b/src/test/test.c index 3468f7fdaa..1c421d98ab 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -1168,6 +1168,7 @@ extern struct testcase_t thread_tests[]; extern struct testcase_t tortls_tests[]; extern struct testcase_t util_tests[]; extern struct testcase_t util_format_tests[]; +extern struct testcase_t util_process_tests[]; extern struct testcase_t dns_tests[]; struct testgroup_t testgroups[] = { @@ -1220,8 +1221,8 @@ struct testgroup_t testgroups[] = { { "util/", util_tests }, { "util/format/", util_format_tests }, { "util/logging/", logging_tests }, + { "util/process/", util_process_tests }, { "util/thread/", thread_tests }, { "dns/", dns_tests }, END_OF_GROUPS }; - diff --git a/src/test/test_util_process.c b/src/test/test_util_process.c new file mode 100644 index 0000000000..5d45b58d3e --- /dev/null +++ b/src/test/test_util_process.c @@ -0,0 +1,72 @@ +/* Copyright (c) 2010-2015, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#define UTIL_PROCESS_PRIVATE +#include "orconfig.h" +#include "or.h" + +#include "test.h" + +#include "util_process.h" + +#include "log_test_helpers.h" + +#define NS_MODULE util_process + +static void +temp_callback(int r, void *s) +{ + (void)r; + (void)s; +} + +static void +test_util_process_set_waitpid_callback(void *ignored) +{ + (void)ignored; + waitpid_callback_t *res; + int previous_log = setup_capture_of_logs(LOG_WARN); + pid_t pid = (pid_t)42; + + res = set_waitpid_callback(pid, temp_callback, NULL); + tt_assert(res); + + res = set_waitpid_callback(pid, temp_callback, NULL); + tt_assert(res); + tt_str_op(mock_saved_log_at(0), OP_EQ, + "Replaced a waitpid monitor on pid 42. That should be " + "impossible.\n"); + + done: + teardown_capture_of_logs(previous_log); +} + +static void +test_util_process_clear_waitpid_callback(void *ignored) +{ + (void)ignored; + waitpid_callback_t *res; + int previous_log = setup_capture_of_logs(LOG_WARN); + pid_t pid = (pid_t)43; + + clear_waitpid_callback(NULL); + + res = set_waitpid_callback(pid, temp_callback, NULL); + clear_waitpid_callback(res); + tt_int_op(mock_saved_log_number(), OP_EQ, 0); + + clear_waitpid_callback(res); + tt_str_op(mock_saved_log_at(0), OP_EQ, + "Couldn't remove waitpid monitor for pid 43.\n"); + + done: + teardown_capture_of_logs(previous_log); +} + +struct testcase_t util_process_tests[] = { + { "set_waitpid_callback", test_util_process_set_waitpid_callback, 0, + NULL, NULL }, + { "clear_waitpid_callback", test_util_process_clear_waitpid_callback, 0, + NULL, NULL }, + END_OF_TESTCASES +}; |