1 | // RUN: %clang_pgogen -O2 -o %t.0 %s |
2 | // RUN: %clang_pgogen=%/t.d1 -O2 -o %t.1 %s |
3 | // RUN: %clang_pgogen=%/t.d1/%:t.d2 -O2 -o %t.2 %s |
4 | // |
5 | // RUN: %run %t.0 "" |
6 | // RUN: env LLVM_PROFILE_FILE=%/t.d1/default.profraw %run %t.0 %/t.d1 |
7 | // RUN: env LLVM_PROFILE_FILE=%/t.d1/%:t.d2/default.profraw %run %t.0 %/t.d1/%:t.d2 |
8 | // RUN: %run %t.1 %/t.d1 |
9 | // RUN: %run %t.2 %/t.d1/%:t.d2 |
10 | // RUN: %run %t.2 %/t.d1/%:t.d2 %/t.d1/%:t.d2/%:t.d3/blah.profraw %/t.d1/%:t.d2/%:t.d3/ |
11 | |
12 | #include <string.h> |
13 | |
14 | const char *__llvm_profile_get_path_prefix(); |
15 | void __llvm_profile_set_filename(const char*); |
16 | |
17 | int main(int argc, const char *argv[]) { |
18 | const char *expected; |
19 | const char *prefix; |
20 | if (argc < 2) |
21 | return 1; |
22 | |
23 | expected = argv[1]; |
24 | prefix = __llvm_profile_get_path_prefix(); |
25 | |
26 | // The last character should be a trailing slash. Ignore it in the comparison |
27 | // since it could be '/' or '\\'. |
28 | int slashpos = strlen(s: prefix); |
29 | if (slashpos > 0) { |
30 | --slashpos; |
31 | if (prefix[slashpos] != '/' && prefix[slashpos] != '\\') |
32 | return 1; |
33 | } |
34 | |
35 | if (strncmp(s1: prefix, s2: expected, n: slashpos)) |
36 | return 1; |
37 | |
38 | if (argc == 4) { |
39 | __llvm_profile_set_filename(argv[2]); |
40 | prefix = __llvm_profile_get_path_prefix(); |
41 | expected = argv[3]; |
42 | if (strcmp(s1: prefix, s2: expected)) |
43 | return 1; |
44 | } |
45 | |
46 | return 0; |
47 | } |
48 | |