1 // Test for direct coverage writing with lots of data.
2 // Current implementation maps output file in chunks of 64K. This test overflows
3 // 1 chunk.
4
5 // RUN: %clangxx_asan -fsanitize-coverage=func -O0 -DSHARED %s -shared -o %dynamiclib -fPIC
6 // RUN: %clangxx_asan -fsanitize-coverage=func -O0 %s %libdl -o %t
7
8 // RUN: rm -rf %T/coverage-direct-large
9
10 // RUN: mkdir -p %T/coverage-direct-large/normal && cd %T/coverage-direct-large/normal
11 // RUN: %env_asan_opts=coverage=1:coverage_direct=0:verbosity=1 %run %t %dynamiclib
12 // RUN: %sancov print *.sancov >out.txt
13 // RUN: cd ../..
14
15 // RUN: mkdir -p %T/coverage-direct-large/direct && cd %T/coverage-direct-large/direct
16 // RUN: %env_asan_opts=coverage=1:coverage_direct=1:verbosity=1 %run %t %dynamiclib
17 // RUN: %sancov rawunpack *.sancov.raw
18 // RUN: %sancov print *.sancov >out.txt
19 // RUN: cd ../..
20
21 // RUN: diff -u coverage-direct-large/normal/out.txt coverage-direct-large/direct/out.txt
22 //
23 // XFAIL: android
24
25 #define F0(Q, x) Q(x)
26 #define F1(Q, x) \
27 F0(Q, x##0) F0(Q, x##1) F0(Q, x##2) F0(Q, x##3) F0(Q, x##4) F0(Q, x##5) \
28 F0(Q, x##6) F0(Q, x##7) F0(Q, x##8) F0(Q, x##9)
29 #define F2(Q, x) \
30 F1(Q, x##0) F1(Q, x##1) F1(Q, x##2) F1(Q, x##3) F1(Q, x##4) F1(Q, x##5) \
31 F1(Q, x##6) F1(Q, x##7) F1(Q, x##8) F1(Q, x##9)
32 #define F3(Q, x) \
33 F2(Q, x##0) F2(Q, x##1) F2(Q, x##2) F2(Q, x##3) F2(Q, x##4) F2(Q, x##5) \
34 F2(Q, x##6) F2(Q, x##7) F2(Q, x##8) F2(Q, x##9)
35 #define F4(Q, x) \
36 F3(Q, x##0) F3(Q, x##1) F3(Q, x##2) F3(Q, x##3) F3(Q, x##4) F3(Q, x##5) \
37 F3(Q, x##6) F3(Q, x##7) F3(Q, x##8) F3(Q, x##9)
38
39 #define DECL(x) __attribute__((noinline)) static void x() {}
40 #define CALL(x) x();
41
F4(DECL,f)42 F4(DECL, f)
43
44 #ifdef SHARED
45 extern "C" void so_entry() {
46 F4(CALL, f)
47 }
48 #else
49
50 #include <assert.h>
51 #include <dlfcn.h>
52 #include <stdio.h>
53 int main(int argc, char **argv) {
54 F4(CALL, f)
55 assert(argc > 1);
56 void *handle1 = dlopen(argv[1], RTLD_LAZY); // %dynamiclib
57 assert(handle1);
58 void (*so_entry)() = (void (*)())dlsym(handle1, "so_entry");
59 assert(so_entry);
60 so_entry();
61
62 return 0;
63 }
64
65 #endif // SHARED
66