diff options
author | Ola Bini <ola@olabini.se> | 2015-09-15 17:37:25 +0200 |
---|---|---|
committer | Ola Bini <ola@olabini.se> | 2015-09-15 17:37:25 +0200 |
commit | cf4f50f94332615abcf6dd345ee1e8fce69232ca (patch) | |
tree | 5c556228f1d4605aff25af1909bad3e4e1b6fb99 /src/test/test_util_process.c | |
parent | a444b11323799536b4cd7902e29f711b0806293a (diff) | |
download | tor-cf4f50f94332615abcf6dd345ee1e8fce69232ca.tar.gz tor-cf4f50f94332615abcf6dd345ee1e8fce69232ca.zip |
Add tests for util_process
Diffstat (limited to 'src/test/test_util_process.c')
-rw-r--r-- | src/test/test_util_process.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/test/test_util_process.c b/src/test/test_util_process.c new file mode 100644 index 0000000000..5d6c072f3f --- /dev/null +++ b/src/test/test_util_process.c @@ -0,0 +1,67 @@ +/* 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); + clear_waitpid_callback(res); + + // 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 +}; |