run-tests.c
Go to the documentation of this file.
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 
22 #include <errno.h>
23 #include <stdio.h>
24 #include <string.h>
25 
26 #ifdef _WIN32
27 # include <io.h>
28 #else
29 # include <unistd.h>
30 #endif
31 
32 #include "uv.h"
33 #include "runner.h"
34 #include "task.h"
35 
36 /* Actual tests and helpers are defined in test-list.h */
37 #include "test-list.h"
38 
39 int ipc_helper(int listen_after_write);
42 int ipc_helper_closed_handle(void);
43 int ipc_send_recv_helper(void);
44 int ipc_helper_bind_twice(void);
45 int ipc_helper_send_zero(void);
46 int stdio_over_pipes_helper(void);
47 void spawn_stdin_stdout(void);
48 void process_title_big_argv(void);
49 int spawn_tcp_server_helper(void);
50 
51 static int maybe_run_test(int argc, char **argv);
52 
53 
54 int main(int argc, char **argv) {
55 #ifndef _WIN32
56  if (0 == geteuid() && NULL == getenv("UV_RUN_AS_ROOT")) {
57  fprintf(stderr, "The libuv test suite cannot be run as root.\n");
58  return EXIT_FAILURE;
59  }
60 #endif
61 
62  platform_init(argc, argv);
63  argv = uv_setup_args(argc, argv);
64 
65  switch (argc) {
66  case 1: return run_tests(0);
67  case 2: return maybe_run_test(argc, argv);
68  case 3: return run_test_part(argv[1], argv[2]);
69  case 4: return maybe_run_test(argc, argv);
70  default:
71  fprintf(stderr, "Too many arguments.\n");
72  fflush(stderr);
73  return EXIT_FAILURE;
74  }
75 
76 #ifndef __SUNPRO_C
77  return EXIT_SUCCESS;
78 #endif
79 }
80 
81 
82 static int maybe_run_test(int argc, char **argv) {
83  if (strcmp(argv[1], "--list") == 0) {
85  return 0;
86  }
87 
88  if (strcmp(argv[1], "ipc_helper_listen_before_write") == 0) {
89  return ipc_helper(0);
90  }
91 
92  if (strcmp(argv[1], "ipc_helper_listen_after_write") == 0) {
93  return ipc_helper(1);
94  }
95 
96  if (strcmp(argv[1], "ipc_helper_heavy_traffic_deadlock_bug") == 0) {
98  }
99 
100  if (strcmp(argv[1], "ipc_send_recv_helper") == 0) {
101  return ipc_send_recv_helper();
102  }
103 
104  if (strcmp(argv[1], "ipc_helper_tcp_connection") == 0) {
105  return ipc_helper_tcp_connection();
106  }
107 
108  if (strcmp(argv[1], "ipc_helper_closed_handle") == 0) {
109  return ipc_helper_closed_handle();
110  }
111 
112  if (strcmp(argv[1], "ipc_helper_bind_twice") == 0) {
113  return ipc_helper_bind_twice();
114  }
115 
116  if (strcmp(argv[1], "ipc_helper_send_zero") == 0) {
117  return ipc_helper_send_zero();
118  }
119 
120  if (strcmp(argv[1], "stdio_over_pipes_helper") == 0) {
121  return stdio_over_pipes_helper();
122  }
123 
124  if (strcmp(argv[1], "spawn_helper1") == 0) {
126  return 1;
127  }
128 
129  if (strcmp(argv[1], "spawn_helper2") == 0) {
131  printf("hello world\n");
132  return 1;
133  }
134 
135  if (strcmp(argv[1], "spawn_tcp_server_helper") == 0) {
137  return spawn_tcp_server_helper();
138  }
139 
140  if (strcmp(argv[1], "spawn_helper3") == 0) {
141  char buffer[256];
143  ASSERT(buffer == fgets(buffer, sizeof(buffer) - 1, stdin));
144  buffer[sizeof(buffer) - 1] = '\0';
145  fputs(buffer, stdout);
146  return 1;
147  }
148 
149  if (strcmp(argv[1], "spawn_helper4") == 0) {
151  /* Never surrender, never return! */
152  while (1) uv_sleep(10000);
153  }
154 
155  if (strcmp(argv[1], "spawn_helper5") == 0) {
156  const char out[] = "fourth stdio!\n";
158  {
159 #ifdef _WIN32
160  DWORD bytes;
161  WriteFile((HANDLE) _get_osfhandle(3), out, sizeof(out) - 1, &bytes, NULL);
162 #else
163  ssize_t r;
164 
165  do
166  r = write(3, out, sizeof(out) - 1);
167  while (r == -1 && errno == EINTR);
168 
169  fsync(3);
170 #endif
171  }
172  return 1;
173  }
174 
175  if (strcmp(argv[1], "spawn_helper6") == 0) {
176  int r;
177 
179 
180  r = fprintf(stdout, "hello world\n");
181  ASSERT(r > 0);
182 
183  r = fprintf(stderr, "hello errworld\n");
184  ASSERT(r > 0);
185 
186  return 1;
187  }
188 
189  if (strcmp(argv[1], "spawn_helper7") == 0) {
190  int r;
191  char *test;
192 
194 
195  /* Test if the test value from the parent is still set */
196  test = getenv("ENV_TEST");
197  ASSERT(test != NULL);
198 
199  r = fprintf(stdout, "%s", test);
200  ASSERT(r > 0);
201 
202  return 1;
203  }
204 
205 #ifndef _WIN32
206  if (strcmp(argv[1], "spawn_helper8") == 0) {
207  int fd;
208 
210  ASSERT(sizeof(fd) == read(0, &fd, sizeof(fd)));
211  ASSERT(fd > 2);
212 # if defined(__PASE__) /* On IBMi PASE, write() returns 1 */
213  ASSERT(1 == write(fd, "x", 1));
214 # else
215  ASSERT(-1 == write(fd, "x", 1));
216 # endif /* !__PASE__ */
217 
218  return 1;
219  }
220 #endif /* !_WIN32 */
221 
222  if (strcmp(argv[1], "spawn_helper9") == 0) {
225  return 1;
226  }
227 
228 #ifndef _WIN32
229  if (strcmp(argv[1], "spawn_helper_setuid_setgid") == 0) {
230  uv_uid_t uid = atoi(argv[2]);
231  uv_gid_t gid = atoi(argv[3]);
232 
233  ASSERT(uid == getuid());
234  ASSERT(gid == getgid());
236 
237  return 1;
238  }
239 #endif /* !_WIN32 */
240 
241  if (strcmp(argv[1], "process_title_big_argv_helper") == 0) {
244  return 0;
245  }
246 
247  return run_test(argv[1], 0, 1);
248 }
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
ipc_helper_bind_twice
int ipc_helper_bind_twice(void)
Definition: test-ipc.c:903
task.h
demumble_test.stdout
stdout
Definition: demumble_test.py:38
spawn_tcp_server_helper
int spawn_tcp_server_helper(void)
Definition: test-spawn.c:661
write
#define write
Definition: test-fs.c:47
ipc_helper_closed_handle
int ipc_helper_closed_handle(void)
Definition: test-ipc.c:875
test
Definition: spinlock_test.cc:36
run_test_part
int run_test_part(const char *test, const char *part)
Definition: runner.c:369
string.h
printf
_Use_decl_annotations_ int __cdecl printf(const char *_Format,...)
Definition: cs_driver.c:91
test-list.h
platform_init
void platform_init(int argc, char **argv)
Definition: runner-unix.c:70
ASSERT
#define ASSERT(expr)
Definition: task.h:102
uv_uid_t
uid_t uv_uid_t
Definition: unix.h:167
print_tests
void print_tests(FILE *stream)
Definition: runner.c:404
demumble_test.stdin
stdin
Definition: demumble_test.py:37
python_utils.port_server.stderr
stderr
Definition: port_server.py:51
spawn_stdin_stdout
void spawn_stdin_stdout(void)
Definition: test-spawn.c:1892
ipc_helper
int ipc_helper(int listen_after_write)
Definition: test-ipc.c:728
run_tests
int run_tests(int benchmark_output)
Definition: runner.c:77
ssize_t
intptr_t ssize_t
Definition: win.h:27
ipc_helper_tcp_connection
int ipc_helper_tcp_connection(void)
Definition: test-ipc.c:781
ipc_helper_send_zero
int ipc_helper_send_zero(void)
Definition: test-ipc.c:949
uv_setup_args
UV_EXTERN char ** uv_setup_args(int argc, char **argv)
Definition: aix.c:832
maybe_run_test
static int maybe_run_test(int argc, char **argv)
Definition: run-tests.c:82
buffer
char buffer[1024]
Definition: libuv/docs/code/idle-compute/main.c:8
uv_sleep
UV_EXTERN void uv_sleep(unsigned int msec)
Definition: unix/core.c:1521
notify_parent_process
void notify_parent_process(void)
Definition: runner-unix.c:54
stdio_over_pipes_helper
int stdio_over_pipes_helper(void)
Definition: test-stdio-over-pipes.c:206
uv.h
runner.h
process_title_big_argv
void process_title_big_argv(void)
Definition: test-process-title.c:129
update_failure_list.test
test
Definition: bloaty/third_party/protobuf/conformance/update_failure_list.py:69
read
int read(izstream &zs, T *x, Items items)
Definition: bloaty/third_party/zlib/contrib/iostream2/zstream.h:115
main
int main(int argc, char **argv)
Definition: run-tests.c:54
bytes
uint8 bytes[10]
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc:153
ipc_helper_heavy_traffic_deadlock_bug
int ipc_helper_heavy_traffic_deadlock_bug(void)
Definition: test-ipc-heavy-traffic-deadlock-bug.c:144
fix_build_deps.r
r
Definition: fix_build_deps.py:491
tests.stress.client.run_test
def run_test(args)
Definition: src/python/grpcio_tests/tests/stress/client.py:116
getenv
#define getenv(ptr)
Definition: ares_private.h:106
uv_gid_t
gid_t uv_gid_t
Definition: unix.h:166
ipc_send_recv_helper
int ipc_send_recv_helper(void)
Definition: test-ipc-send-recv.c:407
errno.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:14