From c20cc02a86015b1f064e8c083c8c3f6c9202029f Mon Sep 17 00:00:00 2001 From: Mike Aizatsky Date: Tue, 26 Apr 2016 21:56:14 +0000 Subject: [sanitizers] rewriting test assuming assert() changes coverage. Summary: On windows platform assert() call creates two distinct CFG edges which are coverage-instrumented. Simply calling assert would change coverage numbers on the platform. Subscribers: kubabrecka Differential Revision: http://reviews.llvm.org/D19514 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@267610 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/asan/TestCases/coverage-pc-buffer.cc | 62 +++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 19 deletions(-) (limited to 'test') diff --git a/test/asan/TestCases/coverage-pc-buffer.cc b/test/asan/TestCases/coverage-pc-buffer.cc index f1e9b4598..5895a5c45 100644 --- a/test/asan/TestCases/coverage-pc-buffer.cc +++ b/test/asan/TestCases/coverage-pc-buffer.cc @@ -19,23 +19,47 @@ void assertNotZeroPcs(uintptr_t *buf, uintptr_t size) { } int main() { - uintptr_t *buf = NULL; - uintptr_t sz = __sanitizer_get_coverage_pc_buffer(&buf); - assertNotZeroPcs(buf, sz); - assert(sz); - - foo(); - bar(); - uintptr_t *buf1 = NULL; - uintptr_t sz1 = __sanitizer_get_coverage_pc_buffer(&buf1); - assertNotZeroPcs(buf1, sz1); - assert(buf1 == buf); - assert(sz1 > sz); - - __sanitizer_reset_coverage(); - uintptr_t *buf3 = NULL; - uintptr_t sz3 = __sanitizer_get_coverage_pc_buffer(&buf3); - assertNotZeroPcs(buf3, sz3); - assert(buf3 == buf); - assert(sz3 < sz1); + { + uintptr_t *buf = NULL; + uintptr_t sz = __sanitizer_get_coverage_pc_buffer(&buf); + assertNotZeroPcs(buf, sz); + assert(sz); + } + + { + uintptr_t *buf = NULL; + uintptr_t sz = __sanitizer_get_coverage_pc_buffer(&buf); + // call functions for the first time. + foo(); + bar(); + uintptr_t *buf1 = NULL; + uintptr_t sz1 = __sanitizer_get_coverage_pc_buffer(&buf1); + assertNotZeroPcs(buf1, sz1); + assert(buf1 == buf); + assert(sz1 > sz); + } + + { + uintptr_t *buf = NULL; + uintptr_t sz = __sanitizer_get_coverage_pc_buffer(&buf); + // second call shouldn't increase coverage. + bar(); + uintptr_t *buf1 = NULL; + uintptr_t sz1 = __sanitizer_get_coverage_pc_buffer(&buf1); + assertNotZeroPcs(buf1, sz1); + assert(buf1 == buf); + assert(sz1 == sz); + } + + { + uintptr_t *buf = NULL; + uintptr_t sz = __sanitizer_get_coverage_pc_buffer(&buf); + // reset coverage to 0. + __sanitizer_reset_coverage(); + uintptr_t *buf1 = NULL; + uintptr_t sz1 = __sanitizer_get_coverage_pc_buffer(&buf1); + assertNotZeroPcs(buf1, sz1); + assert(buf1 == buf); + assert(sz1 < sz); + } } -- cgit v1.2.3