[gcov][test] Simplify instrprof-dlopen-dlclose-gcov.test

This commit is contained in:
Fangrui Song 2020-07-11 17:17:21 -07:00
parent 13ae440de4
commit 6a25838be6
7 changed files with 82 additions and 233 deletions

View File

@ -1,91 +0,0 @@
// CHECK: -: 0:Source:{{.*}}Inputs/instrprof-dlopen-dlclose-main.c
// CHECK-NEXT: -: 0:Graph:instrprof-dlopen-dlclose-main.gcno
// CHECK-NEXT: -: 0:Data:instrprof-dlopen-dlclose-main.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: -: 1:#include <dlfcn.h>
// CHECK-NEXT: -: 2:#include <stdio.h>
// CHECK-NEXT: -: 3:#include <stdlib.h>
// CHECK-NEXT: -: 4:
// CHECK-NEXT: 1: 5:int main(int argc, char *argv[]) {
// CHECK-NEXT: 1: 6: dlerror();
// CHECK-NEXT: 1: 7: void *f1_handle = dlopen("func.shared", RTLD_LAZY | RTLD_GLOBAL);
// CHECK-NEXT: 1: 8: if (f1_handle == NULL) {
// CHECK-NEXT: #####: 9: fprintf(stderr, "unable to open 'func.shared': %s\n", dlerror());
// CHECK-NEXT: #####: 10: return EXIT_FAILURE;
// CHECK-NEXT: -: 11: }
// CHECK-NEXT: -: 12:
// CHECK-NEXT: 1: 13: void (*func)(void) = (void (*)(void))dlsym(f1_handle, "func");
// CHECK-NEXT: 1: 14: if (func == NULL) {
// CHECK-NEXT: #####: 15: fprintf(stderr, "unable to lookup symbol 'func': %s\n", dlerror());
// CHECK-NEXT: #####: 16: return EXIT_FAILURE;
// CHECK-NEXT: -: 17: }
// CHECK-NEXT: -: 18:
// CHECK-NEXT: 1: 19: dlerror();
// CHECK-NEXT: 1: 20: void *f2_handle = dlopen("func2.shared", RTLD_LAZY | RTLD_GLOBAL);
// CHECK-NEXT: 1: 21: if (f2_handle == NULL) {
// CHECK-NEXT: #####: 22: fprintf(stderr, "unable to open 'func2.shared': %s\n", dlerror());
// CHECK-NEXT: #####: 23: return EXIT_FAILURE;
// CHECK-NEXT: -: 24: }
// CHECK-NEXT: -: 25:
// CHECK-NEXT: 1: 26: void (*func2)(void) = (void (*)(void))dlsym(f2_handle, "func2");
// CHECK-NEXT: 1: 27: if (func2 == NULL) {
// CHECK-NEXT: #####: 28: fprintf(stderr, "unable to lookup symbol 'func2': %s\n", dlerror());
// CHECK-NEXT: #####: 29: return EXIT_FAILURE;
// CHECK-NEXT: -: 30: }
// CHECK-NEXT: 1: 31: func2();
// CHECK-NEXT: -: 32:
// CHECK-NEXT: -: 33:#ifdef USE_LIB3
// CHECK-NEXT: -: 34: void *f3_handle = dlopen("func3.shared", RTLD_LAZY | RTLD_GLOBAL);
// CHECK-NEXT: -: 35: if (f3_handle == NULL) {
// CHECK-NEXT: -: 36: fprintf(stderr, "unable to open 'func3.shared': %s\n", dlerror());
// CHECK-NEXT: -: 37: return EXIT_FAILURE;
// CHECK-NEXT: -: 38: }
// CHECK-NEXT: -: 39:
// CHECK-NEXT: -: 40: void (*func3)(void) = (void (*)(void))dlsym(f3_handle, "func3");
// CHECK-NEXT: -: 41: if (func3 == NULL) {
// CHECK-NEXT: -: 42: fprintf(stderr, "unable to lookup symbol 'func3': %s\n", dlerror());
// CHECK-NEXT: -: 43: return EXIT_FAILURE;
// CHECK-NEXT: -: 44: }
// CHECK-NEXT: -: 45: func3();
// CHECK-NEXT: -: 46:#endif
// CHECK-NEXT: -: 47:
// CHECK-NEXT: 1: 48: dlerror();
// CHECK-NEXT: 1: 49: void (*gcov_flush1)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
// CHECK-NEXT: 1: 50: if (gcov_flush1 == NULL) {
// CHECK-NEXT: #####: 51: fprintf(stderr, "unable to find __gcov_flush in func.shared': %s\n", dlerror());
// CHECK-NEXT: #####: 52: return EXIT_FAILURE;
// CHECK-NEXT: -: 53: }
// CHECK-NEXT: -: 54:
// CHECK-NEXT: 1: 55: dlerror();
// CHECK-NEXT: 1: 56: void (*gcov_flush2)() = (void (*)())dlsym(f2_handle, "__gcov_flush");
// CHECK-NEXT: 1: 57: if (gcov_flush2 == NULL) {
// CHECK-NEXT: #####: 58: fprintf(stderr, "unable to find __gcov_flush in func2.shared': %s\n", dlerror());
// CHECK-NEXT: #####: 59: return EXIT_FAILURE;
// CHECK-NEXT: -: 60: }
// CHECK-NEXT: -: 61:
// CHECK-NEXT: 1: 62: if (gcov_flush1 == gcov_flush2) {
// CHECK-NEXT: #####: 63: fprintf(stderr, "Same __gcov_flush found in func.shared and func2.shared\n");
// CHECK-NEXT: #####: 64: return EXIT_FAILURE;
// CHECK-NEXT: -: 65: }
// CHECK-NEXT: -: 66:
// CHECK-NEXT: 1: 67: dlerror();
// CHECK-NEXT: 1: 68: if (dlclose(f2_handle) != 0) {
// CHECK-NEXT: #####: 69: fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
// CHECK-NEXT: #####: 70: return EXIT_FAILURE;
// CHECK-NEXT: -: 71: }
// CHECK-NEXT: -: 72:
// CHECK-NEXT: 1: 73: func();
// CHECK-NEXT: -: 74:
// CHECK-NEXT: 1: 75: int g1 = 0;
// CHECK-NEXT: 1: 76: int g2 = 0;
// CHECK-NEXT: 1: 77: int n = 10;
// CHECK-NEXT: -: 78:
// CHECK-NEXT: 1: 79: if (n % 5 == 0)
// CHECK-NEXT: 1: 80: g1++;
// CHECK-NEXT: -: 81: else
// CHECK-NEXT: #####: 82: g2++;
// CHECK-NEXT: -: 83:
// CHECK-NEXT: 1: 84: return EXIT_SUCCESS;
// CHECK-NEXT: 1: 85:}
// CHECK-NEXT: -: 86:

