Files
clang-p2996/compiler-rt/test/asan/TestCases/coverage-reset.cc
Filipe Cabecinhas 91244924cb [ASan] Test churn for setting ASAN_OPTIONS=symbolize_vs_style=false
Summary:
This commit adds symbolize_vs_style=false to every instance of
ASAN_OPTIONS in the asan tests and sets
ASAN_OPTIONS=symbolize_vs_style=false in lit, for tests which don't set
it.

This way we don't need to make the tests be able to deal with both
symbolize styles.

This is the first patch in the series. I will eventually submit for the
other sanitizers too.

We need this change (or another way to deal with the different outputs) in
order to be able to default to symbolize_vs_style=true on some platforms.

Adding to this change, I'm also adding "env " before any command line
which sets environment variables. That way the test works on other host
shells, like we have if the host is running Windows.

Reviewers: samsonov, kcc, rnk

Subscribers: tberghammer, llvm-commits

Differential Revision: http://reviews.llvm.org/D10294

llvm-svn: 239754
2015-06-15 20:43:42 +00:00

53 lines
1.4 KiB
C++

// Test __sanitizer_reset_coverage().
// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t
// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:coverage=1 %run %t
#include <sanitizer/coverage_interface.h>
#include <stdio.h>
#include <assert.h>
static volatile int sink;
__attribute__((noinline)) void bar() { sink = 2; }
__attribute__((noinline)) void foo() { sink = 1; }
#define GET_AND_PRINT_COVERAGE() \
bitset = 0; \
for (size_t i = 0; i < n_guards; i++) \
if (guards[i]) bitset |= 1U << i; \
printf("line %d: bitset %zd total: %zd\n", __LINE__, bitset, \
__sanitizer_get_total_unique_coverage());
#define IS_POWER_OF_TWO(a) ((a & ((a) - 1)) == 0)
int main() {
size_t *guards = 0;
size_t bitset;
size_t n_guards = __sanitizer_get_coverage_guards(&guards);
GET_AND_PRINT_COVERAGE();
size_t main_bit = bitset;
assert(IS_POWER_OF_TWO(main_bit));
foo();
GET_AND_PRINT_COVERAGE();
size_t foo_bit = bitset & ~main_bit;
assert(IS_POWER_OF_TWO(foo_bit));
bar();
GET_AND_PRINT_COVERAGE();
size_t bar_bit = bitset & ~(main_bit | foo_bit);
assert(IS_POWER_OF_TWO(bar_bit));
__sanitizer_reset_coverage();
GET_AND_PRINT_COVERAGE();
assert(bitset == 0);
foo();
GET_AND_PRINT_COVERAGE();
assert(bitset == foo_bit);
bar();
GET_AND_PRINT_COVERAGE();
assert(bitset == (foo_bit | bar_bit));
}