[gcov][test] Reorganize some compiler-rt/test/profile tests

This commit is contained in:
Fangrui Song 2020-07-03 16:17:06 -07:00
parent aa5ec34e31
commit fba8523fb5
25 changed files with 194 additions and 498 deletions

View File

@ -1,18 +0,0 @@
extern void __gcov_flush();
extern int remove(const char *);
int main(void) {
__gcov_flush();
if (remove("instrprof-gcov-__gcov_flush-multiple.gcda") != 0) {
return 1;
}
__gcov_flush();
__gcov_flush();
if (remove("instrprof-gcov-__gcov_flush-multiple.gcda") != 0) {
return 1;
}
return 0;
}

View File

@ -1,23 +0,0 @@
// CHECK: -: 0:Source:{{.*}}Inputs{{[/\\]}}instrprof-gcov-__gcov_flush-multiple.c
// CHECK-NEXT: -: 0:Graph:instrprof-gcov-__gcov_flush-multiple.gcno
// CHECK-NEXT: -: 0:Data:instrprof-gcov-__gcov_flush-multiple.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: -: 1:extern void __gcov_flush();
// CHECK-NEXT: -: 2:extern int remove(const char *);
// CHECK-NEXT: #####: 3:int main(void) {
// CHECK-NEXT: #####: 4: __gcov_flush();
// CHECK-NEXT: -: 5:
// CHECK-NEXT: #####: 6: if (remove("instrprof-gcov-__gcov_flush-multiple.gcda") != 0) {
// CHECK-NEXT: #####: 7: return 1;
// CHECK-NEXT: -: 8: }
// CHECK-NEXT: -: 9:
// CHECK-NEXT: #####: 10: __gcov_flush();
// CHECK-NEXT: #####: 11: __gcov_flush();
// CHECK-NEXT: -: 12:
// CHECK-NEXT: #####: 13: if (remove("instrprof-gcov-__gcov_flush-multiple.gcda") != 0) {
// CHECK-NEXT: #####: 14: return 1;
// CHECK-NEXT: -: 15: }
// CHECK-NEXT: -: 16:
// CHECK-NEXT: 1: 17: return 0;
// CHECK-NEXT: 1: 18:}

View File

@ -1,15 +0,0 @@
#include <unistd.h>
void func1() {}
void func2() {}
int main(void)
{
func1();
execlp("ls", "-l", "-h", (char*)0);
func2();
return 0;
}

View File

@ -1,23 +0,0 @@
//CHECK: -: 0:Source:{{.*}}Inputs{{[/\\]}}instrprof-gcov-execlp.c
//CHECK-NEXT: -: 0:Graph:instrprof-gcov-execlp.gcno
//CHECK-NEXT: -: 0:Data:instrprof-gcov-execlp.gcda
//CHECK-NEXT: -: 0:Runs:1
//CHECK-NEXT: -: 0:Programs:1
//CHECK-NEXT: -: 1:#include <unistd.h>
//CHECK-NEXT: -: 2:
//CHECK-NEXT:function func1 called 1 returned 100% blocks executed 100%
//CHECK-NEXT: 1: 3:void func1() {}
//CHECK-NEXT:function func2 called 0 returned 0% blocks executed 0%
//CHECK-NEXT: #####: 4:void func2() {}
//CHECK-NEXT: -: 5:
//CHECK-NEXT:function main called 1 returned 0% blocks executed 33%
//CHECK-NEXT: 1: 6:int main(void)
//CHECK-NEXT: -: 7:{
//CHECK-NEXT: 1: 8: func1();
//CHECK-NEXT: -: 9:
//CHECK-NEXT: 1: 10: execlp("ls", "-l", "-h", (char*)0);
//CHECK-NEXT: -: 11:
//CHECK-NEXT: #####: 12: func2();
//CHECK-NEXT: -: 13:
//CHECK-NEXT: #####: 14: return 0;
//CHECK-NEXT: -: 15:}

View File

@ -1,17 +0,0 @@
#include <unistd.h>
void func1() {}
void func2() {}
int main(void)
{
char *const args[] = {"-l", "-h", (char*)0};
func1();
execvp("ls", args);
func2();
return 0;
}

View File

