test_procmon.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright (c) 2010-2017, 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. tor_process_monitor_free(res);
  28. res = tor_process_monitor_new(tor_libevent_get_base(), "44 hello", 0,
  29. NULL, NULL, &msg);
  30. tt_assert(res);
  31. tt_assert(!msg);
  32. tor_process_monitor_free(res);
  33. res = tor_process_monitor_new(tor_libevent_get_base(), "45:hello", 0,
  34. NULL, NULL, &msg);
  35. tt_assert(res);
  36. tt_assert(!msg);
  37. done:
  38. tor_process_monitor_free(res);
  39. }
  40. struct testcase_t procmon_tests[] = {
  41. { "tor_process_monitor_new", test_procmon_tor_process_monitor_new,
  42. TT_FORK, NULL, NULL },
  43. END_OF_TESTCASES
  44. };