In tests, do not expect zero-cost mode to catch UAF.
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 9 Oct 2016 04:01:06 +0000 (00:01 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 9 Oct 2016 04:01:43 +0000 (00:01 -0400)
Also differentiate pass/faile output and add a `make test` target.

Makefile
test.cc

index 87d7be6..935231b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,10 @@ FILES := test.cc zcpointer.cc
 
 all: test-zc test-tr
 
+test: test-zc test-tr
+       ./test-zc
+       ./test-tr
+
 test-zc: $(FILES) zcpointer.h
        $(CXX) $(CXXFLAGS) $(FILES) -o $@
 
diff --git a/test.cc b/test.cc
index 2d43d3f..8769f4c 100644 (file)
--- a/test.cc
+++ b/test.cc
@@ -26,6 +26,8 @@ class C {
 
 #define EXPECT(expr) do { if (!(expr)) { throw std::logic_error(#expr); } } while(0)
 
+#if defined(ZCPOINTER_TRACK_REFS) && ZCPOINTER_TRACK_REFS
+
 #define EXPECT_UAF(expr) do { \
     try { \
       (expr); \
@@ -33,6 +35,15 @@ class C {
     } catch (zc::UseAfterFreeError) {} \
   } while(0)
 
+#else
+
+#define EXPECT_UAF(expr) do { \
+    std::cout << ">>> ZCPOINTER_TRACK_REFS not enabled, cannot catch UAF" << std::endl; \
+    (expr); \
+  } while(0)
+
+#endif
+
 void TestReset() {
   zc::owned<C> c(new C());
   zc::ref<C> owned = c.get();
@@ -164,10 +175,10 @@ int main() {
     std::cout << "=== BEGIN " << test.name << " ===" << std::endl;
     try {
       test.test();
-      std::cout << "=== PASS " << test.name << " ===" << std::endl;
+      std::cout << "+++ PASS " << test.name << " +++" << std::endl;
     } catch (const std::logic_error& e) {
       passed = false;
-      std::cout << "=== FAIL " << test.name
+      std::cout << "!!! FAIL " << test.name
                 << ": Assertion failure: " << e.what() << " ===" << std::endl;
     }
   }