From d3ae36fb68c87c8ba5e72c718c5cfbb3e9f071f1 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 9 Oct 2016 00:01:06 -0400 Subject: [PATCH] In tests, do not expect zero-cost mode to catch UAF. Also differentiate pass/faile output and add a `make test` target. --- Makefile | 4 ++++ test.cc | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 87d7be6..935231b 100644 --- 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 --- 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(new C()); zc::ref 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; } } -- 2.22.5