mirror of
https://github.com/QuasarApp/backward-cpp.git
synced 2025-04-30 04:14:30 +00:00
Tests are all passing now.
This commit is contained in:
parent
6bb925fd70
commit
e8b6cb2475
@ -85,7 +85,6 @@ endmacro()
|
|||||||
# Tests without backward.cpp
|
# Tests without backward.cpp
|
||||||
set(TESTS
|
set(TESTS
|
||||||
test
|
test
|
||||||
compile
|
|
||||||
minitrace
|
minitrace
|
||||||
smalltrace
|
smalltrace
|
||||||
simplerecursive
|
simplerecursive
|
||||||
|
13
backward.hpp
13
backward.hpp
@ -1902,13 +1902,17 @@ public:
|
|||||||
|
|
||||||
for (size_t i = 0; i < signals.size(); ++i) {
|
for (size_t i = 0; i < signals.size(); ++i) {
|
||||||
struct sigaction action;
|
struct sigaction action;
|
||||||
action.sa_flags = SA_SIGINFO | SA_ONSTACK;
|
memset(&action, 0, sizeof action);
|
||||||
sigemptyset(&action.sa_mask);
|
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;
|
action.sa_sigaction = &sig_handler;
|
||||||
|
|
||||||
int r = sigaction(signals[i], &action, 0);
|
int r = sigaction(signals[i], &action, 0);
|
||||||
if (r < 0) success = false;
|
if (r < 0) success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_loaded = success;
|
_loaded = success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1941,7 +1945,12 @@ private:
|
|||||||
printer.print(st, stderr);
|
printer.print(st, stderr);
|
||||||
|
|
||||||
psiginfo(info, 0);
|
psiginfo(info, 0);
|
||||||
|
|
||||||
|
// try to forward the signal.
|
||||||
|
raise(info->si_signo);
|
||||||
|
|
||||||
// terminate the process immediately.
|
// terminate the process immediately.
|
||||||
|
puts("watf? exit");
|
||||||
_exit(EXIT_FAILURE);
|
_exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
test::test_registry_t test::test_registry;
|
test::test_registry_t test::test_registry;
|
||||||
using namespace test;
|
using namespace test;
|
||||||
|
|
||||||
bool run_test(TestBase::TestBase& test) {
|
bool run_test(TestBase& test) {
|
||||||
printf("-- running test case: %s\n", test.name);
|
printf("-- running test case: %s\n", test.name);
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@ -64,6 +64,8 @@ bool run_test(TestBase::TestBase& test) {
|
|||||||
case SIGSEGV:
|
case SIGSEGV:
|
||||||
case SIGBUS:
|
case SIGBUS:
|
||||||
status = test::SIGNAL_SEGFAULT; break;
|
status = test::SIGNAL_SEGFAULT; break;
|
||||||
|
case SIGFPE:
|
||||||
|
status = test::SIGNAL_DIVZERO; break;
|
||||||
default:
|
default:
|
||||||
status = test::SIGNAL_UNCAUGHT;
|
status = test::SIGNAL_UNCAUGHT;
|
||||||
}
|
}
|
||||||
@ -79,7 +81,6 @@ bool run_test(TestBase::TestBase& test) {
|
|||||||
return (status & test::SIGNAL_UNCAUGHT);
|
return (status & test::SIGNAL_UNCAUGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("__> %d %d\n", status, test.expected_status);
|
|
||||||
return 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;
|
size_t total_cnt = 0;
|
||||||
for (test_registry_t::iterator it = test_registry.begin();
|
for (test_registry_t::iterator it = test_registry.begin();
|
||||||
it != test_registry.end(); ++it) {
|
it != test_registry.end(); ++it) {
|
||||||
TestBase::TestBase& test = **it;
|
TestBase& test = **it;
|
||||||
|
|
||||||
bool consider_test = (argc <= 1);
|
bool consider_test = (argc <= 1);
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
|
@ -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 <stdio.h>
|
|
||||||
#include "test/test.hpp"
|
|
||||||
#include "backward.hpp"
|
|
||||||
|
|
||||||
TEST(i_can_compile) {
|
|
||||||
printf("Wow, I'am compiled!\n");
|
|
||||||
}
|
|
@ -21,10 +21,6 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#define BACKWARD_SYSTEN_UNKNOWN
|
|
||||||
//#define BACKWARD_HAS_UNWIND 0
|
|
||||||
//#define BACKWARD_CXX98
|
|
||||||
|
|
||||||
#include "backward.hpp"
|
#include "backward.hpp"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -41,7 +37,7 @@ int divide_by_zero()
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST (invalid_read)
|
TEST_DIVZERO (invalid_read)
|
||||||
{
|
{
|
||||||
SignalHandling sh;
|
SignalHandling sh;
|
||||||
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
||||||
|
@ -21,9 +21,6 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#define BACKWARD_SYSTEN_UNKNOWN
|
|
||||||
//#define BACKWARD_HAS_UNWIND 1
|
|
||||||
//#define BACKWARD_CXX98
|
|
||||||
#include "backward.hpp"
|
#include "backward.hpp"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "test/test.hpp"
|
#include "test/test.hpp"
|
||||||
|
@ -21,17 +21,6 @@
|
|||||||
* SOFTWARE.
|
* 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 "backward.hpp"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -46,7 +35,7 @@ int you_shall_not_pass()
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST (invalid_read)
|
TEST_SEGFAULT (invalid_read)
|
||||||
{
|
{
|
||||||
SignalHandling sh;
|
SignalHandling sh;
|
||||||
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
||||||
|
@ -21,17 +21,6 @@
|
|||||||
* SOFTWARE.
|
* 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 "backward.hpp"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -46,7 +35,7 @@ int you_shall_not_pass()
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(invalid_read2)
|
TEST_SEGFAULT(invalid_read2)
|
||||||
{
|
{
|
||||||
int v = you_shall_not_pass();
|
int v = you_shall_not_pass();
|
||||||
std::cout << "v=" << v << std::endl;
|
std::cout << "v=" << v << std::endl;
|
||||||
|
@ -21,11 +21,6 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#define BACKWARD_SYSTEN_UNKNOWN
|
|
||||||
#define BACKWARD_HAS_DW 1
|
|
||||||
//#define BACKWARD_HAS_BFD 0
|
|
||||||
//#define BACKWARD_CXX98
|
|
||||||
|
|
||||||
#include "backward.hpp"
|
#include "backward.hpp"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -21,10 +21,6 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#define BACKWARD_SYSTEN_UNKNOWN
|
|
||||||
//#define BACKWARD_HAS_UNWIND 0
|
|
||||||
//#define BACKWARD_CXX98
|
|
||||||
|
|
||||||
#include "backward.hpp"
|
#include "backward.hpp"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -38,7 +34,7 @@ void badass_function()
|
|||||||
*ptr = 42;
|
*ptr = 42;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST (invalid_write)
|
TEST_SEGFAULT (invalid_write)
|
||||||
{
|
{
|
||||||
SignalHandling sh;
|
SignalHandling sh;
|
||||||
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
||||||
|
@ -21,10 +21,6 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#define BACKWARD_SYSTEN_UNKNOWN
|
|
||||||
//#define BACKWARD_HAS_UNWIND 0
|
|
||||||
//#define BACKWARD_CXX98
|
|
||||||
|
|
||||||
#include "backward.hpp"
|
#include "backward.hpp"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -32,17 +28,15 @@
|
|||||||
|
|
||||||
using namespace backward;
|
using namespace backward;
|
||||||
|
|
||||||
void badass_function()
|
void badass_function() {
|
||||||
{
|
|
||||||
char* ptr = (char*)42;
|
char* ptr = (char*)42;
|
||||||
*ptr = 42;
|
*ptr = 42;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST (select_signals)
|
TEST_SEGFAULT (select_signals) {
|
||||||
{
|
std::vector<int> signals;
|
||||||
std::vector<int> signals;
|
signals.push_back(SIGSEGV);
|
||||||
signals.push_back(SIGSEGV);
|
SignalHandling sh(signals);
|
||||||
SignalHandling sh(signals);
|
|
||||||
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
||||||
badass_function();
|
badass_function();
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,6 @@
|
|||||||
* SOFTWARE.
|
* 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 "backward.hpp"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "test/test.hpp"
|
#include "test/test.hpp"
|
||||||
|
@ -21,12 +21,6 @@
|
|||||||
* SOFTWARE.
|
* 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 "backward.hpp"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -38,7 +38,7 @@ void abort_abort_I_repeat_abort_abort()
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST (invalid_read)
|
TEST_ABORT (invalid_read)
|
||||||
{
|
{
|
||||||
SignalHandling sh;
|
SignalHandling sh;
|
||||||
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
||||||
|
@ -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 <iostream>
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <cstdlib>
|
||||||
#include "test/test.hpp"
|
#include "test/test.hpp"
|
||||||
|
|
||||||
TEST (empty_test) { }
|
TEST (empty_test) { }
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
namespace test {
|
namespace test {
|
||||||
|
|
||||||
struct AssertFailedError: std::exception {
|
struct AssertFailedError: std::exception {
|
||||||
|
~AssertFailedError() throw() {}
|
||||||
|
|
||||||
AssertFailedError(const char* filename, int line, const char* errmsg):
|
AssertFailedError(const char* filename, int line, const char* errmsg):
|
||||||
basename(_basename(filename)), line(line), errmsg(errmsg) {}
|
basename(_basename(filename)), line(line), errmsg(errmsg) {}
|
||||||
|
|
||||||
@ -72,6 +74,7 @@ enum TestStatus {
|
|||||||
SIGNAL_UNCAUGHT = FAILED | 3<<1,
|
SIGNAL_UNCAUGHT = FAILED | 3<<1,
|
||||||
SIGNAL_SEGFAULT = SIGNAL_UNCAUGHT | 1<<3,
|
SIGNAL_SEGFAULT = SIGNAL_UNCAUGHT | 1<<3,
|
||||||
SIGNAL_ABORT = SIGNAL_UNCAUGHT | 2<<3,
|
SIGNAL_ABORT = SIGNAL_UNCAUGHT | 2<<3,
|
||||||
|
SIGNAL_DIVZERO = SIGNAL_UNCAUGHT | 2<<3,
|
||||||
|
|
||||||
STATUS_MASK = 0x1F
|
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_UNCAUGHT_SIGNAL(name) _TEST_STATUS(name, ::test::SIGNAL_UNCAUGHT)
|
||||||
#define TEST_SEGFAULT(name) _TEST_STATUS(name, ::test::SIGNAL_SEGFAULT)
|
#define TEST_SEGFAULT(name) _TEST_STATUS(name, ::test::SIGNAL_SEGFAULT)
|
||||||
#define TEST_ABORT(name) _TEST_STATUS(name, ::test::SIGNAL_ABORT)
|
#define TEST_ABORT(name) _TEST_STATUS(name, ::test::SIGNAL_ABORT)
|
||||||
|
#define TEST_DIVZERO(name) _TEST_STATUS(name, ::test::SIGNAL_DIVZERO)
|
||||||
|
|
||||||
#define ASSERT(expr) \
|
#define ASSERT(expr) \
|
||||||
(expr) ? static_cast<void>(0) \
|
(expr) ? static_cast<void>(0) \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user