@ -1,25 +0,0 @@
//CHECK: -: 0:Source:{{.*}}Inputs{{[/\\]}}instrprof-gcov-execvp.c
//CHECK-NEXT: -: 0:Graph:instrprof-gcov-execvp.gcno
//CHECK-NEXT: -: 0:Data:instrprof-gcov-execvp.gcda
//CHECK-NEXT: -: 0:Runs:1
//CHECK-NEXT: -: 0:Programs:1
//CHECK-NEXT: -: 1:#include <unistd.h>
//CHECK-NEXT: -: 2:
//CHECK-NEXT:function func1 called 1 returned 100% blocks executed 100%
//CHECK-NEXT: 1: 3:void func1() {}
//CHECK-NEXT:function func2 called 0 returned 0% blocks executed 0%
//CHECK-NEXT: #####: 4:void func2() {}
//CHECK-NEXT: -: 5:
//CHECK-NEXT:function main called 1 returned 0% blocks executed 33%
//CHECK-NEXT: 1: 6:int main(void)
//CHECK-NEXT: -: 7:{
//CHECK-NEXT: 1: 8: char *const args[] = {"-l", "-h", (char*)0};
//CHECK-NEXT: -: 9:
//CHECK-NEXT: 1: 10: func1();
//CHECK-NEXT: -: 11:
//CHECK-NEXT: 1: 12: execvp("ls", args);
//CHECK-NEXT: -: 13:
//CHECK-NEXT: #####: 14: func2();
//CHECK-NEXT: -: 15:
//CHECK-NEXT: #####: 16: return 0;
//CHECK-NEXT: -: 17:}

View File

@ -1,15 +0,0 @@
#include <unistd.h>
void func1() {}
void func2() {}
int main(void)
{
func1();
fork();
func2();
return 0;
}

View File

@ -1,23 +0,0 @@
// CHECK: -: 0:Source:{{.*}}Inputs{{[/\\]}}instrprof-gcov-fork.c
// CHECK-NEXT: -: 0:Graph:instrprof-gcov-fork.gcno
// CHECK-NEXT: -: 0:Data:instrprof-gcov-fork.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: -: 1:#include <unistd.h>
// CHECK-NEXT: -: 2:
// CHECK-NEXT:function func1 called 1 returned 100% blocks executed 100%
// CHECK-NEXT: 1: 3:void func1() {}
// CHECK-NEXT:function func2 called 2 returned 100% blocks executed 100%
// CHECK-NEXT: 2: 4:void func2() {}
// CHECK-NEXT: -: 5:
// CHECK-NEXT:function main called 1 returned 200% blocks executed 100%
// CHECK-NEXT: 1: 6:int main(void)
// CHECK-NEXT: -: 7:{
// CHECK-NEXT: 1: 8: func1();
// CHECK-NEXT: -: 9:
// CHECK-NEXT: 1: 10: fork();
// CHECK-NEXT: -: 11:
// CHECK-NEXT: 2: 12: func2();
// CHECK-NEXT: -: 13:
// CHECK-NEXT: 2: 14: return 0;
// CHECK-NEXT: -: 15:}

View File

@ -1,14 +0,0 @@
// CHECK: -: 0:Source:{{.*}}Inputs{{[/\\]}}instrprof-shared-lib.c
// CHECK-NEXT: -: 0:Graph:instrprof-shared-lib.gcno
// CHECK-NEXT: -: 0:Data:instrprof-shared-lib.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: -: 1:int g1 = 0;
// CHECK-NEXT: -: 2:int g2 = 1;
// CHECK-NEXT: -: 3:
// CHECK-NEXT: 1: 4:void foo(int n) {
// CHECK-NEXT: 1: 5: if (n % 5 == 0)
// CHECK-NEXT: #####: 6: g1++;
// CHECK-NEXT: -: 7: else
// CHECK-NEXT: 1: 8: g2++;
// CHECK-NEXT: 1: 9:}

View File

@ -1,14 +0,0 @@
// CHECK: -: 0:Source:{{.*}}Inputs{{[/\\]}}instrprof-shared-lib.c
// CHECK-NEXT: -: 0:Graph:instrprof-shared-lib.gcno
// CHECK-NEXT: -: 0:Data:instrprof-shared-lib.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: -: 1:int g1 = 0;
// CHECK-NEXT: -: 2:int g2 = 1;
// CHECK-NEXT: -: 3:
// CHECK-NEXT: 2: 4:void foo(int n) {
// CHECK-NEXT: 2: 5: if (n % 5 == 0)
// CHECK-NEXT: #####: 6: g1++;
// CHECK-NEXT: -: 7: else
// CHECK-NEXT: 2: 8: g2++;
// CHECK-NEXT: 2: 9:}

View File

@ -1,36 +0,0 @@
extern void foo(int n);
extern void __gcov_flush(void);
int bar1 = 0;
int bar2 = 1;
void bar(int n) {
if (n % 5 == 0)
bar1++;
else
bar2++;
}
int main(int argc, char *argv[]) {
#ifdef SHARED_CALL_BEFORE_GCOV_FLUSH
foo(1);
#endif
bar(5);
__gcov_flush();
bar(5);
#ifdef SHARED_CALL_AFTER_GCOV_FLUSH
foo(1);
#endif
#ifdef EXIT_ABRUPTLY
_exit(0);
#endif
bar(5);
return 0;
}

