test: add valgrind support
Run tests through valgrind when UV_USE_VALGRIND=1 is set in the environment.
This commit is contained in:
parent
48f98424bd
commit
4e268f7718
@ -55,8 +55,13 @@ void platform_init(int argc, char **argv) {
|
||||
|
||||
/* Invoke "argv[0] test-name [test-part]". Store process info in *p. */
|
||||
/* Make sure that all stdio output of the processes is buffered up. */
|
||||
int process_start(char* name, char* part, process_info_t* p) {
|
||||
FILE* stdout_file = tmpfile();
|
||||
int process_start(char* name, char* part, process_info_t* p, int is_helper) {
|
||||
FILE* stdout_file;
|
||||
const char* arg;
|
||||
char* args[16];
|
||||
int n;
|
||||
|
||||
stdout_file = tmpfile();
|
||||
if (!stdout_file) {
|
||||
perror("tmpfile");
|
||||
return -1;
|
||||
@ -74,11 +79,28 @@ int process_start(char* name, char* part, process_info_t* p) {
|
||||
|
||||
if (pid == 0) {
|
||||
/* child */
|
||||
arg = getenv("UV_USE_VALGRIND");
|
||||
n = 0;
|
||||
|
||||
/* Disable valgrind for helpers, it complains about helpers leaking memory.
|
||||
* They're killed after the test and as such never get a chance to clean up.
|
||||
*/
|
||||
if (is_helper == 0 && arg != NULL && atoi(arg) != 0) {
|
||||
args[n++] = "valgrind";
|
||||
args[n++] = "--quiet";
|
||||
args[n++] = "--leak-check=full";
|
||||
args[n++] = "--show-reachable=yes";
|
||||
args[n++] = "--error-exitcode=125";
|
||||
}
|
||||
|
||||
args[n++] = executable_path;
|
||||
args[n++] = name;
|
||||
args[n++] = part;
|
||||
args[n++] = NULL;
|
||||
|
||||
dup2(fileno(stdout_file), STDOUT_FILENO);
|
||||
dup2(fileno(stdout_file), STDERR_FILENO);
|
||||
|
||||
char* args[] = { executable_path, name, part, NULL };
|
||||
execvp(executable_path, args);
|
||||
execvp(args[0], args);
|
||||
perror("execvp()");
|
||||
_exit(127);
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ void platform_init(int argc, char **argv) {
|
||||
}
|
||||
|
||||
|
||||
int process_start(char *name, char *part, process_info_t *p) {
|
||||
int process_start(char *name, char *part, process_info_t *p, int is_helper) {
|
||||
HANDLE file = INVALID_HANDLE_VALUE;
|
||||
HANDLE nul = INVALID_HANDLE_VALUE;
|
||||
WCHAR path[MAX_PATH], filename[MAX_PATH];
|
||||
|
||||
@ -147,7 +147,8 @@ int run_test(const char* test, int timeout, int benchmark_output) {
|
||||
|
||||
if (process_start(task->task_name,
|
||||
task->process_name,
|
||||
&processes[process_count]) == -1) {
|
||||
&processes[process_count],
|
||||
1 /* is_helper */) == -1) {
|
||||
snprintf(errmsg,
|
||||
sizeof errmsg,
|
||||
"Process `%s` failed to start.",
|
||||
@ -173,7 +174,8 @@ int run_test(const char* test, int timeout, int benchmark_output) {
|
||||
|
||||
if (process_start(task->task_name,
|
||||
task->process_name,
|
||||
&processes[process_count]) == -1) {
|
||||
&processes[process_count],
|
||||
0 /* !is_helper */) == -1) {
|
||||
snprintf(errmsg,
|
||||
sizeof errmsg,
|
||||
"Process `%s` failed to start.",
|
||||
|
||||
@ -127,7 +127,7 @@ void platform_init();
|
||||
|
||||
/* Invoke "argv[0] test-name [test-part]". Store process info in *p. */
|
||||
/* Make sure that all stdio output of the processes is buffered up. */
|
||||
int process_start(char *name, char* part, process_info_t *p);
|
||||
int process_start(char *name, char* part, process_info_t *p, int is_helper);
|
||||
|
||||
/* Wait for all `n` processes in `vec` to terminate. */
|
||||
/* Time out after `timeout` msec, or never if timeout == -1 */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user