test_procmon.c 1.3 KB

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