View File

@ -1,41 +0,0 @@
// CHECK: -: 0:Source:{{.*}}Inputs{{[/\\]}}instrprof-shared-main-gcov-flush.c
// CHECK-NEXT: -: 0:Graph:instrprof-shared-main-gcov-flush.gcno
// CHECK-NEXT: -: 0:Data:instrprof-shared-main-gcov-flush.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: -: 1:extern void foo(int n);
// CHECK-NEXT: -: 2:extern void __gcov_flush(void);
// CHECK-NEXT: -: 3:
// CHECK-NEXT: -: 4:int bar1 = 0;
// CHECK-NEXT: -: 5:int bar2 = 1;
// CHECK-NEXT: -: 6:
// CHECK-NEXT: 1: 7:void bar(int n) {
// CHECK-NEXT: 1: 8: if (n % 5 == 0)
// CHECK-NEXT: 1: 9: bar1++;
// CHECK-NEXT: -: 10: else
// CHECK-NEXT: #####: 11: bar2++;
// CHECK-NEXT: 1: 12:}
// CHECK-NEXT: -: 13:
// CHECK-NEXT: 1: 14:int main(int argc, char *argv[]) {
// CHECK-NEXT: -: 15:#ifdef SHARED_CALL_BEFORE_GCOV_FLUSH
// CHECK-NEXT: 1: 16: foo(1);
// CHECK-NEXT: -: 17:#endif
// CHECK-NEXT: -: 18:
// CHECK-NEXT: 1: 19: bar(5);
// CHECK-NEXT: -: 20:
// CHECK-NEXT: 1: 21: __gcov_flush();
// CHECK-NEXT: -: 22:
// CHECK-NEXT: 1: 23: bar(5);
// CHECK-NEXT: -: 24:
// CHECK-NEXT: -: 25:#ifdef SHARED_CALL_AFTER_GCOV_FLUSH
// CHECK-NEXT: 1: 26: foo(1);
// CHECK-NEXT: -: 27:#endif
// CHECK-NEXT: -: 28:
// CHECK-NEXT: -: 29:#ifdef EXIT_ABRUPTLY
// CHECK-NEXT: 1: 30: _exit(0);
// CHECK-NEXT: -: 31:#endif
// CHECK-NEXT: -: 32:
// CHECK-NEXT: -: 33: bar(5);
// CHECK-NEXT: -: 34:
// CHECK-NEXT: -: 35: return 0;
// CHECK-NEXT: -: 36:}

View File

@ -1,41 +0,0 @@
// CHECK: -: 0:Source:{{.*}}Inputs{{[/\\]}}instrprof-shared-main-gcov-flush.c
// CHECK-NEXT: -: 0:Graph:instrprof-shared-main-gcov-flush.gcno
// CHECK-NEXT: -: 0:Data:instrprof-shared-main-gcov-flush.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: -: 1:extern void foo(int n);
// CHECK-NEXT: -: 2:extern void __gcov_flush(void);
// CHECK-NEXT: -: 3:
// CHECK-NEXT: -: 4:int bar1 = 0;
// CHECK-NEXT: -: 5:int bar2 = 1;
// CHECK-NEXT: -: 6:
// CHECK-NEXT: 3: 7:void bar(int n) {
// CHECK-NEXT: 3: 8: if (n % 5 == 0)
// CHECK-NEXT: 3: 9: bar1++;
// CHECK-NEXT: -: 10: else
// CHECK-NEXT: #####: 11: bar2++;
// CHECK-NEXT: 3: 12:}
// CHECK-NEXT: -: 13:
// CHECK-NEXT: 1: 14:int main(int argc, char *argv[]) {
// CHECK-NEXT: -: 15:#ifdef SHARED_CALL_BEFORE_GCOV_FLUSH
// CHECK-NEXT: -: 16: foo(1);
// CHECK-NEXT: -: 17:#endif
// CHECK-NEXT: -: 18:
// CHECK-NEXT: 1: 19: bar(5);
// CHECK-NEXT: -: 20:
// CHECK-NEXT: 1: 21: __gcov_flush();
// CHECK-NEXT: -: 22:
// CHECK-NEXT: 1: 23: bar(5);
// CHECK-NEXT: -: 24:
// CHECK-NEXT: -: 25:#ifdef SHARED_CALL_AFTER_GCOV_FLUSH
// CHECK-NEXT: 1: 26: foo(1);
// CHECK-NEXT: -: 27:#endif
// CHECK-NEXT: -: 28:
// CHECK-NEXT: -: 29:#ifdef EXIT_ABRUPTLY
// CHECK-NEXT: -: 30: _exit(0);
// CHECK-NEXT: -: 31:#endif
// CHECK-NEXT: -: 32:
// CHECK-NEXT: 1: 33: bar(5);
// CHECK-NEXT: -: 34:
// CHECK-NEXT: 1: 35: return 0;
// CHECK-NEXT: -: 36:}

