1
0

run-tests.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to
  5. * deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  7. * sell copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  18. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  19. * IN THE SOFTWARE.
  20. */
  21. #include <errno.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #ifdef _WIN32
  25. # include <io.h>
  26. #else
  27. # include <unistd.h>
  28. #endif
  29. #include "uv.h"
  30. #include "runner.h"
  31. #include "task.h"
  32. /* Actual tests and helpers are defined in test-list.h */
  33. #include "test-list.h"
  34. /* The time in milliseconds after which a single test times out. */
  35. #define TEST_TIMEOUT 5000
  36. int ipc_helper(int listen_after_write);
  37. int ipc_helper_tcp_connection(void);
  38. int ipc_send_recv_helper(void);
  39. int stdio_over_pipes_helper(void);
  40. static int maybe_run_test(int argc, char **argv);
  41. int main(int argc, char **argv) {
  42. platform_init(argc, argv);
  43. argv = uv_setup_args(argc, argv);
  44. switch (argc) {
  45. case 1: return run_tests(TEST_TIMEOUT, 0);
  46. case 2: return maybe_run_test(argc, argv);
  47. case 3: return run_test_part(argv[1], argv[2]);
  48. default:
  49. LOGF("Too many arguments.\n");
  50. return 1;
  51. }
  52. }
  53. static int maybe_run_test(int argc, char **argv) {
  54. if (strcmp(argv[1], "--list") == 0) {
  55. print_tests(stdout);
  56. return 0;
  57. }
  58. if (strcmp(argv[1], "ipc_helper_listen_before_write") == 0) {
  59. return ipc_helper(0);
  60. }
  61. if (strcmp(argv[1], "ipc_helper_listen_after_write") == 0) {
  62. return ipc_helper(1);
  63. }
  64. if (strcmp(argv[1], "ipc_send_recv_helper") == 0) {
  65. return ipc_send_recv_helper();
  66. }
  67. if (strcmp(argv[1], "ipc_helper_tcp_connection") == 0) {
  68. return ipc_helper_tcp_connection();
  69. }
  70. if (strcmp(argv[1], "stdio_over_pipes_helper") == 0) {
  71. return stdio_over_pipes_helper();
  72. }
  73. if (strcmp(argv[1], "spawn_helper1") == 0) {
  74. return 1;
  75. }
  76. if (strcmp(argv[1], "spawn_helper2") == 0) {
  77. printf("hello world\n");
  78. return 1;
  79. }
  80. if (strcmp(argv[1], "spawn_helper3") == 0) {
  81. char buffer[256];
  82. ASSERT(buffer == fgets(buffer, sizeof(buffer) - 1, stdin));
  83. buffer[sizeof(buffer) - 1] = '\0';
  84. fputs(buffer, stdout);
  85. return 1;
  86. }
  87. if (strcmp(argv[1], "spawn_helper4") == 0) {
  88. /* Never surrender, never return! */
  89. while (1) uv_sleep(10000);
  90. }
  91. if (strcmp(argv[1], "spawn_helper5") == 0) {
  92. const char out[] = "fourth stdio!\n";
  93. #ifdef _WIN32
  94. DWORD bytes;
  95. WriteFile((HANDLE) _get_osfhandle(3), out, sizeof(out) - 1, &bytes, NULL);
  96. #else
  97. {
  98. ssize_t r;
  99. do
  100. r = write(3, out, sizeof(out) - 1);
  101. while (r == -1 && errno == EINTR);
  102. fsync(3);
  103. }
  104. #endif
  105. return 1;
  106. }
  107. if (strcmp(argv[1], "spawn_helper6") == 0) {
  108. int r;
  109. r = fprintf(stdout, "hello world\n");
  110. ASSERT(r > 0);
  111. r = fprintf(stderr, "hello errworld\n");
  112. ASSERT(r > 0);
  113. return 1;
  114. }
  115. if (strcmp(argv[1], "spawn_helper7") == 0) {
  116. int r;
  117. char *test;
  118. /* Test if the test value from the parent is still set */
  119. test = getenv("ENV_TEST");
  120. ASSERT(test != NULL);
  121. r = fprintf(stdout, "%s", test);
  122. ASSERT(r > 0);
  123. return 1;
  124. }
  125. return run_test(argv[1], TEST_TIMEOUT, 0, 1);
  126. }