Atlas Runtime
fail.hpp
Go to the documentation of this file.
1 /*
2  * (c) Copyright 2016 Hewlett Packard Enterprise Development LP
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version. This program is
8  * distributed in the hope that it will be useful, but WITHOUT ANY
9  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11  * for more details. You should have received a copy of the GNU Lesser
12  * General Public License along with this program. If not, see
13  * <http://www.gnu.org/licenses/>.
14  */
15 
16 
17 #ifndef FAIL
18 #define FAIL
19 
20 #include <cstdlib>
21 #include <iostream>
22 #include <execinfo.h>
23 #include <atomic>
24 #define FAIL_MAX 100
25 static std::atomic<int> fail_chance(0);
26 inline void fail_program () {
27  if (rand() % FAIL_MAX <= fail_chance.load()){
28  void *array[10];
29  size_t size;
30  char **strings;
31  size_t i;
32 
33  size = backtrace (array, 10);
34  strings = backtrace_symbols (array, size);
35 
36  for (i = 0; i < size; i++)
37  std::cout << strings[i] << "\n";
38  delete (strings);
39  std::exit(0);
40  } else {
41  ++fail_chance;
42  }
43 }
44 #endif
#define FAIL_MAX
Definition: fail.hpp:24
int size(COW_AL *cal)
Definition: cow_array_list.c:183
void fail_program()
Definition: fail.hpp:26