View File

@ -1,41 +0,0 @@
// CHECK: -: 0:Source:{{.*}}Inputs{{[/\\]}}instrprof-shared-main-gcov-flush.c
// CHECK-NEXT: -: 0:Graph:instrprof-shared-main-gcov-flush.gcno
// CHECK-NEXT: -: 0:Data:instrprof-shared-main-gcov-flush.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: -: 1:extern void foo(int n);
// CHECK-NEXT: -: 2:extern void __gcov_flush(void);
// CHECK-NEXT: -: 3:
// CHECK-NEXT: -: 4:int bar1 = 0;
// CHECK-NEXT: -: 5:int bar2 = 1;
// CHECK-NEXT: -: 6:
// CHECK-NEXT: 3: 7:void bar(int n) {
// CHECK-NEXT: 3: 8: if (n % 5 == 0)
// CHECK-NEXT: 3: 9: bar1++;
// CHECK-NEXT: -: 10: else
// CHECK-NEXT: #####: 11: bar2++;
// CHECK-NEXT: 3: 12:}
// CHECK-NEXT: -: 13:
// CHECK-NEXT: 1: 14:int main(int argc, char *argv[]) {
// CHECK-NEXT: -: 15:#ifdef SHARED_CALL_BEFORE_GCOV_FLUSH
// CHECK-NEXT: 1: 16: foo(1);
// CHECK-NEXT: -: 17:#endif
// CHECK-NEXT: -: 18:
// CHECK-NEXT: 1: 19: bar(5);
// CHECK-NEXT: -: 20:
// CHECK-NEXT: 1: 21: __gcov_flush();
// CHECK-NEXT: -: 22:
// CHECK-NEXT: 1: 23: bar(5);
// CHECK-NEXT: -: 24:
// CHECK-NEXT: -: 25:#ifdef SHARED_CALL_AFTER_GCOV_FLUSH
// CHECK-NEXT: 1: 26: foo(1);
// CHECK-NEXT: -: 27:#endif
// CHECK-NEXT: -: 28:
// CHECK-NEXT: -: 29:#ifdef EXIT_ABRUPTLY
// CHECK-NEXT: -: 30: _exit(0);
// CHECK-NEXT: -: 31:#endif
// CHECK-NEXT: -: 32:
// CHECK-NEXT: 1: 33: bar(5);
// CHECK-NEXT: -: 34:
// CHECK-NEXT: 1: 35: return 0;
// CHECK-NEXT: -: 36:}

View File

@ -1,41 +0,0 @@
// CHECK: -: 0:Source:{{.*}}Inputs{{[/\\]}}instrprof-shared-main-gcov-flush.c
// CHECK-NEXT: -: 0:Graph:instrprof-shared-main-gcov-flush.gcno
// CHECK-NEXT: -: 0:Data:instrprof-shared-main-gcov-flush.gcda
// CHECK-NEXT: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK-NEXT: -: 1:extern void foo(int n);
// CHECK-NEXT: -: 2:extern void __gcov_flush(void);
// CHECK-NEXT: -: 3:
// CHECK-NEXT: -: 4:int bar1 = 0;
// CHECK-NEXT: -: 5:int bar2 = 1;
// CHECK-NEXT: -: 6:
// CHECK-NEXT: 3: 7:void bar(int n) {
// CHECK-NEXT: 3: 8: if (n % 5 == 0)
// CHECK-NEXT: 3: 9: bar1++;
// CHECK-NEXT: -: 10: else
// CHECK-NEXT: #####: 11: bar2++;
// CHECK-NEXT: 3: 12:}
// CHECK-NEXT: -: 13:
// CHECK-NEXT: 1: 14:int main(int argc, char *argv[]) {
// CHECK-NEXT: -: 15:#ifdef SHARED_CALL_BEFORE_GCOV_FLUSH
// CHECK-NEXT: 1: 16: foo(1);
// CHECK-NEXT: -: 17:#endif
// CHECK-NEXT: -: 18:
// CHECK-NEXT: 1: 19: bar(5);
// CHECK-NEXT: -: 20:
// CHECK-NEXT: 1: 21: __gcov_flush();
// CHECK-NEXT: -: 22:
// CHECK-NEXT: 1: 23: bar(5);
// CHECK-NEXT: -: 24:
// CHECK-NEXT: -: 25:#ifdef SHARED_CALL_AFTER_GCOV_FLUSH
// CHECK-NEXT: -: 26: foo(1);
// CHECK-NEXT: -: 27:#endif
// CHECK-NEXT: -: 28:
// CHECK-NEXT: -: 29:#ifdef EXIT_ABRUPTLY
// CHECK-NEXT: -: 30: _exit(0);
// CHECK-NEXT: -: 31:#endif
// CHECK-NEXT: -: 32:
// CHECK-NEXT: 1: 33: bar(5);
// CHECK-NEXT: -: 34:
// CHECK-NEXT: 1: 35: return 0;
// CHECK-NEXT: -: 36:}

