test_procmon.c (1412B)
1 /* Copyright (c) 2010-2021, The Tor Project, Inc. */ 2 /* See LICENSE for licensing information */ 3 4 #include "orconfig.h" 5 #include "core/or/or.h" 6 #include "test/test.h" 7 8 #include "lib/evloop/procmon.h" 9 10 #include "test/log_test_helpers.h" 11 12 struct event_base; 13 14 static void 15 test_procmon_tor_process_monitor_new(void *ignored) 16 { 17 (void)ignored; 18 tor_process_monitor_t *res; 19 const char *msg; 20 21 res = tor_process_monitor_new(NULL, "probably invalid", 0, NULL, NULL, &msg); 22 tt_assert(!res); 23 tt_str_op(msg, OP_EQ, "invalid PID"); 24 25 res = tor_process_monitor_new(NULL, "243443535345454", 0, NULL, NULL, &msg); 26 tt_assert(!res); 27 tt_str_op(msg, OP_EQ, "invalid PID"); 28 29 res = tor_process_monitor_new(tor_libevent_get_base(), "43", 0, 30 NULL, NULL, &msg); 31 tt_assert(res); 32 tt_assert(!msg); 33 tor_process_monitor_free(res); 34 35 res = tor_process_monitor_new(tor_libevent_get_base(), "44 hello", 0, 36 NULL, NULL, &msg); 37 tt_assert(res); 38 tt_assert(!msg); 39 tor_process_monitor_free(res); 40 41 res = tor_process_monitor_new(tor_libevent_get_base(), "45:hello", 0, 42 NULL, NULL, &msg); 43 tt_assert(res); 44 tt_assert(!msg); 45 46 done: 47 tor_process_monitor_free(res); 48 } 49 50 struct testcase_t procmon_tests[] = { 51 { "tor_process_monitor_new", test_procmon_tor_process_monitor_new, 52 TT_FORK, NULL, NULL }, 53 END_OF_TESTCASES 54 };