From e8b6cb2475dceb852b186fa1517d794e6cd887d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Bourlet?= Date: Sun, 17 Nov 2013 22:16:13 -0800 Subject: [PATCH] Tests are all passing now. --- CMakeLists.txt | 1 - backward.hpp | 13 +++++++++++-- test/_test_main.cpp | 7 ++++--- test/compile.cpp | 30 ------------------------------ test/divbyzero.cpp | 6 +----- test/fib.cpp | 3 --- test/invalidread.cpp | 13 +------------ test/invalidread2.cpp | 13 +------------ test/minitrace.cpp | 5 ----- test/segfault.cpp | 6 +----- test/select_signals.cpp | 16 +++++----------- test/simplerecursive.cpp | 7 ------- test/smalltrace.cpp | 6 ------ test/suicide.cpp | 2 +- test/test.cpp | 23 +++++++++++++++++++++++ test/test.hpp | 4 ++++ 16 files changed, 52 insertions(+), 103 deletions(-) delete mode 100644 test/compile.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bee74a..fb334ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,7 +85,6 @@ endmacro() # Tests without backward.cpp set(TESTS test - compile minitrace smalltrace simplerecursive diff --git a/backward.hpp b/backward.hpp index 200356d..dca2be1 100644 --- a/backward.hpp +++ b/backward.hpp @@ -1902,13 +1902,17 @@ public: for (size_t i = 0; i < signals.size(); ++i) { struct sigaction action; - action.sa_flags = SA_SIGINFO | SA_ONSTACK; - sigemptyset(&action.sa_mask); + memset(&action, 0, sizeof action); + action.sa_flags = (SA_SIGINFO | SA_ONSTACK | SA_NODEFER | + SA_RESETHAND); + sigfillset(&action.sa_mask); + sigdelset(&action.sa_mask, signals[i]); action.sa_sigaction = &sig_handler; int r = sigaction(signals[i], &action, 0); if (r < 0) success = false; } + _loaded = success; } @@ -1941,7 +1945,12 @@ private: printer.print(st, stderr); psiginfo(info, 0); + + // try to forward the signal. + raise(info->si_signo); + // terminate the process immediately. + puts("watf? exit"); _exit(EXIT_FAILURE); } }; diff --git a/test/_test_main.cpp b/test/_test_main.cpp index 17c3ea9..b1d30ef 100644 --- a/test/_test_main.cpp +++ b/test/_test_main.cpp @@ -31,7 +31,7 @@ test::test_registry_t test::test_registry; using namespace test; -bool run_test(TestBase::TestBase& test) { +bool run_test(TestBase& test) { printf("-- running test case: %s\n", test.name); fflush(stdout); @@ -64,6 +64,8 @@ bool run_test(TestBase::TestBase& test) { case SIGSEGV: case SIGBUS: status = test::SIGNAL_SEGFAULT; break; + case SIGFPE: + status = test::SIGNAL_DIVZERO; break; default: status = test::SIGNAL_UNCAUGHT; } @@ -79,7 +81,6 @@ bool run_test(TestBase::TestBase& test) { return (status & test::SIGNAL_UNCAUGHT); } - printf("__> %d %d\n", status, test.expected_status); return status == test.expected_status; } @@ -89,7 +90,7 @@ int main(int argc, const char* const argv[]) { size_t total_cnt = 0; for (test_registry_t::iterator it = test_registry.begin(); it != test_registry.end(); ++it) { - TestBase::TestBase& test = **it; + TestBase& test = **it; bool consider_test = (argc <= 1); for (int i = 1; i < argc; ++i) { diff --git a/test/compile.cpp b/test/compile.cpp deleted file mode 100644 index 90b8b1f..0000000 --- a/test/compile.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * test/compile.cpp - * Copyright 2013 Google Inc. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include "test/test.hpp" -#include "backward.hpp" - -TEST(i_can_compile) { - printf("Wow, I'am compiled!\n"); -} diff --git a/test/divbyzero.cpp b/test/divbyzero.cpp index 32b52b9..cf8ecce 100644 --- a/test/divbyzero.cpp +++ b/test/divbyzero.cpp @@ -21,10 +21,6 @@ * SOFTWARE. */ -//#define BACKWARD_SYSTEN_UNKNOWN -//#define BACKWARD_HAS_UNWIND 0 -//#define BACKWARD_CXX98 - #include "backward.hpp" #include @@ -41,7 +37,7 @@ int divide_by_zero() return v; } -TEST (invalid_read) +TEST_DIVZERO (invalid_read) { SignalHandling sh; std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl; diff --git a/test/fib.cpp b/test/fib.cpp index b9ca18c..a6d5207 100644 --- a/test/fib.cpp +++ b/test/fib.cpp @@ -21,9 +21,6 @@ * SOFTWARE. */ -//#define BACKWARD_SYSTEN_UNKNOWN -//#define BACKWARD_HAS_UNWIND 1 -//#define BACKWARD_CXX98 #include "backward.hpp" #include #include "test/test.hpp" diff --git a/test/invalidread.cpp b/test/invalidread.cpp index 947a75b..f011b2e 100644 --- a/test/invalidread.cpp +++ b/test/invalidread.cpp @@ -21,17 +21,6 @@ * SOFTWARE. */ -//#define BACKWARD_SYSTEM_UNKNOWN - -//#define BACKWARD_HAS_UNWIND 1 -//#define BACKWARD_HAS_BACKTRACE 1 - -//#define BACKWARD_HAS_DW 1 -//#define BACKWARD_HAS_BFD 1 -//#define BACKWARD_HAS_BACKTRACE_SYMBOL 1 - -//#define BACKWARD_CXX98 - #include "backward.hpp" #include @@ -46,7 +35,7 @@ int you_shall_not_pass() return v; } -TEST (invalid_read) +TEST_SEGFAULT (invalid_read) { SignalHandling sh; std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl; diff --git a/test/invalidread2.cpp b/test/invalidread2.cpp index 7c3935d..30ee0e8 100644 --- a/test/invalidread2.cpp +++ b/test/invalidread2.cpp @@ -21,17 +21,6 @@ * SOFTWARE. */ -//#define BACKWARD_SYSTEM_UNKNOWN - -//#define BACKWARD_HAS_UNWIND 1 -//#define BACKWARD_HAS_BACKTRACE 1 - -//#define BACKWARD_HAS_DW 1 -//#define BACKWARD_HAS_BFD 1 -//#define BACKWARD_HAS_BACKTRACE_SYMBOL 1 - -//#define BACKWARD_CXX98 - #include "backward.hpp" #include @@ -46,7 +35,7 @@ int you_shall_not_pass() return v; } -TEST(invalid_read2) +TEST_SEGFAULT(invalid_read2) { int v = you_shall_not_pass(); std::cout << "v=" << v << std::endl; diff --git a/test/minitrace.cpp b/test/minitrace.cpp index f436c63..ec85c97 100644 --- a/test/minitrace.cpp +++ b/test/minitrace.cpp @@ -21,11 +21,6 @@ * SOFTWARE. */ -//#define BACKWARD_SYSTEN_UNKNOWN -#define BACKWARD_HAS_DW 1 -//#define BACKWARD_HAS_BFD 0 -//#define BACKWARD_CXX98 - #include "backward.hpp" #include diff --git a/test/segfault.cpp b/test/segfault.cpp index 18f4f2e..4553bd2 100644 --- a/test/segfault.cpp +++ b/test/segfault.cpp @@ -21,10 +21,6 @@ * SOFTWARE. */ -//#define BACKWARD_SYSTEN_UNKNOWN -//#define BACKWARD_HAS_UNWIND 0 -//#define BACKWARD_CXX98 - #include "backward.hpp" #include @@ -38,7 +34,7 @@ void badass_function() *ptr = 42; } -TEST (invalid_write) +TEST_SEGFAULT (invalid_write) { SignalHandling sh; std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl; diff --git a/test/select_signals.cpp b/test/select_signals.cpp index 7b53344..64fea81 100644 --- a/test/select_signals.cpp +++ b/test/select_signals.cpp @@ -21,10 +21,6 @@ * SOFTWARE. */ -//#define BACKWARD_SYSTEN_UNKNOWN -//#define BACKWARD_HAS_UNWIND 0 -//#define BACKWARD_CXX98 - #include "backward.hpp" #include @@ -32,17 +28,15 @@ using namespace backward; -void badass_function() -{ +void badass_function() { char* ptr = (char*)42; *ptr = 42; } -TEST (select_signals) -{ - std::vector signals; - signals.push_back(SIGSEGV); - SignalHandling sh(signals); +TEST_SEGFAULT (select_signals) { + std::vector signals; + signals.push_back(SIGSEGV); + SignalHandling sh(signals); std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl; badass_function(); } diff --git a/test/simplerecursive.cpp b/test/simplerecursive.cpp index 045f7bc..b73a8e8 100644 --- a/test/simplerecursive.cpp +++ b/test/simplerecursive.cpp @@ -21,13 +21,6 @@ * SOFTWARE. */ -//#define BACKWARD_HAS_UNWIND 1 -//#define BACKWARD_SYSTEN_UNKNOWN -#define BACKWARD_HAS_DW 1 -//#define BACKWARD_HAS_BFD 1 -//#define BACKWARD_HAS_BACKTRACE_SYMBOL 1 -//#define BACKWARD_HAS_BACKTRACE 1 -//#define BACKWARD_CXX98 #include "backward.hpp" #include #include "test/test.hpp" diff --git a/test/smalltrace.cpp b/test/smalltrace.cpp index 384b061..07b7f1c 100644 --- a/test/smalltrace.cpp +++ b/test/smalltrace.cpp @@ -21,12 +21,6 @@ * SOFTWARE. */ -//#define BACKWARD_SYSTEN_UNKNOWN -//#define BACKWARD_HAS_UNWIND 0 -//#define BACKWARD_HAS_DW 1 -#define BACKWARD_HAS_BFD 1 -//#define BACKWARD_CXX98 - #include "backward.hpp" #include diff --git a/test/suicide.cpp b/test/suicide.cpp index d51388c..6be62bd 100644 --- a/test/suicide.cpp +++ b/test/suicide.cpp @@ -38,7 +38,7 @@ void abort_abort_I_repeat_abort_abort() abort(); } -TEST (invalid_read) +TEST_ABORT (invalid_read) { SignalHandling sh; std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl; diff --git a/test/test.cpp b/test/test.cpp index c045b5f..6c5bbff 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,6 +1,29 @@ +/* + * test/test.cpp + * Copyright 2013 Google Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ #include #include +#include #include "test/test.hpp" TEST (empty_test) { } diff --git a/test/test.hpp b/test/test.hpp index 5958ce8..fa0d224 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -35,6 +35,8 @@ namespace test { struct AssertFailedError: std::exception { + ~AssertFailedError() throw() {} + AssertFailedError(const char* filename, int line, const char* errmsg): basename(_basename(filename)), line(line), errmsg(errmsg) {} @@ -72,6 +74,7 @@ enum TestStatus { SIGNAL_UNCAUGHT = FAILED | 3<<1, SIGNAL_SEGFAULT = SIGNAL_UNCAUGHT | 1<<3, SIGNAL_ABORT = SIGNAL_UNCAUGHT | 2<<3, + SIGNAL_DIVZERO = SIGNAL_UNCAUGHT | 2<<3, STATUS_MASK = 0x1F }; @@ -124,6 +127,7 @@ TestBase::TestBase(const char* n, TestStatus s): name(n), expected_status(s) { #define TEST_UNCAUGHT_SIGNAL(name) _TEST_STATUS(name, ::test::SIGNAL_UNCAUGHT) #define TEST_SEGFAULT(name) _TEST_STATUS(name, ::test::SIGNAL_SEGFAULT) #define TEST_ABORT(name) _TEST_STATUS(name, ::test::SIGNAL_ABORT) +#define TEST_DIVZERO(name) _TEST_STATUS(name, ::test::SIGNAL_DIVZERO) #define ASSERT(expr) \ (expr) ? static_cast(0) \