View File

@ -0,0 +1,28 @@
/// A basic block with fork/exec* is split. .gcda is flushed immediately before
/// fork/exec* so the lines before exec* are counted once while succeeding
/// lines are not counted.
// RUN: mkdir -p %t.d && cd %t.d
// RUN: %clang --coverage %s -o %t
// RUN: test -f gcov-execlp.gcno
// RUN: rm -f gcov-execlp.gcda && %run %t
// RUN: llvm-cov gcov -t gcov-execlp.gcda | FileCheck %s --check-prefixes=CHECK,EXECLP
// RUN: %clang --coverage -DEXECVP %s -o %t
// RUN: rm -f gcov-execlp.gcda && %run %t
// RUN: llvm-cov gcov -t gcov-execlp.gcda | FileCheck %s --check-prefixes=CHECK,EXECVP
#include <unistd.h>
void func1(void) {} // CHECK: 1: [[#@LINE]]:void func1(void)
void func2(void) {} // CHECK-NEXT: #####: [[#@LINE]]:
int main(void) { // CHECK-NEXT: 1: [[#@LINE]]:
func1(); // CHECK-NEXT: 1: [[#@LINE]]:
#ifdef EXECVP
char *argv[] = {"ls", "-l", "-h", (char *)0};
execvp("ls", argv); // EXECVP: 1: [[#@LINE]]: execvp
#else
execlp("ls", "-l", "-h", (char *)0); // EXECLP: 1: [[#@LINE]]: execlp
#endif
func2(); // CHECK: #####: [[#@LINE]]: func2
return 0; // CHECK-NEXT: #####: [[#@LINE]]:
}

View File

@ -0,0 +1,22 @@
/// A basic block with fork/exec* is split. .gcda is flushed immediately before
/// fork/exec* so the lines before fork are counted once while succeeding
/// lines are counted twice.
// UNSUPPORTED: darwin
// RUN: mkdir -p %t.d && cd %t.d
// RUN: %clang --coverage %s -o %t
// RUN: test -f gcov-fork.gcno
// RUN: rm -f gcov-fork.gcda && %run %t
// RUN: llvm-cov gcov -t gcov-fork.gcda | FileCheck %s
#include <unistd.h>
void func1() {} // CHECK: 1: [[#@LINE]]:void func1()
void func2() {} // CHECK-NEXT: 2: [[#@LINE]]:
int main(void) { // CHECK-NEXT: 1: [[#@LINE]]:
func1(); // CHECK-NEXT: 1: [[#@LINE]]:
fork(); // CHECK-NEXT: 1: [[#@LINE]]:
func2(); // CHECK-NEXT: 2: [[#@LINE]]:
return 0; // CHECK-NEXT: 2: [[#@LINE]]:
}

View File

