blob: cf7351ddcd3707fc1de2a95cb929c6e72874c610 [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// 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.
Stephen Hines86277eb2015-03-23 12:06:32 -07004
Pirama Arumuga Nainar259f7062015-05-06 11:49:53 -07005// RUN: %clangxx_asan -fsanitize-coverage=1 -O0 -DSHARED %s -shared -o %dynamiclib -fPIC
6// RUN: %clangxx_asan -fsanitize-coverage=1 -O0 %s %libdl -o %t
Stephen Hines2d1fdb22014-05-28 23:58:16 -07007
8// RUN: rm -rf %T/coverage-direct-large
9
10// RUN: mkdir -p %T/coverage-direct-large/normal && cd %T/coverage-direct-large/normal
Pirama Arumuga Nainar259f7062015-05-06 11:49:53 -070011// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:verbosity=1 %run %t %dynamiclib
Stephen Hines2d1fdb22014-05-28 23:58:16 -070012// 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
Pirama Arumuga Nainar259f7062015-05-06 11:49:53 -070016// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:verbosity=1 %run %t %dynamiclib
Stephen Hines2d1fdb22014-05-28 23:58:16 -070017// 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
Stephen Hines86277eb2015-03-23 12:06:32 -070039#define DECL(x) __attribute__((noinline)) static void x() {}
Stephen Hines2d1fdb22014-05-28 23:58:16 -070040#define CALL(x) x();
41
42F4(DECL, f)
43
Stephen Hines86277eb2015-03-23 12:06:32 -070044#ifdef SHARED
45extern "C" void so_entry() {
46 F4(CALL, f)
47}
48#else
49
50#include <assert.h>
51#include <dlfcn.h>
Pirama Arumuga Nainar259f7062015-05-06 11:49:53 -070052#include <stdio.h>
53int main(int argc, char **argv) {
Stephen Hines2d1fdb22014-05-28 23:58:16 -070054 F4(CALL, f)
Pirama Arumuga Nainar259f7062015-05-06 11:49:53 -070055 assert(argc > 1);
56 void *handle1 = dlopen(argv[1], RTLD_LAZY); // %dynamiclib
Stephen Hines86277eb2015-03-23 12:06:32 -070057 assert(handle1);
58 void (*so_entry)() = (void (*)())dlsym(handle1, "so_entry");
59 assert(so_entry);
60 so_entry();
61
Stephen Hines2d1fdb22014-05-28 23:58:16 -070062 return 0;
63}
Stephen Hines86277eb2015-03-23 12:06:32 -070064
65#endif // SHARED