diff options
author | Xinliang David Li <davidxl@google.com> | 2016-06-06 03:17:58 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-06-06 03:17:58 +0000 |
commit | 5cd1f94d4f72f35a4f3de7d4c78dbb2e51a6870e (patch) | |
tree | d12e1aed9b45fd093a9b109c9cb47d160a2ed368 /compiler-rt/test | |
parent | 04a89fd8264ec3e55ed3d9b739a9f84b9292727c (diff) | |
download | bcm5719-llvm-5cd1f94d4f72f35a4f3de7d4c78dbb2e51a6870e.tar.gz bcm5719-llvm-5cd1f94d4f72f35a4f3de7d4c78dbb2e51a6870e.zip |
[profile] in-process mergeing support (part-2)
(Part-1 merging API is in profile runtime)
This patch implements a portable file opening API
with exclusive access for the process. In-process
profile merge requires profile file update to be
atomic/fully sychronized.
llvm-svn: 271864
Diffstat (limited to 'compiler-rt/test')
-rw-r--r-- | compiler-rt/test/profile/Inputs/instrprof-file_ex.c | 59 | ||||
-rw-r--r-- | compiler-rt/test/profile/Linux/instrprof-file_ex.test | 16 |
2 files changed, 75 insertions, 0 deletions
diff --git a/compiler-rt/test/profile/Inputs/instrprof-file_ex.c b/compiler-rt/test/profile/Inputs/instrprof-file_ex.c new file mode 100644 index 00000000000..22e7555a13f --- /dev/null +++ b/compiler-rt/test/profile/Inputs/instrprof-file_ex.c @@ -0,0 +1,59 @@ +/* This is a test case where the parent process forks 10 + * children which contend to write to the same file. With + * file locking support, the data from each child should not + * be lost. + */ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/wait.h> + +extern FILE *lprofOpenFileEx(const char *); +int main(int argc, char *argv[]) { + pid_t tid; + FILE *F; + const char *FN; + int child[10]; + int c; + int i; + + if (argc < 2) { + fprintf(stderr, "Requires one argument \n"); + exit(1); + } + FN = argv[1]; + truncate(FN, 0); + + for (i = 0; i < 10; i++) { + c = fork(); + // in child: + if (c == 0) { + FILE *F = lprofOpenFileEx(FN); + if (!F) { + fprintf(stderr, "Can not open file %s from child\n", FN); + exit(1); + } + fseek(F, 0, SEEK_END); + fprintf(F, "Dump from Child %d\n", i + 11); + fclose(F); + exit(0); + } else { + child[i] = c; + } + } + + // In parent + for (i = 0; i < 10; i++) { + int child_status; + if ((tid = waitpid(child[i], &child_status, 0) == -1)) + break; + } + F = lprofOpenFileEx(FN); + if (!F) { + fprintf(stderr, "Can not open file %s from parent\n", FN); + exit(1); + } + fseek(F, 0, SEEK_END); + fprintf(F, "Dump from parent %d\n", i + 11); + return 0; +} diff --git a/compiler-rt/test/profile/Linux/instrprof-file_ex.test b/compiler-rt/test/profile/Linux/instrprof-file_ex.test new file mode 100644 index 00000000000..af79b7398cc --- /dev/null +++ b/compiler-rt/test/profile/Linux/instrprof-file_ex.test @@ -0,0 +1,16 @@ +RUN: mkdir -p %t.d +RUN: %clang_profgen -fprofile-instr-generate %S/../Inputs/instrprof-file_ex.c -o %t +RUN: %run %t %t.d/run.dump +RUN: sort %t.d/run.dump | FileCheck %s + +CHECK: Dump from Child 11 +CHECK-NEXT: Dump from Child 12 +CHECK-NEXT: Dump from Child 13 +CHECK-NEXT: Dump from Child 14 +CHECK-NEXT: Dump from Child 15 +CHECK-NEXT: Dump from Child 16 +CHECK-NEXT: Dump from Child 17 +CHECK-NEXT: Dump from Child 18 +CHECK-NEXT: Dump from Child 19 +CHECK-NEXT: Dump from Child 20 +CHECK-NEXT: Dump from parent 21 |