@ -0,0 +1,113 @@
/// This test fails on Mac (https://bugs.llvm.org/show_bug.cgi?id=38134)
// XFAIL: darwin
// RUN: mkdir -p %t.d && cd %t.d
// RUN: %clang -E -DSHARED %s -o shared.c
// RUN: %clang --coverage -fPIC -shared shared.c -o libfunc.so
// RUN: test -f shared.gcno
/// Test the case where we exit abruptly after calling __gcov_flush, which means we don't write out the counters at exit.
// RUN: %clang -DEXIT_ABRUPTLY -DSHARED_CALL_BEFORE_FLUSH -DSHARED_CALL_AFTER_FLUSH --coverage %s -L%t.d -rpath %t.d -lfunc -o %t
// RUN: test -f gcov-shared-flush.gcno
// RUN: rm -f gcov-shared-flush.gcda shared.gcda
// RUN: %run %t
// RUN: llvm-cov gcov -t gcov-shared-flush.gcda | FileCheck %s --check-prefix=NO_WRITEOUT
// RUN: llvm-cov gcov -t shared.gcda | FileCheck %s --check-prefix=SHARED
// NO_WRITEOUT: -: [[#%u,L:]]:#ifdef EXIT_ABRUPTLY
// NO_WRITEOUT-NEXT: 1: [[#%u,L+1]]: _exit(0);
// SHARED: 1: {{[[0-9]+}}:void foo(int n)
/// Test the case where we exit normally and we have a call to the shared library function before __gcov_flush.
// RUN: %clang -DSHARED_CALL_BEFORE_FLUSH --coverage %s -L%t.d -rpath %t.d -lfunc -o %t
// RUN: test -f gcov-shared-flush.gcno
// RUN: rm -f gcov-shared-flush.gcda shared.gcda
// RUN: %run %t
// RUN: llvm-cov gcov -t gcov-shared-flush.gcda | FileCheck %s --check-prefix=BEFORE
// RUN: llvm-cov gcov -t shared.gcda | FileCheck %s --check-prefix=SHARED_ONCE
// BEFORE: -: {{[0-9]+}}:#ifdef SHARED_CALL_BEFORE_FLUSH
// BEFORE-NEXT: 1: {{[0-9]+}}: foo(1);
// BEFORE: 1: {{[0-9]+}}: __gcov_flush();
// BEFORE: -: {{[0-9]+}}:#ifdef SHARED_CALL_AFTER_FLUSH
// BEFORE-NEXT: -: {{[0-9]+}}: foo(1);
// BEFORE: 1: {{[0-9]+}}: bar(5);
// SHARED_ONCE: 1: {{[0-9]+}}:void foo(int n)
// # Test the case where we exit normally and we have a call to the shared library function after __gcov_flush.
// RUN: %clang -DSHARED_CALL_AFTER_FLUSH --coverage %s -L%t.d -rpath %t.d -lfunc -o %t
// RUN: test -f gcov-shared-flush.gcno
// RUN: rm -f gcov-shared-flush.gcda shared.gcda
// RUN: %run %t
// RUN: llvm-cov gcov -t gcov-shared-flush.gcda | FileCheck %s --check-prefix=AFTER
// RUN: llvm-cov gcov -t shared.gcda > 2s.txt
// AFTER: -: {{[0-9]+}}:#ifdef SHARED_CALL_BEFORE_FLUSH
// AFTER-NEXT: -: {{[0-9]+}}: foo(1);
// AFTER: 1: {{[0-9]+}}: __gcov_flush();
// AFTER: -: {{[0-9]+}}:#ifdef SHARED_CALL_AFTER_FLUSH
// AFTER-NEXT: 1: {{[0-9]+}}: foo(1);
// AFTER: 1: {{[0-9]+}}: bar(5);
// # Test the case where we exit normally and we have calls to the shared library function before and after __gcov_flush.
// RUN: %clang -DSHARED_CALL_BEFORE_FLUSH -DSHARED_CALL_AFTER_FLUSH --coverage %s -L%t.d -rpath %t.d -lfunc -o %t
// RUN: test -f gcov-shared-flush.gcno
// RUN: rm -f gcov-shared-flush.gcda shared.gcda
// RUN: %run %t
// RUN: llvm-cov gcov -t gcov-shared-flush.gcda | FileCheck %s --check-prefix=BEFORE_AFTER
// RUN: llvm-cov gcov -t shared.gcda | FileCheck %s --check-prefix=SHARED_TWICE
// BEFORE_AFTER: -: {{[0-9]+}}:#ifdef SHARED_CALL_BEFORE_FLUSH
// BEFORE_AFTER-NEXT: 1: {{[0-9]+}}: foo(1);
// BEFORE_AFTER: 1: {{[0-9]+}}: __gcov_flush();
// BEFORE_AFTER: -: {{[0-9]+}}:#ifdef SHARED_CALL_AFTER_FLUSH
// BEFORE_AFTER-NEXT: 1: {{[0-9]+}}: foo(1);
// BEFORE_AFTER: 1: {{[0-9]+}}: bar(5);
// SHARED_TWICE: 2: {{[0-9]+}}:void foo(int n)
#ifdef SHARED
void foo(int n) {
}
#else
extern void foo(int n);
extern void __gcov_flush(void);
int bar1 = 0;
int bar2 = 1;
void bar(int n) {
if (n % 5 == 0)
bar1++;
else
bar2++;
}
int main(int argc, char *argv[]) {
#ifdef SHARED_CALL_BEFORE_FLUSH
foo(1);
#endif
bar(5);
__gcov_flush();
bar(5);
#ifdef SHARED_CALL_AFTER_FLUSH
foo(1);
#endif
#ifdef EXIT_ABRUPTLY
_exit(0);
#endif
bar(5);
return 0;
}
#endif

View File