View File

@ -1,91 +0,0 @@
// CHECK: -: 0:Source:{{.*}}Inputs/instrprof-dlopen-dlclose-main.c
// CHECK-NEXT: -: 0:Graph:instrprof-dlopen-dlclose-main.gcno
// CHECK-NEXT: -: 0:Data:instrprof-dlopen-dlclose-main.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: -: 1:#include <dlfcn.h>
// CHECK-NEXT: -: 2:#include <stdio.h>
// CHECK-NEXT: -: 3:#include <stdlib.h>
// CHECK-NEXT: -: 4:
// CHECK-NEXT: 1: 5:int main(int argc, char *argv[]) {
// CHECK-NEXT: 1: 6: dlerror();
// CHECK-NEXT: 1: 7: void *f1_handle = dlopen("func.shared", RTLD_LAZY | RTLD_GLOBAL);
// CHECK-NEXT: 1: 8: if (f1_handle == NULL) {
// CHECK-NEXT: #####: 9: fprintf(stderr, "unable to open 'func.shared': %s\n", dlerror());
// CHECK-NEXT: #####: 10: return EXIT_FAILURE;
// CHECK-NEXT: -: 11: }
// CHECK-NEXT: -: 12:
// CHECK-NEXT: 1: 13: void (*func)(void) = (void (*)(void))dlsym(f1_handle, "func");
// CHECK-NEXT: 1: 14: if (func == NULL) {
// CHECK-NEXT: #####: 15: fprintf(stderr, "unable to lookup symbol 'func': %s\n", dlerror());
// CHECK-NEXT: #####: 16: return EXIT_FAILURE;
// CHECK-NEXT: -: 17: }
// CHECK-NEXT: -: 18:
// CHECK-NEXT: 1: 19: dlerror();
// CHECK-NEXT: 1: 20: void *f2_handle = dlopen("func2.shared", RTLD_LAZY | RTLD_GLOBAL);
// CHECK-NEXT: 1: 21: if (f2_handle == NULL) {
// CHECK-NEXT: #####: 22: fprintf(stderr, "unable to open 'func2.shared': %s\n", dlerror());
// CHECK-NEXT: #####: 23: return EXIT_FAILURE;
// CHECK-NEXT: -: 24: }
// CHECK-NEXT: -: 25:
// CHECK-NEXT: 1: 26: void (*func2)(void) = (void (*)(void))dlsym(f2_handle, "func2");
// CHECK-NEXT: 1: 27: if (func2 == NULL) {
// CHECK-NEXT: #####: 28: fprintf(stderr, "unable to lookup symbol 'func2': %s\n", dlerror());
// CHECK-NEXT: #####: 29: return EXIT_FAILURE;
// CHECK-NEXT: -: 30: }
// CHECK-NEXT: 1: 31: func2();
// CHECK-NEXT: -: 32:
// CHECK-NEXT: -: 33:#ifdef USE_LIB3
// CHECK-NEXT: 1: 34: void *f3_handle = dlopen("func3.shared", RTLD_LAZY | RTLD_GLOBAL);
// CHECK-NEXT: 1: 35: if (f3_handle == NULL) {
// CHECK-NEXT: #####: 36: fprintf(stderr, "unable to open 'func3.shared': %s\n", dlerror());
// CHECK-NEXT: #####: 37: return EXIT_FAILURE;
// CHECK-NEXT: -: 38: }
// CHECK-NEXT: -: 39:
// CHECK-NEXT: 1: 40: void (*func3)(void) = (void (*)(void))dlsym(f3_handle, "func3");
// CHECK-NEXT: 1: 41: if (func3 == NULL) {
// CHECK-NEXT: #####: 42: fprintf(stderr, "unable to lookup symbol 'func3': %s\n", dlerror());
// CHECK-NEXT: #####: 43: return EXIT_FAILURE;
// CHECK-NEXT: -: 44: }
// CHECK-NEXT: 1: 45: func3();
// CHECK-NEXT: -: 46:#endif
// CHECK-NEXT: -: 47:
// CHECK-NEXT: 1: 48: dlerror();
// CHECK-NEXT: 1: 49: void (*gcov_flush1)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
// CHECK-NEXT: 1: 50: if (gcov_flush1 == NULL) {
// CHECK-NEXT: #####: 51: fprintf(stderr, "unable to find __gcov_flush in func.shared': %s\n", dlerror());
// CHECK-NEXT: #####: 52: return EXIT_FAILURE;
// CHECK-NEXT: -: 53: }
// CHECK-NEXT: -: 54:
// CHECK-NEXT: 1: 55: dlerror();
// CHECK-NEXT: 1: 56: void (*gcov_flush2)() = (void (*)())dlsym(f2_handle, "__gcov_flush");
// CHECK-NEXT: 1: 57: if (gcov_flush2 == NULL) {
// CHECK-NEXT: #####: 58: fprintf(stderr, "unable to find __gcov_flush in func2.shared': %s\n", dlerror());
// CHECK-NEXT: #####: 59: return EXIT_FAILURE;
// CHECK-NEXT: -: 60: }
// CHECK-NEXT: -: 61:
// CHECK-NEXT: 1: 62: if (gcov_flush1 == gcov_flush2) {
// CHECK-NEXT: #####: 63: fprintf(stderr, "Same __gcov_flush found in func.shared and func2.shared\n");
// CHECK-NEXT: #####: 64: return EXIT_FAILURE;
// CHECK-NEXT: -: 65: }
// CHECK-NEXT: -: 66:
// CHECK-NEXT: 1: 67: dlerror();
// CHECK-NEXT: 1: 68: if (dlclose(f2_handle) != 0) {
// CHECK-NEXT: #####: 69: fprintf(stderr, "unable to close 'func2.shared': %s\n", dlerror());
// CHECK-NEXT: #####: 70: return EXIT_FAILURE;
// CHECK-NEXT: -: 71: }
// CHECK-NEXT: -: 72:
// CHECK-NEXT: 1: 73: func();
// CHECK-NEXT: -: 74:
// CHECK-NEXT: 1: 75: int g1 = 0;
// CHECK-NEXT: 1: 76: int g2 = 0;
// CHECK-NEXT: 1: 77: int n = 10;
// CHECK-NEXT: -: 78:
// CHECK-NEXT: 1: 79: if (n % 5 == 0)
// CHECK-NEXT: 1: 80: g1++;
// CHECK-NEXT: -: 81: else
// CHECK-NEXT: #####: 82: g2++;
// CHECK-NEXT: -: 83:
// CHECK-NEXT: 1: 84: return EXIT_SUCCESS;
// CHECK-NEXT: 1: 85:}
// CHECK-NEXT: -: 86:

