Tests are all passing now.

This commit is contained in:
François-Xavier Bourlet 2013-11-17 22:16:13 -08:00
parent 6bb925fd70
commit e8b6cb2475
16 changed files with 52 additions and 103 deletions

View File

@ -85,7 +85,6 @@ endmacro()
# Tests without backward.cpp
set(TESTS
test
compile
minitrace
smalltrace
simplerecursive

View File

@ -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);
}
};

View File

@ -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) {

View File

@ -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");
}

View File

@ -21,10 +21,6 @@
* SOFTWARE.
*/
//#define BACKWARD_SYSTEN_UNKNOWN
//#define BACKWARD_HAS_UNWIND 0
//#define BACKWARD_CXX98
#include "backward.hpp"
#include <stdio.h>
@ -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;

View File

@ -21,9 +21,6 @@
* SOFTWARE.
*/
//#define BACKWARD_SYSTEN_UNKNOWN
//#define BACKWARD_HAS_UNWIND 1
//#define BACKWARD_CXX98
#include "backward.hpp"
#include <stdio.h>
#include "test/test.hpp"

View File

@ -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 <stdio.h>
@ -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;

View File

@ -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 <stdio.h>
@ -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;

View File

@ -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 <stdio.h>

View File

@ -21,10 +21,6 @@
* SOFTWARE.
*/
//#define BACKWARD_SYSTEN_UNKNOWN
//#define BACKWARD_HAS_UNWIND 0
//#define BACKWARD_CXX98
#include "backward.hpp"
#include <stdio.h>
@ -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;

View File

@ -21,10 +21,6 @@
* SOFTWARE.
*/
//#define BACKWARD_SYSTEN_UNKNOWN
//#define BACKWARD_HAS_UNWIND 0
//#define BACKWARD_CXX98
#include "backward.hpp"
#include <stdio.h>
@ -32,17 +28,15 @@
using namespace backward;
void badass_function()
{
void badass_function() {
char* ptr = (char*)42;
*ptr = 42;
}
TEST (select_signals)
{
std::vector<int> signals;
signals.push_back(SIGSEGV);
SignalHandling sh(signals);
TEST_SEGFAULT (select_signals) {
std::vector<int> signals;
signals.push_back(SIGSEGV);
SignalHandling sh(signals);
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
badass_function();
}

View File

@ -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 <stdio.h>
#include "test/test.hpp"

View File

@ -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 <stdio.h>

View File

@ -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;

View File

@ -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 <stdexcept>
#include <cstdlib>
#include "test/test.hpp"
TEST (empty_test) { }

View File

@ -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<void>(0) \