mirror of
https://github.com/QuasarApp/backward-cpp.git
synced 2025-05-13 09:59:43 +00:00
Tests refactored onto less files.
This commit is contained in:
parent
e8b6cb2475
commit
246fd67b34
@ -85,14 +85,8 @@ endmacro()
|
||||
# Tests without backward.cpp
|
||||
set(TESTS
|
||||
test
|
||||
minitrace
|
||||
smalltrace
|
||||
simplerecursive
|
||||
fib
|
||||
segfault
|
||||
invalidread
|
||||
suicide
|
||||
divbyzero
|
||||
stacktrace
|
||||
rectrace
|
||||
select_signals
|
||||
)
|
||||
|
||||
@ -102,7 +96,7 @@ endforeach()
|
||||
|
||||
# Tests with backward.cpp
|
||||
set(TESTS
|
||||
invalidread2
|
||||
suicide
|
||||
)
|
||||
|
||||
foreach(test ${TESTS})
|
||||
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* test/divbyzero.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 "backward.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "test/test.hpp"
|
||||
|
||||
using namespace backward;
|
||||
|
||||
volatile int zero = 0;
|
||||
|
||||
int divide_by_zero()
|
||||
{
|
||||
std::cout << "And the wild black hole appears..." << std::endl;
|
||||
int v = 42 / zero;
|
||||
return v;
|
||||
}
|
||||
|
||||
TEST_DIVZERO (invalid_read)
|
||||
{
|
||||
SignalHandling sh;
|
||||
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
||||
int v = divide_by_zero();
|
||||
std::cout << "v=" << v << std::endl;
|
||||
}
|
58
test/fib.cpp
58
test/fib.cpp
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* test/fib.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 "backward.hpp"
|
||||
#include <stdio.h>
|
||||
#include "test/test.hpp"
|
||||
|
||||
using namespace backward;
|
||||
|
||||
int some_counter;
|
||||
|
||||
void end_of_our_journey(StackTrace& st) {
|
||||
if (not st.size()) {
|
||||
st.load_here();
|
||||
}
|
||||
}
|
||||
|
||||
int fib(StackTrace& st, int level) {
|
||||
if (level == 2) {
|
||||
return 1;
|
||||
}
|
||||
if (level <= 1) {
|
||||
end_of_our_journey(st);
|
||||
return 0;
|
||||
}
|
||||
return fib(st, level - 1) + fib(st, level - 2);
|
||||
}
|
||||
|
||||
TEST (fibrecursive) {
|
||||
StackTrace st;
|
||||
const int input = 6;
|
||||
int r = fib(st, input);
|
||||
|
||||
std::cout << "fib(" << input << ") == " << r << std::endl;
|
||||
|
||||
Printer printer;
|
||||
printer.print(st, stdout);
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* test/invalidread.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 "backward.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "test/test.hpp"
|
||||
|
||||
using namespace backward;
|
||||
|
||||
int you_shall_not_pass()
|
||||
{
|
||||
char* ptr = (char*)42;
|
||||
int v = *ptr;
|
||||
return v;
|
||||
}
|
||||
|
||||
TEST_SEGFAULT (invalid_read)
|
||||
{
|
||||
SignalHandling sh;
|
||||
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
||||
int v = you_shall_not_pass();
|
||||
std::cout << "v=" << v << std::endl;
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* test/invalidread2.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 "backward.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "test/test.hpp"
|
||||
|
||||
using namespace backward;
|
||||
|
||||
int you_shall_not_pass()
|
||||
{
|
||||
char* ptr = (char*)42;
|
||||
int v = *ptr;
|
||||
return v;
|
||||
}
|
||||
|
||||
TEST_SEGFAULT(invalid_read2)
|
||||
{
|
||||
int v = you_shall_not_pass();
|
||||
std::cout << "v=" << v << std::endl;
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* test/minitrace.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 "backward.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "test/test.hpp"
|
||||
|
||||
using namespace backward;
|
||||
|
||||
void collect_trace(StackTrace& st) {
|
||||
st.load_here();
|
||||
}
|
||||
|
||||
TEST (minitrace) {
|
||||
StackTrace st;
|
||||
collect_trace(st);
|
||||
|
||||
Printer printer;
|
||||
printer.print(st, stdout);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* test/simplerecursive.cpp
|
||||
* test/rectrace.cpp
|
||||
* Copyright 2013 Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
@ -27,8 +27,6 @@
|
||||
|
||||
using namespace backward;
|
||||
|
||||
int some_counter;
|
||||
|
||||
typedef StackTrace stacktrace_t;
|
||||
|
||||
void end_of_our_journey(stacktrace_t& st) {
|
||||
@ -63,7 +61,7 @@ namespace titi {
|
||||
|
||||
} // namespace toto
|
||||
|
||||
TEST (simplerecursive) {
|
||||
TEST (recursion) {
|
||||
{ // lexical scope.
|
||||
stacktrace_t st;
|
||||
const int input = 3;
|
||||
@ -77,3 +75,25 @@ TEST (simplerecursive) {
|
||||
printer.print(st, stdout);
|
||||
}
|
||||
}
|
||||
|
||||
int fib(StackTrace& st, int level) {
|
||||
if (level == 2) {
|
||||
return 1;
|
||||
}
|
||||
if (level <= 1) {
|
||||
end_of_our_journey(st);
|
||||
return 0;
|
||||
}
|
||||
return fib(st, level - 1) + fib(st, level - 2);
|
||||
}
|
||||
|
||||
TEST (fibrecursive) {
|
||||
StackTrace st;
|
||||
const int input = 6;
|
||||
int r = fib(st, input);
|
||||
|
||||
std::cout << "fib(" << input << ") == " << r << std::endl;
|
||||
|
||||
Printer printer;
|
||||
printer.print(st, stdout);
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* test/segfault.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 "backward.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "test/test.hpp"
|
||||
|
||||
using namespace backward;
|
||||
|
||||
void badass_function()
|
||||
{
|
||||
char* ptr = (char*)42;
|
||||
*ptr = 42;
|
||||
}
|
||||
|
||||
TEST_SEGFAULT (invalid_write)
|
||||
{
|
||||
SignalHandling sh;
|
||||
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
||||
badass_function();
|
||||
}
|
@ -33,10 +33,18 @@ void badass_function() {
|
||||
*ptr = 42;
|
||||
}
|
||||
|
||||
TEST_SEGFAULT (select_signals) {
|
||||
TEST_SEGFAULT (pprint_sigsev) {
|
||||
std::vector<int> signals;
|
||||
signals.push_back(SIGSEGV);
|
||||
SignalHandling sh(signals);
|
||||
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
||||
badass_function();
|
||||
}
|
||||
|
||||
TEST_SEGFAULT (wont_pprint) {
|
||||
std::vector<int> signals;
|
||||
signals.push_back(SIGABRT);
|
||||
SignalHandling sh(signals);
|
||||
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
||||
badass_function();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* test/smalltrace.cpp
|
||||
* test/stacktrace.cpp
|
||||
* Copyright 2013 Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
@ -22,35 +22,41 @@
|
||||
*/
|
||||
|
||||
#include "backward.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <cstdio>
|
||||
#include "test/test.hpp"
|
||||
|
||||
using namespace backward;
|
||||
|
||||
void d(StackTrace& st)
|
||||
{
|
||||
void collect_trace(StackTrace& st) {
|
||||
st.load_here();
|
||||
}
|
||||
|
||||
void c(StackTrace& st)
|
||||
{
|
||||
TEST (minitrace) {
|
||||
StackTrace st;
|
||||
collect_trace(st);
|
||||
|
||||
Printer printer;
|
||||
printer.print(st, stdout);
|
||||
}
|
||||
|
||||
void d(StackTrace& st) {
|
||||
st.load_here();
|
||||
}
|
||||
|
||||
void c(StackTrace& st) {
|
||||
return d(st);
|
||||
}
|
||||
|
||||
void b(StackTrace& st)
|
||||
{
|
||||
void b(StackTrace& st) {
|
||||
return c(st);
|
||||
}
|
||||
|
||||
__attribute__ ((noinline))
|
||||
void a(StackTrace& st)
|
||||
{
|
||||
void a(StackTrace& st) {
|
||||
return b(st);
|
||||
}
|
||||
|
||||
TEST (smalltrace)
|
||||
{
|
||||
TEST (smalltrace) {
|
||||
StackTrace st;
|
||||
a(st);
|
||||
|
@ -21,10 +21,6 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
//#define BACKWARD_SYSTEN_UNKNOWN
|
||||
//#define BACKWARD_HAS_UNWIND 0
|
||||
//#define BACKWARD_CXX98
|
||||
|
||||
#include "backward.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
@ -32,15 +28,52 @@
|
||||
|
||||
using namespace backward;
|
||||
|
||||
void badass_function()
|
||||
{
|
||||
char* ptr = (char*)42;
|
||||
*ptr = 42;
|
||||
}
|
||||
|
||||
TEST_SEGFAULT (invalid_write)
|
||||
{
|
||||
badass_function();
|
||||
}
|
||||
|
||||
int you_shall_not_pass()
|
||||
{
|
||||
char* ptr = (char*)42;
|
||||
int v = *ptr;
|
||||
return v;
|
||||
}
|
||||
|
||||
TEST_SEGFAULT(invalid_read)
|
||||
{
|
||||
int v = you_shall_not_pass();
|
||||
std::cout << "v=" << v << std::endl;
|
||||
}
|
||||
|
||||
void abort_abort_I_repeat_abort_abort()
|
||||
{
|
||||
std::cout << "Jumping off the boat!" << std::endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
TEST_ABORT (invalid_read)
|
||||
TEST_ABORT (calling_abort)
|
||||
{
|
||||
SignalHandling sh;
|
||||
std::cout << std::boolalpha << "sh.loaded() == " << sh.loaded() << std::endl;
|
||||
abort_abort_I_repeat_abort_abort();
|
||||
}
|
||||
|
||||
volatile int zero = 0;
|
||||
|
||||
int divide_by_zero()
|
||||
{
|
||||
std::cout << "And the wild black hole appears..." << std::endl;
|
||||
int v = 42 / zero;
|
||||
return v;
|
||||
}
|
||||
|
||||
TEST_DIVZERO (divide_by_zero)
|
||||
{
|
||||
int v = divide_by_zero();
|
||||
std::cout << "v=" << v << std::endl;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user