summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test
diff options
context:
space:
mode:
Diffstat (limited to 'compiler-rt/test')
-rw-r--r--compiler-rt/test/profile/Inputs/instrprof-file_ex.c59
-rw-r--r--compiler-rt/test/profile/Linux/instrprof-file_ex.test16
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
OpenPOWER on IntegriCloud