@ -1,10 +0,0 @@
RUN: mkdir -p %t.d
RUN: cd %t.d
RUN: %clang --coverage -o %t %S/../Inputs/instrprof-gcov-execlp.c
RUN: test -f instrprof-gcov-execlp.gcno
RUN: rm -f instrprof-gcov-execlp.gcda
RUN: %run %t
RUN: llvm-cov gcov -b -c instrprof-gcov-execlp.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-gcov-execlp.c.gcov %S/../Inputs/instrprof-gcov-execlp.c.gcov

View File

@ -1,10 +0,0 @@
RUN: mkdir -p %t.d
RUN: cd %t.d
RUN: %clang --coverage -o %t %S/../Inputs/instrprof-gcov-execvp.c
RUN: test -f instrprof-gcov-execvp.gcno
RUN: rm -f instrprof-gcov-execvp.gcda
RUN: %run %t
RUN: llvm-cov gcov -b -c instrprof-gcov-execvp.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-gcov-execvp.c.gcov %S/../Inputs/instrprof-gcov-execvp.c.gcov

View File

@ -1,13 +0,0 @@
UNSUPPORTED: linux
UNSUPPORTED: darwin
RUN: mkdir -p %t.d
RUN: cd %t.d
RUN: %clang --coverage -o %t %S/../Inputs/instrprof-gcov-fork.c
RUN: test -f instrprof-gcov-fork.gcno
RUN: rm -f instrprof-gcov-fork.gcda
RUN: %run %t
RUN: llvm-cov gcov -b -c instrprof-gcov-fork.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-gcov-fork.c.gcov %S/../Inputs/instrprof-gcov-fork.c.gcov

View File

@ -1,52 +0,0 @@
# This test fails on Mac (https://bugs.llvm.org/show_bug.cgi?id=38134)
XFAIL: darwin
RUN: mkdir -p %t.d
RUN: cd %t.d
RUN: %clang --coverage -o libfunc.so -fPIC -shared %S/../Inputs/instrprof-shared-lib.c
RUN: test -f instrprof-shared-lib.gcno
# Test the case where we exit abruptly after calling __gcov_flush, which means we don't write out the counters at exit.
RUN: %clang -DEXIT_ABRUPTLY -DSHARED_CALL_BEFORE_GCOV_FLUSH -DSHARED_CALL_AFTER_GCOV_FLUSH --coverage -o %t -L%t.d -rpath %t.d -lfunc %S/../Inputs/instrprof-shared-main-gcov-flush.c
RUN: test -f instrprof-shared-main-gcov-flush.gcno
RUN: rm -f instrprof-shared-main-gcov-flush.gcda instrprof-shared-lib.gcda
RUN: %run %t
RUN: llvm-cov gcov instrprof-shared-main-gcov-flush.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-main-gcov-flush.c.gcov %S/../Inputs/instrprof-shared-main-gcov-flush_no-writeout.c.gcov
RUN: llvm-cov gcov instrprof-shared-lib.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-lib.c.gcov %S/../Inputs/instrprof-shared-lib.c.gcov
# Test the case where we exit normally and we have a call to the shared library function before __gcov_flush.
RUN: %clang -DSHARED_CALL_BEFORE_GCOV_FLUSH --coverage -o %t -L%t.d -rpath %t.d -lfunc %S/../Inputs/instrprof-shared-main-gcov-flush.c
RUN: test -f instrprof-shared-main-gcov-flush.gcno
RUN: rm -f instrprof-shared-main-gcov-flush.gcda instrprof-shared-lib.gcda
RUN: %run %t
RUN: llvm-cov gcov instrprof-shared-main-gcov-flush.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-main-gcov-flush.c.gcov %S/../Inputs/instrprof-shared-main-gcov-flush_shared-call-before.c.gcov
RUN: llvm-cov gcov instrprof-shared-lib.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-lib.c.gcov %S/../Inputs/instrprof-shared-lib.c.gcov
# Test the case where we exit normally and we have a call to the shared library function after __gcov_flush.
RUN: %clang -DSHARED_CALL_AFTER_GCOV_FLUSH --coverage -o %t -L%t.d -rpath %t.d -lfunc %S/../Inputs/instrprof-shared-main-gcov-flush.c
RUN: test -f instrprof-shared-main-gcov-flush.gcno
RUN: rm -f instrprof-shared-main-gcov-flush.gcda instrprof-shared-lib.gcda
RUN: %run %t
RUN: llvm-cov gcov instrprof-shared-main-gcov-flush.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-main-gcov-flush.c.gcov %S/../Inputs/instrprof-shared-main-gcov-flush_shared-call-after.c.gcov
RUN: llvm-cov gcov instrprof-shared-lib.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-lib.c.gcov %S/../Inputs/instrprof-shared-lib.c.gcov
# Test the case where we exit normally and we have calls to the shared library function before and after __gcov_flush.
RUN: %clang -DSHARED_CALL_BEFORE_GCOV_FLUSH -DSHARED_CALL_AFTER_GCOV_FLUSH --coverage -o %t -L%t.d -rpath %t.d -lfunc %S/../Inputs/instrprof-shared-main-gcov-flush.c
RUN: test -f instrprof-shared-main-gcov-flush.gcno
RUN: rm -f instrprof-shared-main-gcov-flush.gcda instrprof-shared-lib.gcda
RUN: %run %t
RUN: llvm-cov gcov instrprof-shared-main-gcov-flush.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-main-gcov-flush.c.gcov %S/../Inputs/instrprof-shared-main-gcov-flush_shared-call-before-after.c.gcov
RUN: llvm-cov gcov instrprof-shared-lib.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-shared-lib.c.gcov %S/../Inputs/instrprof-shared-lib_called-twice.c.gcov

