From ca1cc5c4e067d496e92e775bd0ac30c1b775bb62 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 18 Jul 2020 11:10:18 -0700 Subject: [PATCH] [gcov][test] Call wait() to make gcov-fork.c reliable If the parent exit before the child, the line counts might be 1. next:18'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 26: 1: 21: if (fork() == -1) return 1; // CHECK-NEXT: 1: [[#@LINE]]: next:18'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 27: 1: 22: func2(); // CHECK-NEXT: 2: [[#@LINE]]: next:18'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 28: 1: 23: return 0; // CHECK-NEXT: 2: [[#@LINE]]: next:18'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- compiler-rt/test/profile/Posix/gcov-fork.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler-rt/test/profile/Posix/gcov-fork.c b/compiler-rt/test/profile/Posix/gcov-fork.c index 4942d5a..022ce71 100644 --- a/compiler-rt/test/profile/Posix/gcov-fork.c +++ b/compiler-rt/test/profile/Posix/gcov-fork.c @@ -1,10 +1,6 @@ /// 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 -/// FIXME: http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/50913 -// UNSUPPORTED: host-byteorder-big-endian - // RUN: mkdir -p %t.d && cd %t.d // RUN: %clang --coverage %s -o %t // RUN: test -f gcov-fork.gcno @@ -17,8 +13,12 @@ void func1() {} // CHECK: 1: [[#@LINE]]:void func1() void func2() {} // CHECK-NEXT: 2: [[#@LINE]]: int main(void) { // CHECK-NEXT: 1: [[#@LINE]]: + int status; // CHECK-NEXT: -: [[#@LINE]]: func1(); // CHECK-NEXT: 1: [[#@LINE]]: - if (fork() == -1) return 1; // CHECK-NEXT: 1: [[#@LINE]]: + pid_t pid = fork(); // CHECK-NEXT: 1: [[#@LINE]]: + if (pid == -1) return 1; // CHECK-NEXT: 2: [[#@LINE]]: + if (pid) // CHECK-NEXT: 2: [[#@LINE]]: + wait(&status); // CHECK-NEXT: 1: [[#@LINE]]: func2(); // CHECK-NEXT: 2: [[#@LINE]]: return 0; // CHECK-NEXT: 2: [[#@LINE]]: } -- 2.7.4