Blame test/runner.h

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