View File

@ -1,6 +0,0 @@
// CHECK: -: 0:Source:{{.*}}Inputs/instrprof-dlopen-func.c
// CHECK-NEXT: -: 0:Graph:instrprof-dlopen-func.gcno
// CHECK-NEXT: -: 0:Data:instrprof-dlopen-func.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: 1: 1:void func(int K) {}

View File

@ -1,6 +0,0 @@
// CHECK: -: 0:Source:{{.*}}Inputs/instrprof-dlopen-func2.c
// CHECK-NEXT: -: 0:Graph:instrprof-dlopen-func2.gcno
// CHECK-NEXT: -: 0:Data:instrprof-dlopen-func2.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: 1: 1:void func2(int K) {}

View File

@ -1,6 +0,0 @@
// CHECK: -: 0:Source:{{.*}}Inputs/instrprof-dlopen-func2.c
// CHECK-NEXT: -: 0:Graph:instrprof-dlopen-func2.gcno
// CHECK-NEXT: -: 0:Data:instrprof-dlopen-func2.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: 1: 1:void func2(int K) {}

View File

@ -0,0 +1,82 @@
/// atexit(3) not supported in dlopen(3)ed+dlclose(3)d DSO
// XFAIL: netbsd
// RUN: mkdir -p %t.d && cd %t.d
// RUN: echo 'void func1(int k) {}' > func1.c
// RUN: echo 'void func2(int k) {}' > func2.c
// RUN: echo 'void func3(int k) {}' > func3.c
// RUN: %clang --coverage -fPIC -shared func1.c -o func1.so
// RUN: %clang --coverage -fPIC -shared func2.c -o func2.so
// RUN: %clang --coverage -fPIC -shared func3.c -o func3.so
// RUN: %clang --coverage -fPIC -rpath %t.d %s -o %t
/// Test with two dlopened libraries.
// RUN: rm -f gcov-dlopen.gcda func1.gcda func2.gcda
// RUN: %run %t
// RUN: llvm-cov gcov -t gcov-dlopen.gcda | FileCheck %s
// RUN: llvm-cov gcov -t func1.gcda | FileCheck %s --check-prefix=FUNC1
// RUN: llvm-cov gcov -t func2.gcda | FileCheck %s --check-prefix=FUNC2
// FUNC1: 1: 1:void func1(int k) {}
// FUNC2: 1: 1:void func2(int k) {}
/// Test with three dlopened libraries.
// RUN: %clang -DUSE_LIB3 --coverage -fPIC -rpath %t.d %s -o %t
// RUN: rm -f gcov-dlopen.gcda func1.gcda func2.gcda func3.gcda
// RUN: %run %t
// RUN: llvm-cov gcov -t gcov-dlopen.gcda | FileCheck %s --check-prefix=LIB3
// RUN: llvm-cov gcov -t func1.gcda | FileCheck %s --check-prefix=FUNC1
// RUN: llvm-cov gcov -t func2.gcda | FileCheck %s --check-prefix=FUNC2
// RUN: llvm-cov gcov -t func3.gcda | FileCheck %s --check-prefix=FUNC3
// FUNC3: 1: 1:void func3(int k) {}
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
void *f1_handle = dlopen("func1.so", RTLD_LAZY | RTLD_GLOBAL);
if (f1_handle == NULL)
return fprintf(stderr, "unable to open 'func1.so': %s\n", dlerror());
void (*func1)(void) = (void (*)(void))dlsym(f1_handle, "func1");
if (func1 == NULL)
return fprintf(stderr, "unable to lookup symbol 'func1': %s\n", dlerror());
void *f2_handle = dlopen("func2.so", RTLD_LAZY | RTLD_GLOBAL);
if (f2_handle == NULL)
return fprintf(stderr, "unable to open 'func2.so': %s\n", dlerror());
void (*func2)(void) = (void (*)(void))dlsym(f2_handle, "func2");
if (func2 == NULL)
return fprintf(stderr, "unable to lookup symbol 'func2': %s\n", dlerror());
func2();
#ifdef USE_LIB3
// CHECK: -: [[#@LINE+2]]: void *f3_handle
// LIB3: 1: [[#@LINE+1]]: void *f3_handle
void *f3_handle = dlopen("func3.so", RTLD_LAZY | RTLD_GLOBAL);
if (f3_handle == NULL)
return fprintf(stderr, "unable to open 'func3.so': %s\n", dlerror());
void (*func3)(void) = (void (*)(void))dlsym(f3_handle, "func3");
if (func3 == NULL)
return fprintf(stderr, "unable to lookup symbol 'func3': %s\n", dlerror());
func3();
#endif
void (*gcov_flush1)() = (void (*)())dlsym(f1_handle, "__gcov_flush");
if (gcov_flush1 == NULL)
return fprintf(stderr, "unable to find __gcov_flush in func1.so': %s\n", dlerror());
void (*gcov_flush2)() = (void (*)())dlsym(f2_handle, "__gcov_flush");
if (gcov_flush2 == NULL)
return fprintf(stderr, "unable to find __gcov_flush in func2.so': %s\n", dlerror());
if (gcov_flush1 == gcov_flush2)
return fprintf(stderr, "same __gcov_flush found in func1.so and func2.so\n");
if (dlclose(f2_handle) != 0)
return fprintf(stderr, "unable to close 'func2.so': %s\n", dlerror());
func1();
return 0;
}