View File

@ -9,23 +9,14 @@
// CHECK: -: 0:Runs:1
// CHECK-NEXT: -: 0:Programs:1
// CHECK: -: 1:void __gcov_flush(void);
// CHECK-NEXT: -: 2:
// CHECK-NEXT: 1: 3:int main(void) {
// CHECK-NEXT: 1: 4: int i = 22;
// CHECK-NEXT: 1: 5: __gcov_flush();
// CHECK-NEXT: 1: 6: i = 42;
// CHECK-NEXT: 1: 7: __builtin_trap();
// CHECK-NEXT: 1: 8: i = 84;
// CHECK-NEXT: 1: 9: return 0;
void __gcov_flush(void);
int main(void) {
int i = 22;
__gcov_flush();
i = 42;
__builtin_trap();
i = 84;
return 0;
int main(void) { // CHECK: 1: [[#@LINE]]:int main(void)
int i = 22; // CHECK-NEXT: 1: [[#@LINE]]:
__gcov_flush(); // CHECK-NEXT: 1: [[#@LINE]]:
i = 42; // CHECK-NEXT: 1: [[#@LINE]]:
__builtin_trap(); // CHECK-NEXT: 1: [[#@LINE]]:
i = 84; // CHECK-NEXT: 1: [[#@LINE]]:
return 0; // CHECK-NEXT: 1: [[#@LINE]]:
}

View File

@ -0,0 +1,24 @@
/// Test we close file handle on flush, so the .gcda file can be deleted on
/// Windows while the process is still running. In addition, test we create
/// a new .gcda on flush, so there is a file when the process exists.
// RUN: mkdir -p %t.d && cd %t.d
// RUN: %clang --coverage -o %t %s
// RUN: test -f gcov-dump-and-remove.gcno
// RUN: rm -f gcov-dump-and-remove.gcda && %run %t
// RUN: llvm-cov gcov -t gcov-dump-and-remove.gcda | FileCheck %s
extern void __gcov_flush(void);
extern int remove(const char *); // CHECK: -: [[#@LINE]]:extern int remove
int main(void) { // CHECK-NEXT: #####: [[#@LINE]]:
__gcov_flush(); // CHECK-NEXT: #####: [[#@LINE]]:
if (remove("gcov-dump-and-remove.gcda") != 0) // CHECK-NEXT: #####: [[#@LINE]]:
return 1; // CHECK-NEXT: #####: [[#@LINE]]: return 1;
// CHECK-NEXT: -: [[#@LINE]]:
__gcov_flush(); // CHECK-NEXT: #####: [[#@LINE]]:
__gcov_flush(); // CHECK-NEXT: #####: [[#@LINE]]:
if (remove("gcov-dump-and-remove.gcda") != 0) // CHECK-NEXT: #####: [[#@LINE]]:
return 1; // CHECK-NEXT: #####: [[#@LINE]]: return 1;
return 0;
}

View File

@ -1,10 +0,0 @@
RUN: mkdir -p %t.d
RUN: cd %t.d
RUN: %clang --coverage -o %t %S/Inputs/instrprof-gcov-__gcov_flush-multiple.c
RUN: test -f instrprof-gcov-__gcov_flush-multiple.gcno
RUN: rm -f instrprof-gcov-__gcov_flush-multiple.gcda
RUN: %run %t
RUN: llvm-cov gcov instrprof-gcov-__gcov_flush-multiple.gcda
RUN: FileCheck --match-full-lines --strict-whitespace --input-file instrprof-gcov-__gcov_flush-multiple.c.gcov %S/Inputs/instrprof-gcov-__gcov_flush-multiple.c.gcov