|
@@ -1388,7 +1388,11 @@ run_util_spawn_background(const char *argv[], const char *expected_out,
|
|
|
char stdout_buf[100], stderr_buf[100];
|
|
|
|
|
|
/* Start the program */
|
|
|
+#ifdef MS_WINDOWS
|
|
|
+ process_handle = tor_spawn_background(NULL, argv);
|
|
|
+#else
|
|
|
process_handle = tor_spawn_background(argv[0], argv);
|
|
|
+#endif
|
|
|
|
|
|
tt_int_op(process_handle.status, ==, expected_status);
|
|
|
|
|
@@ -1425,55 +1429,14 @@ run_util_spawn_background(const char *argv[], const char *expected_out,
|
|
|
;
|
|
|
}
|
|
|
|
|
|
-static char*
|
|
|
-get_windows_path(const char *process_name, const char **dest)
|
|
|
-{
|
|
|
-#ifdef MS_WINDOWS
|
|
|
- char fn[MAX_PATH];
|
|
|
- DWORD retval;
|
|
|
- char *new_fn = NULL;
|
|
|
- int i;
|
|
|
-
|
|
|
- /* Get the file name of the current module */
|
|
|
- retval = GetModuleFileName(NULL, fn, sizeof(fn));
|
|
|
- if (retval >= sizeof(fn)) {
|
|
|
- log_warn(LD_GENERAL, "Executable path name was longer than maximum (%d)", sizeof(fn));
|
|
|
- return NULL;
|
|
|
- }
|
|
|
-
|
|
|
- /* Remove the filename component */
|
|
|
- for (i = retval - 1; i >= 0; i--) {
|
|
|
- /* \0 terminate at first path separator from end */
|
|
|
- if ('\\' == fn[i] || '/' == fn[i]) {
|
|
|
- fn[i] = '\0';
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- tor_asprintf(&new_fn, "%s\\%s", fn, process_name);
|
|
|
- *dest = new_fn;
|
|
|
- return new_fn;
|
|
|
-#else
|
|
|
- (void)process_name;
|
|
|
- (void)dest;
|
|
|
- return NULL;
|
|
|
-#endif
|
|
|
-}
|
|
|
-
|
|
|
/** Check that we can launch a process and read the output */
|
|
|
static void
|
|
|
test_util_spawn_background_ok(void *ptr)
|
|
|
{
|
|
|
#ifdef MS_WINDOWS
|
|
|
- const char *argv[] = {NULL, "--test", NULL};
|
|
|
+ const char *argv[] = {"test-child.exe", "--test", NULL};
|
|
|
const char *expected_out = "OUT\r\n--test\r\nSLEEPING\r\nDONE\r\n";
|
|
|
const char *expected_err = "ERR\r\n";
|
|
|
- char *filename;
|
|
|
-
|
|
|
- /* Find path to test-child.exe (same directory as this executable */
|
|
|
- filename = get_windows_path("test-child.exe", argv);
|
|
|
- tt_assert(filename != NULL);
|
|
|
- log_warn(LD_GENERAL, "Using %s as path", filename);
|
|
|
#else
|
|
|
const char *argv[] = {BUILDDIR "/src/test/test-child", "--test", NULL};
|
|
|
const char *expected_out = "OUT\n--test\nSLEEPING\nDONE\n";
|
|
@@ -1483,12 +1446,6 @@ test_util_spawn_background_ok(void *ptr)
|
|
|
(void)ptr;
|
|
|
|
|
|
run_util_spawn_background(argv, expected_out, expected_err, 0, 1);
|
|
|
- done:
|
|
|
-#ifdef MS_WINDOWS
|
|
|
- tor_free(filename);
|
|
|
-#else
|
|
|
- ;
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
/** Check that failing to find the executable works as expected */
|
|
@@ -1527,18 +1484,12 @@ test_util_spawn_background_partial_read(void *ptr)
|
|
|
process_handle_t process_handle;
|
|
|
char stdout_buf[100], stderr_buf[100];
|
|
|
#ifdef MS_WINDOWS
|
|
|
- const char *argv[] = {NULL, "--test", NULL};
|
|
|
+ const char *argv[] = {"test-child.exe", "--test", NULL};
|
|
|
const char *expected_out[] = { "OUT\r\n--test\r\nSLEEPING\r\n",
|
|
|
"DONE\r\n",
|
|
|
NULL };
|
|
|
const char *expected_err = "ERR\r\n";
|
|
|
int expected_out_ctr;
|
|
|
- char *filename;
|
|
|
-
|
|
|
- /* Find path to test-child.exe (same directory as this executable */
|
|
|
- filename = get_windows_path("test-child.exe", argv);
|
|
|
- tt_assert(filename != NULL);
|
|
|
- log_warn(LD_GENERAL, "Using %s as path", filename);
|
|
|
#else
|
|
|
const char *argv[] = {BUILDDIR "/src/test/test-child", "--test", NULL};
|
|
|
const char *expected_out = "OUT\n--test\nSLEEPING\nDONE\n";
|
|
@@ -1547,9 +1498,8 @@ test_util_spawn_background_partial_read(void *ptr)
|
|
|
(void)ptr;
|
|
|
|
|
|
/* Start the program */
|
|
|
- process_handle = tor_spawn_background(argv[0], argv);
|
|
|
+ process_handle = tor_spawn_background(NULL, argv);
|
|
|
tt_int_op(process_handle.status, ==, expected_status);
|
|
|
- tor_free(filename);
|
|
|
|
|
|
/* Check stdout */
|
|
|
#ifdef MS_WINDOWS
|
|
@@ -1597,11 +1547,7 @@ test_util_spawn_background_partial_read(void *ptr)
|
|
|
tt_int_op(pos, ==, strlen(expected_err));
|
|
|
|
|
|
done:
|
|
|
-#ifdef MS_WINDOWS
|
|
|
- tor_free(filename);
|
|
|
-#else
|
|
|
;
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
static void
|