0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/deps/uv/test/runner.h

178 lines
5.3 KiB
C
Raw Normal View History

2011-05-13 04:16:40 +02:00
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef RUNNER_H_
#define RUNNER_H_
#include <limits.h> /* PATH_MAX */
#include <stdio.h> /* FILE */
2011-05-13 04:16:40 +02:00
/*
* The maximum number of processes (main + helpers) that a test / benchmark
* can have.
*/
#define MAX_PROCESSES 8
/*
* Struct to store both tests and to define helper processes for tasks.
*/
typedef struct {
char *task_name;
char *process_name;
2013-01-11 13:49:45 +01:00
int (*main)(void);
2011-05-13 04:16:40 +02:00
int is_helper;
int show_output;
2014-02-27 03:08:30 +01:00
/*
* The time in milliseconds after which a single test or benchmark times out.
*/
int timeout;
2011-05-13 04:16:40 +02:00
} task_entry_t, bench_entry_t;
/*
* Macros used by test-list.h and benchmark-list.h.
*/
#define TASK_LIST_START \
task_entry_t TASKS[] = {
#define TASK_LIST_END \
2014-02-27 03:08:30 +01:00
{ 0, 0, 0, 0, 0, 0 } \
2011-05-13 04:16:40 +02:00
};
#define TEST_DECLARE(name) \
2013-01-11 13:49:45 +01:00
int run_test_##name(void);
2011-05-13 04:16:40 +02:00
#define TEST_ENTRY(name) \
2014-02-27 03:08:30 +01:00
{ #name, #name, &run_test_##name, 0, 0, 5000 },
2014-02-27 03:08:30 +01:00
#define TEST_ENTRY_CUSTOM(name, is_helper, show_output, timeout) \
{ #name, #name, &run_test_##name, is_helper, show_output, timeout },
2011-05-13 04:16:40 +02:00
#define BENCHMARK_DECLARE(name) \
2013-01-11 13:49:45 +01:00
int run_benchmark_##name(void);
2011-05-13 04:16:40 +02:00
#define BENCHMARK_ENTRY(name) \
2014-02-27 03:08:30 +01:00
{ #name, #name, &run_benchmark_##name, 0, 0, 60000 },
2011-05-13 04:16:40 +02:00
#define HELPER_DECLARE(name) \
2013-01-11 13:49:45 +01:00
int run_helper_##name(void);
2011-05-13 04:16:40 +02:00
#define HELPER_ENTRY(task_name, name) \
2014-02-27 03:08:30 +01:00
{ #task_name, #name, &run_helper_##name, 1, 0, 0 },
2011-05-13 04:16:40 +02:00
#define TEST_HELPER HELPER_ENTRY
#define BENCHMARK_HELPER HELPER_ENTRY
#ifdef PATH_MAX
extern char executable_path[PATH_MAX];
#else
extern char executable_path[4096];
#endif
2011-05-13 04:16:40 +02:00
/*
* Include platform-dependent definitions
*/
#ifdef _WIN32
# include "runner-win.h"
#else
# include "runner-unix.h"
#endif
/* The array that is filled by test-list.h or benchmark-list.h */
extern task_entry_t TASKS[];
2011-07-14 23:28:52 +02:00
/*
* Run all tests.
*/
2014-02-27 03:08:30 +01:00
int run_tests(int benchmark_output);
2011-05-13 04:16:40 +02:00
2011-07-14 23:28:52 +02:00
/*
* Run a single test. Starts up any helpers.
*/
2013-02-24 04:03:49 +01:00
int run_test(const char* test,
int benchmark_output,
int test_count);
2011-07-14 23:28:52 +02:00
/*
* Run a test part, i.e. the test or one of its helpers.
*/
int run_test_part(const char* test, const char* part);
2011-05-13 04:16:40 +02:00
/*
* Print tests in sorted order to `stream`. Used by `./run-tests --list`.
*/
void print_tests(FILE* stream);
/* Print lines in |buffer| as TAP diagnostics to |stream|. */
void print_lines(const char* buffer, size_t size, FILE* stream);
2011-05-13 04:16:40 +02:00
/*
* Stuff that should be implemented by test-runner-<platform>.h
* All functions return 0 on success, -1 on failure, unless specified
* otherwise.
*/
/* Do platform-specific initialization. */
int platform_init(int argc, char** argv);
2011-05-13 04:16:40 +02:00
2011-07-14 23:28:52 +02:00
/* Invoke "argv[0] test-name [test-part]". Store process info in *p. */
2011-05-13 04:16:40 +02:00
/* Make sure that all stdio output of the processes is buffered up. */
2012-10-06 23:04:30 +02:00
int process_start(char *name, char* part, process_info_t *p, int is_helper);
2011-05-13 04:16:40 +02:00
/* Wait for all `n` processes in `vec` to terminate. */
/* Time out after `timeout` msec, or never if timeout == -1 */
/* Return 0 if all processes are terminated, -1 on error, -2 on timeout. */
int process_wait(process_info_t *vec, int n, int timeout);
/* Returns the number of bytes in the stdio output buffer for process `p`. */
long int process_output_size(process_info_t *p);
/* Copy the contents of the stdio output buffer to `stream`. */
int process_copy_output(process_info_t* p, FILE* stream);
2011-05-13 04:16:40 +02:00
2013-05-11 00:30:53 +02:00
/* Copy the last line of the stdio output buffer to `buffer` */
int process_read_last_line(process_info_t *p,
char * buffer,
size_t buffer_len);
2011-05-13 04:16:40 +02:00
/* Return the name that was specified when `p` was started by process_start */
char* process_get_name(process_info_t *p);
/* Terminate process `p`. */
int process_terminate(process_info_t *p);
/* Return the exit code of process p. */
/* On error, return -1. */
int process_reap(process_info_t *p);
/* Clean up after terminating process `p` (e.g. free the output buffer etc.). */
void process_cleanup(process_info_t *p);
/* Move the console cursor one line up and back to the first column. */
2013-01-11 13:49:45 +01:00
void rewind_cursor(void);
2011-05-13 04:16:40 +02:00
#endif /* RUNNER_H_ */