test
suicide.cpp
Go to the documentation of this file.
1
/*
2
* test/suicide.cpp
3
* Copyright 2013 Google Inc. All Rights Reserved.
4
*
5
* Permission is hereby granted, free of charge, to any person obtaining a copy
6
* of this software and associated documentation files (the "Software"), to deal
7
* in the Software without restriction, including without limitation the rights
8
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
* copies of the Software, and to permit persons to whom the Software is
10
* furnished to do so, subject to the following conditions:
11
*
12
* The above copyright notice and this permission notice shall be included in
13
* all copies or substantial portions of the Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
* SOFTWARE.
22
*/
23
24
#include <
backward_ros/backward.hpp
>
25
26
#include <cstdio>
27
#include <sys/resource.h>
28
#include "
test.hpp
"
29
30
using namespace
backward
;
31
32
void
badass_function
()
33
{
34
char
* ptr = (
char
*)42;
35
*ptr = 42;
36
}
37
38
TEST_SEGFAULT
(invalid_write)
39
{
40
badass_function
();
41
}
42
43
int
you_shall_not_pass
()
44
{
45
char
* ptr = (
char
*)42;
46
int
v = *ptr;
47
return
v;
48
}
49
50
TEST_SEGFAULT
(invalid_read)
51
{
52
int
v =
you_shall_not_pass
();
53
std::cout <<
"v="
<< v << std::endl;
54
}
55
56
void
abort_abort_I_repeat_abort_abort
()
57
{
58
std::cout <<
"Jumping off the boat!"
<< std::endl;
59
abort();
60
}
61
62
TEST_ABORT
(calling_abort)
63
{
64
abort_abort_I_repeat_abort_abort
();
65
}
66
67
volatile
int
zero
= 0;
68
69
int
divide_by_zero
()
70
{
71
std::cout <<
"And the wild black hole appears..."
<< std::endl;
72
int
v = 42 /
zero
;
73
return
v;
74
}
75
76
TEST_DIVZERO
(
divide_by_zero
)
77
{
78
int
v =
divide_by_zero
();
79
std::cout <<
"v="
<< v << std::endl;
80
}
81
82
int
bye_bye_stack
(
int
i) {
83
return
bye_bye_stack
(i + 1) +
bye_bye_stack
(i * 2);
84
}
85
86
TEST_SEGFAULT
(stackoverflow)
87
{
88
struct
rlimit limit;
89
limit.rlim_max = 8096;
90
setrlimit(RLIMIT_STACK, &limit);
91
int
r =
bye_bye_stack
(42);
92
std::cout <<
"r="
<< r << std::endl;
93
}
divide_by_zero
int divide_by_zero()
Definition:
suicide.cpp:69
TEST_DIVZERO
TEST_DIVZERO(divide_by_zero)
Definition:
suicide.cpp:76
TEST_SEGFAULT
TEST_SEGFAULT(invalid_write)
Definition:
suicide.cpp:38
badass_function
void badass_function()
Definition:
suicide.cpp:32
backward.hpp
test.hpp
zero
volatile int zero
Definition:
suicide.cpp:67
you_shall_not_pass
int you_shall_not_pass()
Definition:
suicide.cpp:43
bye_bye_stack
int bye_bye_stack(int i)
Definition:
suicide.cpp:82
abort_abort_I_repeat_abort_abort
void abort_abort_I_repeat_abort_abort()
Definition:
suicide.cpp:56
backward
Definition:
backward.hpp:419
TEST_ABORT
TEST_ABORT(calling_abort)
Definition:
suicide.cpp:62
backward_ros
Author(s):
autogenerated on Tue Mar 1 2022 23:50:48