[compiler-rt] r267610 - [sanitizers] rewriting test assuming assert() changes coverage.

Mike Aizatsky via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 26 14:56:14 PDT 2016


Author: aizatsky
Date: Tue Apr 26 16:56:14 2016
New Revision: 267610

URL: http://llvm.org/viewvc/llvm-project?rev=267610&view=rev
Log:
[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

Modified:
    compiler-rt/trunk/test/asan/TestCases/coverage-pc-buffer.cc

Modified: compiler-rt/trunk/test/asan/TestCases/coverage-pc-buffer.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/coverage-pc-buffer.cc?rev=267610&r1=267609&r2=267610&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/coverage-pc-buffer.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/coverage-pc-buffer.cc Tue Apr 26 16:56:14 2016
@@ -19,23 +19,47 @@ void assertNotZeroPcs(uintptr_t *buf, ui
 }
 
 int main() {
-  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);
+    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);
+  {
+    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);
+  }
 
-  __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);
+    // 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);
+  }
 }




More information about the llvm-commits mailing list