mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
refactor win/nix handling for test_spawn_background*()
Instead of having a #if ... for every function, just define TEST_CHILD to the right patch and EOL to the expected line terminator.
This commit is contained in:
parent
e3833193af
commit
a5c092b34b
@ -2530,8 +2530,17 @@ test_util_fgets_eagain(void *ptr)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef BUILDDIR
|
||||||
|
#define BUILDDIR "."
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define notify_pending_waitpid_callbacks() STMT_NIL
|
#define notify_pending_waitpid_callbacks() STMT_NIL
|
||||||
|
#define TEST_CHILD "test-child.exe"
|
||||||
|
#define EOL "\r\n"
|
||||||
|
#else
|
||||||
|
#define TEST_CHILD (BUILDDIR "/src/test/test-child")
|
||||||
|
#define EOL "\n"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Helper function for testing tor_spawn_background */
|
/** Helper function for testing tor_spawn_background */
|
||||||
@ -2617,15 +2626,9 @@ run_util_spawn_background(const char *argv[], const char *expected_out,
|
|||||||
static void
|
static void
|
||||||
test_util_spawn_background_ok(void *ptr)
|
test_util_spawn_background_ok(void *ptr)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
const char *argv[] = {TEST_CHILD, "--test", NULL};
|
||||||
const char *argv[] = {"test-child.exe", "--test", NULL};
|
const char *expected_out = "OUT"EOL "--test"EOL "SLEEPING"EOL "DONE" EOL;
|
||||||
const char *expected_out = "OUT\r\n--test\r\nSLEEPING\r\nDONE\r\n";
|
const char *expected_err = "ERR"EOL;
|
||||||
const char *expected_err = "ERR\r\n";
|
|
||||||
#else
|
|
||||||
const char *argv[] = {BUILDDIR "/src/test/test-child", "--test", NULL};
|
|
||||||
const char *expected_out = "OUT\n--test\nSLEEPING\nDONE\n";
|
|
||||||
const char *expected_err = "ERR\n";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
(void)ptr;
|
(void)ptr;
|
||||||
|
|
||||||
@ -2637,9 +2640,6 @@ test_util_spawn_background_ok(void *ptr)
|
|||||||
static void
|
static void
|
||||||
test_util_spawn_background_fail(void *ptr)
|
test_util_spawn_background_fail(void *ptr)
|
||||||
{
|
{
|
||||||
#ifndef BUILDDIR
|
|
||||||
#define BUILDDIR "."
|
|
||||||
#endif
|
|
||||||
const char *argv[] = {BUILDDIR "/src/test/no-such-file", "--test", NULL};
|
const char *argv[] = {BUILDDIR "/src/test/no-such-file", "--test", NULL};
|
||||||
const char *expected_err = "";
|
const char *expected_err = "";
|
||||||
char expected_out[1024];
|
char expected_out[1024];
|
||||||
@ -2676,30 +2676,21 @@ test_util_spawn_background_partial_read_impl(int exit_early)
|
|||||||
process_handle_t *process_handle=NULL;
|
process_handle_t *process_handle=NULL;
|
||||||
int status;
|
int status;
|
||||||
char stdout_buf[100], stderr_buf[100];
|
char stdout_buf[100], stderr_buf[100];
|
||||||
#ifdef _WIN32
|
|
||||||
const char *argv[] = {"test-child.exe", "--test", NULL};
|
const char *argv[] = {TEST_CHILD, "--test", NULL};
|
||||||
const char *expected_out[] = { "OUT\r\n--test\r\nSLEEPING\r\n",
|
const char *expected_out[] = { "OUT" EOL "--test" EOL "SLEEPING" EOL,
|
||||||
"DONE\r\n",
|
"DONE" EOL,
|
||||||
NULL };
|
NULL };
|
||||||
const char *expected_err = "ERR\r\n";
|
const char *expected_err = "ERR" EOL;
|
||||||
#else
|
|
||||||
const char *argv[] = {BUILDDIR "/src/test/test-child", "--test", NULL};
|
#ifndef _WIN32
|
||||||
const char *expected_out[] = { "OUT\n--test\nSLEEPING\n",
|
|
||||||
"DONE\n",
|
|
||||||
NULL };
|
|
||||||
const char *expected_err = "ERR\n";
|
|
||||||
int eof = 0;
|
int eof = 0;
|
||||||
#endif
|
#endif
|
||||||
int expected_out_ctr;
|
int expected_out_ctr;
|
||||||
|
|
||||||
|
|
||||||
if (exit_early) {
|
if (exit_early) {
|
||||||
argv[1] = "--hang";
|
argv[1] = "--hang";
|
||||||
#ifdef _WIN32
|
expected_out[0] = "OUT"EOL "--hang"EOL "SLEEPING" EOL;
|
||||||
expected_out[0] = "OUT\r\n--hang\r\nSLEEPING\r\n";
|
|
||||||
#else
|
|
||||||
expected_out[0] = "OUT\n--hang\nSLEEPING\n";
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start the program */
|
/* Start the program */
|
||||||
@ -2801,11 +2792,7 @@ test_util_spawn_background_waitpid_notify(void *arg)
|
|||||||
int status;
|
int status;
|
||||||
int ms_timer;
|
int ms_timer;
|
||||||
|
|
||||||
#ifdef _WIN32
|
const char *argv[] = {TEST_CHILD, "--fast", NULL};
|
||||||
const char *argv[] = {"test-child.exe", "--fast", NULL};
|
|
||||||
#else
|
|
||||||
const char *argv[] = {BUILDDIR "/src/test/test-child", "--fast", NULL};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
(void) arg;
|
(void) arg;
|
||||||
|
|
||||||
@ -2849,6 +2836,9 @@ test_util_spawn_background_waitpid_notify(void *arg)
|
|||||||
tor_process_handle_destroy(process_handle, 1);
|
tor_process_handle_destroy(process_handle, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef TEST_CHILD
|
||||||
|
#undef EOL
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for format_hex_number_sigsafe()
|
* Test for format_hex_number_sigsafe()
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user