test: canonicalize test runner path
The get_currentexe test requires a canonicalized argv[0] to check against. Before this commit, it failed when argv[0] contained symbolic links. Fixes libuv/libuv#18.
This commit is contained in:
parent
3aeca36a1b
commit
ff29322b99
@ -33,7 +33,8 @@ static int maybe_run_test(int argc, char **argv);
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
platform_init(argc, argv);
|
if (platform_init(argc, argv))
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
switch (argc) {
|
switch (argc) {
|
||||||
case 1: return run_tests(1);
|
case 1: return run_tests(1);
|
||||||
@ -41,8 +42,10 @@ int main(int argc, char **argv) {
|
|||||||
case 3: return run_test_part(argv[1], argv[2]);
|
case 3: return run_test_part(argv[1], argv[2]);
|
||||||
default:
|
default:
|
||||||
LOGF("Too many arguments.\n");
|
LOGF("Too many arguments.\n");
|
||||||
return 1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -46,7 +46,8 @@ static int maybe_run_test(int argc, char **argv);
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
platform_init(argc, argv);
|
if (platform_init(argc, argv))
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
argv = uv_setup_args(argc, argv);
|
argv = uv_setup_args(argc, argv);
|
||||||
|
|
||||||
@ -56,8 +57,10 @@ int main(int argc, char **argv) {
|
|||||||
case 3: return run_test_part(argv[1], argv[2]);
|
case 3: return run_test_part(argv[1], argv[2]);
|
||||||
default:
|
default:
|
||||||
LOGF("Too many arguments.\n");
|
LOGF("Too many arguments.\n");
|
||||||
return 1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -22,10 +22,11 @@
|
|||||||
#include "runner-unix.h"
|
#include "runner-unix.h"
|
||||||
#include "runner.h"
|
#include "runner.h"
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
#include <stdint.h> /* uintptr_t */
|
#include <stdint.h> /* uintptr_t */
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h> /* usleep */
|
#include <unistd.h> /* readlink, usleep */
|
||||||
#include <string.h> /* strdup */
|
#include <string.h> /* strdup */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -40,8 +41,9 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Do platform-specific initialization. */
|
/* Do platform-specific initialization. */
|
||||||
void platform_init(int argc, char **argv) {
|
int platform_init(int argc, char **argv) {
|
||||||
const char* tap;
|
const char* tap;
|
||||||
|
ssize_t n;
|
||||||
|
|
||||||
tap = getenv("UV_TAP_OUTPUT");
|
tap = getenv("UV_TAP_OUTPUT");
|
||||||
tap_output = (tap != NULL && atoi(tap) > 0);
|
tap_output = (tap != NULL && atoi(tap) > 0);
|
||||||
@ -49,8 +51,14 @@ void platform_init(int argc, char **argv) {
|
|||||||
/* Disable stdio output buffering. */
|
/* Disable stdio output buffering. */
|
||||||
setvbuf(stdout, NULL, _IONBF, 0);
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
setvbuf(stderr, NULL, _IONBF, 0);
|
setvbuf(stderr, NULL, _IONBF, 0);
|
||||||
strncpy(executable_path, argv[0], sizeof(executable_path) - 1);
|
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
|
if (realpath(argv[0], executable_path) == NULL) {
|
||||||
|
perror("realpath");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Do platform-specific initialization. */
|
/* Do platform-specific initialization. */
|
||||||
void platform_init(int argc, char **argv) {
|
int platform_init(int argc, char **argv) {
|
||||||
const char* tap;
|
const char* tap;
|
||||||
|
|
||||||
tap = getenv("UV_TAP_OUTPUT");
|
tap = getenv("UV_TAP_OUTPUT");
|
||||||
@ -66,6 +66,8 @@ void platform_init(int argc, char **argv) {
|
|||||||
setvbuf(stderr, NULL, _IONBF, 0);
|
setvbuf(stderr, NULL, _IONBF, 0);
|
||||||
|
|
||||||
strcpy(executable_path, argv[0]);
|
strcpy(executable_path, argv[0]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@
|
|||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "uv.h"
|
#include "uv.h"
|
||||||
|
|
||||||
char executable_path[PATHMAX] = { '\0' };
|
char executable_path[sizeof(executable_path)];
|
||||||
|
|
||||||
int tap_output = 0;
|
int tap_output = 0;
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
#ifndef RUNNER_H_
|
#ifndef RUNNER_H_
|
||||||
#define RUNNER_H_
|
#define RUNNER_H_
|
||||||
|
|
||||||
|
#include <limits.h> /* PATH_MAX */
|
||||||
#include <stdio.h> /* FILE */
|
#include <stdio.h> /* FILE */
|
||||||
|
|
||||||
|
|
||||||
@ -83,8 +84,11 @@ typedef struct {
|
|||||||
#define TEST_HELPER HELPER_ENTRY
|
#define TEST_HELPER HELPER_ENTRY
|
||||||
#define BENCHMARK_HELPER HELPER_ENTRY
|
#define BENCHMARK_HELPER HELPER_ENTRY
|
||||||
|
|
||||||
#define PATHMAX 1024
|
#ifdef PATH_MAX
|
||||||
extern char executable_path[PATHMAX];
|
extern char executable_path[PATH_MAX];
|
||||||
|
#else
|
||||||
|
extern char executable_path[4096];
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Include platform-dependent definitions
|
* Include platform-dependent definitions
|
||||||
@ -130,7 +134,7 @@ void print_tests(FILE* stream);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Do platform-specific initialization. */
|
/* Do platform-specific initialization. */
|
||||||
void platform_init(int argc, char** argv);
|
int platform_init(int argc, char** argv);
|
||||||
|
|
||||||
/* Invoke "argv[0] test-name [test-part]". Store process info in *p. */
|
/* Invoke "argv[0] test-name [test-part]". Store process info in *p. */
|
||||||
/* Make sure that all stdio output of the processes is buffered up. */
|
/* Make sure that all stdio output of the processes is buffered up. */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user