aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-10-07 09:32:51 -0400
committerNick Mathewson <nickm@torproject.org>2015-10-07 09:32:51 -0400
commitcec2bc435ed252389d80d77ab17ba4de33ae3153 (patch)
tree6fe1defb670a0a5e3bd5d29d46f2941703b4f99d /src
parent15bfdbeb9db2bc3585ba623851ed2ee2a0dd0a80 (diff)
parentca927b7f637551746220bea118c036825d440679 (diff)
downloadtor-cec2bc435ed252389d80d77ab17ba4de33ae3153.tar.gz
tor-cec2bc435ed252389d80d77ab17ba4de33ae3153.zip
Merge remote-tracking branch 'twstrike/procmon_tests'
Conflicts: src/test/include.am src/test/log_test_helpers.c src/test/log_test_helpers.h
Diffstat (limited to 'src')
-rw-r--r--src/common/procmon.c4
-rw-r--r--src/test/include.am1
-rw-r--r--src/test/test.c3
-rw-r--r--src/test/test_procmon.c55
4 files changed, 60 insertions, 3 deletions
diff --git a/src/common/procmon.c b/src/common/procmon.c
index 2d0f021724..8c59cadebb 100644
--- a/src/common/procmon.c
+++ b/src/common/procmon.c
@@ -192,7 +192,8 @@ tor_process_monitor_new(struct event_base *base,
tor_procmon_callback_t cb, void *cb_arg,
const char **msg)
{
- tor_process_monitor_t *procmon = tor_malloc(sizeof(tor_process_monitor_t));
+ tor_process_monitor_t *procmon = tor_malloc_zero(
+ sizeof(tor_process_monitor_t));
struct parsed_process_specifier_t ppspec;
tor_assert(msg != NULL);
@@ -354,4 +355,3 @@ tor_process_monitor_free(tor_process_monitor_t *procmon)
tor_free(procmon);
}
-
diff --git a/src/test/include.am b/src/test/include.am
index 67bc600911..5b3c045de1 100644
--- a/src/test/include.am
+++ b/src/test/include.am
@@ -86,6 +86,7 @@ src_test_test_SOURCES = \
src/test/test_oom.c \
src/test/test_options.c \
src/test/test_policy.c \
+ src/test/test_procmon.c \
src/test/test_pt.c \
src/test/test_relay.c \
src/test/test_relaycell.c \
diff --git a/src/test/test.c b/src/test/test.c
index fd0f3aff1a..33a1e57092 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -1151,6 +1151,7 @@ extern struct testcase_t nodelist_tests[];
extern struct testcase_t oom_tests[];
extern struct testcase_t options_tests[];
extern struct testcase_t policy_tests[];
+extern struct testcase_t procmon_tests[];
extern struct testcase_t pt_tests[];
extern struct testcase_t relay_tests[];
extern struct testcase_t relaycell_tests[];
@@ -1203,6 +1204,7 @@ struct testgroup_t testgroups[] = {
{ "oom/", oom_tests },
{ "options/", options_tests },
{ "policy/" , policy_tests },
+ { "procmon/", procmon_tests },
{ "pt/", pt_tests },
{ "relay/" , relay_tests },
{ "relaycell/", relaycell_tests },
@@ -1222,4 +1224,3 @@ struct testgroup_t testgroups[] = {
{ "dns/", dns_tests },
END_OF_GROUPS
};
-
diff --git a/src/test/test_procmon.c b/src/test/test_procmon.c
new file mode 100644
index 0000000000..6a9c209f7c
--- /dev/null
+++ b/src/test/test_procmon.c
@@ -0,0 +1,55 @@
+/* Copyright (c) 2010-2015, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#define PROCMON_PRIVATE
+#include "orconfig.h"
+#include "or.h"
+#include "test.h"
+
+#include "procmon.h"
+
+#include "log_test_helpers.h"
+
+#define NS_MODULE procmon
+
+struct event_base;
+
+static void
+test_procmon_tor_process_monitor_new(void *ignored)
+{
+ (void)ignored;
+ tor_process_monitor_t *res;
+ const char *msg;
+
+ res = tor_process_monitor_new(NULL, "probably invalid", 0, NULL, NULL, &msg);
+ tt_assert(!res);
+ tt_str_op(msg, OP_EQ, "invalid PID");
+
+ res = tor_process_monitor_new(NULL, "243443535345454", 0, NULL, NULL, &msg);
+ tt_assert(!res);
+ tt_str_op(msg, OP_EQ, "invalid PID");
+
+ res = tor_process_monitor_new(tor_libevent_get_base(), "43", 0,
+ NULL, NULL, &msg);
+ tt_assert(res);
+ tt_assert(!msg);
+
+ res = tor_process_monitor_new(tor_libevent_get_base(), "44 hello", 0,
+ NULL, NULL, &msg);
+ tt_assert(res);
+ tt_assert(!msg);
+
+ res = tor_process_monitor_new(tor_libevent_get_base(), "45:hello", 0,
+ NULL, NULL, &msg);
+ tt_assert(res);
+ tt_assert(!msg);
+
+ done:
+ (void)0;
+}
+
+struct testcase_t procmon_tests[] = {
+ { "tor_process_monitor_new", test_procmon_tor_process_monitor_new,
+ TT_FORK, NULL, NULL },
+ END_OF_TESTCASES
+};