test-child.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright (c) 2011-2016, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #include "orconfig.h"
  4. #include <stdio.h>
  5. #ifdef _WIN32
  6. #define WINDOWS_LEAN_AND_MEAN
  7. #include <windows.h>
  8. #else
  9. #include <unistd.h>
  10. #endif
  11. #include <string.h>
  12. #ifdef _WIN32
  13. #define SLEEP(sec) Sleep((sec)*1000)
  14. #else
  15. #define SLEEP(sec) sleep(sec)
  16. #endif
  17. /** Trivial test program which prints out its command line arguments so we can
  18. * check if tor_spawn_background() works */
  19. int
  20. main(int argc, char **argv)
  21. {
  22. int i;
  23. int delay = 1;
  24. int fast = 0;
  25. if (argc > 1) {
  26. if (!strcmp(argv[1], "--hang")) {
  27. delay = 60;
  28. } else if (!strcmp(argv[1], "--fast")) {
  29. fast = 1;
  30. delay = 0;
  31. }
  32. }
  33. fprintf(stdout, "OUT\n");
  34. fprintf(stderr, "ERR\n");
  35. for (i = 1; i < argc; i++)
  36. fprintf(stdout, "%s\n", argv[i]);
  37. if (!fast)
  38. fprintf(stdout, "SLEEPING\n");
  39. /* We need to flush stdout so that test_util_spawn_background_partial_read()
  40. succeed. Otherwise ReadFile() will get the entire output in one */
  41. // XXX: Can we make stdio flush on newline?
  42. fflush(stdout);
  43. if (!fast)
  44. SLEEP(1);
  45. fprintf(stdout, "DONE\n");
  46. fflush(stdout);
  47. if (fast)
  48. return 0;
  49. while (--delay) {
  50. SLEEP(1);
  51. }
  52. return 0;
  53. }