test: canonicalize argv[0] in exepath test

Commit ff29322b ("test: canonicalize test runner path") from 2014
changed the test runner to call `realpath(3)` on `argv[0]` in order
to fix the `get_currentexe` test failing with the autotools build when
the executable path contained symbolic links but that is now causing
the `spawn_reads_child_path` test to fail on z/os with the cmake build.

Fix that by only doing path canonicalization in the `get_currentexe`
test, not always.

An auxiliary fix is applied to the `process_title_threadsafe` test
because it assumed that setting the process title to a long string,
then reading it back produces in the original string.

On some platforms however the maximum size of the process title is
limited to the size of the `argv` vector.

Because the test runner used absolute paths until now, the argv vector
was bigger than it is with relative paths, big enough to let this bad
assumption go unnoticed until now.

Minor fixes are applied to tests that assumed 1024 for the maximum
path size because this commit makes visible that some of the CI matrix
systems support much longer paths.

PR-URL: https://github.com/libuv/libuv/pull/2755
Refs: https://github.com/libuv/libuv/pull/2737#issuecomment-602800431
Refs: https://github.com/libuv/libuv/pull/2754#issuecomment-604015785
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
This commit is contained in:
Ben Noordhuis 2020-03-27 23:37:51 +01:00
parent 87cbf546d8
commit fa1da18549
8 changed files with 30 additions and 29 deletions

View File

@ -26,7 +26,7 @@
#include <stdint.h> /* uintptr_t */
#include <errno.h>
#include <unistd.h> /* readlink, usleep */
#include <unistd.h> /* usleep */
#include <string.h> /* strdup */
#include <stdio.h>
#include <stdlib.h>
@ -72,12 +72,7 @@ int platform_init(int argc, char **argv) {
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
signal(SIGPIPE, SIG_IGN);
if (realpath(argv[0], executable_path) == NULL) {
perror("realpath");
return -1;
}
snprintf(executable_path, sizeof(executable_path), "%s", argv[0]);
return 0;
}

View File

@ -84,11 +84,7 @@ typedef struct {
#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
/*
* Include platform-dependent definitions

View File

@ -23,7 +23,7 @@
#include "task.h"
#include <string.h>
#define PATHMAX 1024
#define PATHMAX 4096
TEST_IMPL(cwd_and_chdir) {
char buffer_orig[PATHMAX];

View File

@ -55,7 +55,7 @@
#endif
#define TOO_LONG_NAME_LENGTH 65536
#define PATHMAX 1024
#define PATHMAX 4096
typedef struct {
const char* path;

View File

@ -23,28 +23,29 @@
#include "task.h"
#include <string.h>
#define PATHMAX 1024
#ifndef _WIN32
#include <unistd.h>
#endif
#define PATHMAX 4096
extern char executable_path[];
TEST_IMPL(get_currentexe) {
char buffer[PATHMAX];
char path[PATHMAX];
size_t size;
char* match;
char* path;
int r;
size = sizeof(buffer) / sizeof(buffer[0]);
r = uv_exepath(buffer, &size);
ASSERT(!r);
/* uv_exepath can return an absolute path on darwin, so if the test runner
* was run with a relative prefix of "./", we need to strip that prefix off
* executable_path or we'll fail. */
if (executable_path[0] == '.' && executable_path[1] == '/') {
path = executable_path + 2;
} else {
path = executable_path;
}
#ifdef _WIN32
snprintf(path, sizeof(path), "%s", executable_path);
#else
ASSERT(NULL != realpath(executable_path, path));
#endif
match = strstr(buffer, path);
/* Verify that the path returned from uv_exepath is a subdirectory of

View File

@ -23,7 +23,7 @@
#include "task.h"
#include <string.h>
#define PATHMAX 1024
#define PATHMAX 4096
#define SMALLPATH 1
TEST_IMPL(homedir) {

View File

@ -40,14 +40,23 @@ static const char* titles[] = {
static void getter_thread_body(void* arg) {
char buffer[512];
size_t len;
for (;;) {
ASSERT(0 == uv_get_process_title(buffer, sizeof(buffer)));
/* The maximum size of the process title on some platforms depends on
* the total size of the argv vector. It's therefore possible to read
* back a title that's shorter than what we submitted.
*/
len = strlen(buffer);
ASSERT_GT(len, 0);
ASSERT(
0 == strcmp(buffer, titles[0]) ||
0 == strcmp(buffer, titles[1]) ||
0 == strcmp(buffer, titles[2]) ||
0 == strcmp(buffer, titles[3]));
0 == strncmp(buffer, titles[0], len) ||
0 == strncmp(buffer, titles[1], len) ||
0 == strncmp(buffer, titles[2], len) ||
0 == strncmp(buffer, titles[3], len));
uv_sleep(0);
}

View File

@ -23,7 +23,7 @@
#include "task.h"
#include <string.h>
#define PATHMAX 1024
#define PATHMAX 4096
#define SMALLPATH 1
TEST_IMPL(tmpdir) {