runner.h
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 #ifndef RUNNER_H_
23 #define RUNNER_H_
24 
25 #include <limits.h> /* PATH_MAX */
26 #include <stdio.h> /* FILE */
27 
28 
29 /*
30  * The maximum number of processes (main + helpers) that a test / benchmark
31  * can have.
32  */
33 #define MAX_PROCESSES 8
34 
35 
36 /*
37  * Struct to store both tests and to define helper processes for tasks.
38  */
39 typedef struct {
40  char *task_name;
41  char *process_name;
42  int (*main)(void);
43  int is_helper;
45 
46  /*
47  * The time in milliseconds after which a single test or benchmark times out.
48  */
49  int timeout;
51 
52 
53 /*
54  * Macros used by test-list.h and benchmark-list.h.
55  */
56 #define TASK_LIST_START \
57  task_entry_t TASKS[] = {
58 
59 #define TASK_LIST_END \
60  { 0, 0, 0, 0, 0, 0 } \
61  };
62 
63 #define TEST_DECLARE(name) \
64  int run_test_##name(void);
65 
66 #define TEST_ENTRY(name) \
67  { #name, #name, &run_test_##name, 0, 0, 5000 },
68 
69 #define TEST_ENTRY_CUSTOM(name, is_helper, show_output, timeout) \
70  { #name, #name, &run_test_##name, is_helper, show_output, timeout },
71 
72 #define BENCHMARK_DECLARE(name) \
73  int run_benchmark_##name(void);
74 
75 #define BENCHMARK_ENTRY(name) \
76  { #name, #name, &run_benchmark_##name, 0, 0, 60000 },
77 
78 #define HELPER_DECLARE(name) \
79  int run_helper_##name(void);
80 
81 #define HELPER_ENTRY(task_name, name) \
82  { #task_name, #name, &run_helper_##name, 1, 0, 0 },
83 
84 #define TEST_HELPER HELPER_ENTRY
85 #define BENCHMARK_HELPER HELPER_ENTRY
86 
87 extern char executable_path[4096];
88 
89 /*
90  * Include platform-dependent definitions
91  */
92 #ifdef _WIN32
93 # include "runner-win.h"
94 #else
95 # include "runner-unix.h"
96 #endif
97 
98 
99 /* The array that is filled by test-list.h or benchmark-list.h */
100 extern task_entry_t TASKS[];
101 
102 /*
103  * Run all tests.
104  */
105 int run_tests(int benchmark_output);
106 
107 /*
108  * Run a single test. Starts up any helpers.
109  */
110 int run_test(const char* test,
111  int benchmark_output,
112  int test_count);
113 
114 /*
115  * Run a test part, i.e. the test or one of its helpers.
116  */
117 int run_test_part(const char* test, const char* part);
118 
119 
120 /*
121  * Print tests in sorted order to `stream`. Used by `./run-tests --list`.
122  */
123 void print_tests(FILE* stream);
124 
125 /* Print lines in |buffer| as TAP diagnostics to |stream|. */
126 void print_lines(const char* buffer, size_t size, FILE* stream);
127 
128 /*
129  * Stuff that should be implemented by test-runner-<platform>.h
130  * All functions return 0 on success, -1 on failure, unless specified
131  * otherwise.
132  */
133 
134 /* Do platform-specific initialization. */
135 void platform_init(int argc, char** argv);
136 
137 /* Invoke "argv[0] test-name [test-part]". Store process info in *p. Make sure
138  * that all stdio output of the processes is buffered up. */
139 int process_start(char *name, char* part, process_info_t *p, int is_helper);
140 
141 /* Wait for all `n` processes in `vec` to terminate. Time out after `timeout`
142  * msec, or never if timeout == -1. Return 0 if all processes are terminated,
143  * -1 on error, -2 on timeout. */
144 int process_wait(process_info_t *vec, int n, int timeout);
145 
146 /* Returns the number of bytes in the stdio output buffer for process `p`. */
148 
149 /* Copy the contents of the stdio output buffer to `stream`. */
151 
152 /* Copy the last line of the stdio output buffer to `buffer` */
154  char * buffer,
155  size_t buffer_len);
156 
157 /* Return the name that was specified when `p` was started by process_start */
159 
160 /* Terminate process `p`. */
162 
163 /* Return the exit code of process p. On error, return -1. */
165 
166 /* Clean up after terminating process `p` (e.g. free the output buffer etc.). */
168 
169 /* Move the console cursor one line up and back to the first column. */
170 void rewind_cursor(void);
171 
172 #endif /* RUNNER_H_ */
print_lines
void print_lines(const char *buffer, size_t size, FILE *stream)
Definition: runner.c:433
print_tests
void print_tests(FILE *stream)
Definition: runner.c:404
process_wait
int process_wait(process_info_t *vec, int n, int timeout)
Definition: runner-unix.c:226
process_cleanup
void process_cleanup(process_info_t *p)
Definition: runner-unix.c:432
process_start
int process_start(char *name, char *part, process_info_t *p, int is_helper)
Definition: runner-unix.c:81
task_entry_t::is_helper
int is_helper
Definition: runner.h:43
test
Definition: spinlock_test.cc:36
executable_path
char executable_path[4096]
Definition: runner.c:30
setup.name
name
Definition: setup.py:542
xds_manager.p
p
Definition: xds_manager.py:60
task_entry_t::show_output
int show_output
Definition: runner.h:44
runner-win.h
xds_interop_client.int
int
Definition: xds_interop_client.py:113
run_test
int run_test(const char *test, int benchmark_output, int test_count)
Definition: runner.c:164
task_entry_t
Definition: runner.h:39
task_entry_t::process_name
char * process_name
Definition: runner.h:41
test_count
int test_count
Definition: bloaty/third_party/protobuf/conformance/conformance_cpp.cc:69
buffer
char buffer[1024]
Definition: libuv/docs/code/idle-compute/main.c:8
run_tests
int run_tests(int benchmark_output)
Definition: runner.c:77
task_entry_t::task_name
char * task_name
Definition: runner.h:40
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
process_terminate
int process_terminate(process_info_t *p)
Definition: runner-unix.c:416
benchmark.FILE
FILE
Definition: benchmark.py:21
process_reap
int process_reap(process_info_t *p)
Definition: runner-unix.c:422
process_read_last_line
int process_read_last_line(process_info_t *p, char *buffer, size_t buffer_len)
Definition: runner-unix.c:381
main
Definition: main.py:1
process_get_name
char * process_get_name(process_info_t *p)
Definition: runner-unix.c:410
bench_entry_t
struct task_entry_t bench_entry_t
process_copy_output
int process_copy_output(process_info_t *p, FILE *stream)
Definition: runner-unix.c:357
TASKS
task_entry_t TASKS[]
process_output_size
long int process_output_size(process_info_t *p)
Definition: runner-unix.c:343
rewind_cursor
void rewind_cursor(void)
Definition: runner-unix.c:439
runner-unix.h
task_entry_t::timeout
int timeout
Definition: runner.h:49
platform_init
void platform_init(int argc, char **argv)
Definition: runner-unix.c:70
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
run_test_part
int run_test_part(const char *test, const char *part)
Definition: runner.c:369
timeout
uv_timer_t timeout
Definition: libuv/docs/code/uvwget/main.c:9
process_info_t
Definition: runner-unix.h:28
stream
voidpf stream
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136


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