View File

@ -1,33 +0,0 @@
# atexit(3) not supported in dlopen(3)ed+dlclose(3)d DSO
XFAIL: netbsd
RUN: mkdir -p %t.d
RUN: cd %t.d
RUN: %clang --coverage -o func.shared -fPIC -shared %S/../Inputs/instrprof-dlopen-func.c
RUN: %clang --coverage -o func2.shared -fPIC -shared %S/../Inputs/instrprof-dlopen-func2.c
RUN: %clang --coverage -o func3.shared -fPIC -shared %S/../Inputs/instrprof-dlopen-func3.c
RUN: %clang --coverage -o %t -fPIC -rpath %t.d %S/../Inputs/instrprof-dlopen-dlclose-main.c
# Test with two dlopened libraries.
RUN: rm -f instrprof-dlopen-dlclose-main.gcda instrprof-dlopen-func.gcda instrprof-dlopen-func2.gcda
RUN: %run %t
RUN: llvm-cov gcov instrprof-dlopen-dlclose-main.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-dlopen-dlclose-main.c.gcov %S/../Inputs/instrprof-dlopen-dlclose-main.c.gcov
RUN: llvm-cov gcov instrprof-dlopen-func.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-dlopen-func.c.gcov %S/../Inputs/instrprof-dlopen-func.c.gcov
RUN: llvm-cov gcov instrprof-dlopen-func2.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-dlopen-func2.c.gcov %S/../Inputs/instrprof-dlopen-func2.c.gcov
# Test with three dlopened libraries.
RUN: %clang -DUSE_LIB3 --coverage -o %t -fPIC -rpath %t.d %S/../Inputs/instrprof-dlopen-dlclose-main.c
RUN: rm -f instrprof-dlopen-dlclose-main.gcda instrprof-dlopen-func.gcda instrprof-dlopen-func2.gcda instrprof-dlopen-func3.gcda
RUN: %run %t
RUN: llvm-cov gcov instrprof-dlopen-dlclose-main.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-dlopen-dlclose-main.c.gcov %S/../Inputs/instrprof-dlopen-dlclose-main_three-libs.c.gcov
RUN: llvm-cov gcov instrprof-dlopen-func.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-dlopen-func.c.gcov %S/../Inputs/instrprof-dlopen-func.c.gcov
RUN: llvm-cov gcov instrprof-dlopen-func2.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-dlopen-func2.c.gcov %S/../Inputs/instrprof-dlopen-func2.c.gcov
RUN: llvm-cov gcov instrprof-dlopen-func3.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-dlopen-func2.c.gcov %S/../Inputs/instrprof-dlopen-func3.c.gcov