test: fix spawn test with autotools build

Fix spawn_reads_child_path when executed as `test/run-tests` or
`make check`:

1. `make check` builds a dynamic libuv.so or libuv.dyld by default.

2. spawn_reads_child_path spawns a new instance of the test runner
   by consulting uv_exepath() and executing the result.

3. `test/run-tests` is normally a shell script that sets up
   DYLD_LIBRARY_PATH or LD_LIBRARY_PATH before executing the
   real test runner in `test/.libs`.

4. uv_exepath() (corectly) returns the path of the binary in
   `test/.libs`.  The binary is linked against libuv.so but that
   library is not on any of the default linker paths; and if it is,
   it's almost certainly the wrong version.

5. Ergo, carry over the value of the (DY)LD_LIBRARY_PATH environment
   variable into the environment of the child process so that the
   dynamic linker knows where to find the library.

Alternatively, we could link the test runner statically against libuv.a
but that breaks `make check` when configured with `--disable-static`.

Fixes: https://github.com/libuv/libuv/issues/85
PR-URL: https://github.com/libuv/libuv/pull/91
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
Ben Noordhuis 2014-12-28 18:14:34 +01:00
parent c71e7b753c
commit 9141f48ea5

View File

@ -1300,7 +1300,16 @@ TEST_IMPL(spawn_reads_child_path) {
int len;
char file[64];
char path[1024];
char *env[2] = {path, NULL};
char* env[3];
/* Need to carry over the dynamic linker path when the test runner is
* linked against libuv.so, see https://github.com/libuv/libuv/issues/85.
*/
#if defined(__APPLE__)
static const char dyld_path_var[] = "DYLD_LIBRARY_PATH";
#else
static const char dyld_path_var[] = "LD_LIBRARY_PATH";
#endif
/* Set up the process, but make sure that the file to run is relative and */
/* requires a lookup into PATH */
@ -1315,6 +1324,16 @@ TEST_IMPL(spawn_reads_child_path) {
strcpy(path, "PATH=");
strcpy(path + 5, exepath);
env[0] = path;
env[1] = getenv(dyld_path_var);
env[2] = NULL;
if (env[1] != NULL) {
static char buf[1024 + sizeof(dyld_path_var)];
snprintf(buf, sizeof(buf), "%s=%s", dyld_path_var, env[1]);
env[1] = buf;
}
options.file = file;
options.args[0] = file;
options.env = env;