-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
133 lines (106 loc) · 2.86 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <atomic>
#include <csignal>
#include <cstdlib>
#include <exception>
#include <iostream>
#include <thread>
//#include <pthread.h>
#include <sys/syscall.h>
#include <unistd.h>
namespace execinfo
{
#include <execinfo.h>
};
using std::cerr;
using std::cout;
using std::endl;
using std::set_terminate;
using std::exception;
#define DEBUG
#include "collections.hh"
#include "errors.hh"
#include "formula.hh"
#include "sequent.hh"
#include "sync.hh"
#include "unionfind.hh"
using namespace Logical;
volatile atomic_size_t Logical::max_thread_count(std::thread::hardware_concurrency() * 2);
//volatile atomic_size_t Logical::max_thread_count(1);
volatile sig_atomic_t Logical::thread_error(false);
extern "C" void signal_received(int sig_num)
{
Logical::thread_error = true;
}
#ifdef DEBUG
static constexpr size_t segfault_stack_max = 256;
void* segfault_stack[segfault_stack_max];
#endif
extern "C" void segfault_received(int sig_num)
{
Logical::thread_error = true;
#ifdef DEBUG
size_t stack_size = execinfo::backtrace(segfault_stack, segfault_stack_max);
char** stack_trace = execinfo::backtrace_symbols(segfault_stack, stack_size);
for(size_t i = 0; i < stack_size; i++)
cout << " " << stack_trace[i] << endl;
#endif
abort();
}
#ifdef DEBUG
mutex Formula::active_objects_mutex;
unordered_set<const Formula*> Formula::active_objects = unordered_set<const Formula*>();
#endif
int main(int argc, char* argv[])
{
signal(SIGTERM, signal_received);
signal(SIGABRT, signal_received);
signal(SIGSEGV, segfault_received);
try
{
cout << "max thread count (0 = unlimited): " << max_thread_count << endl;
//cout << "sync_test" << endl;
//sync_test();
cout << "collections_test" << endl;
collections_test();
cout << "unionfind_test" << endl;
unionfind_test();
cout << "expression_test" << endl;
expression_test();
#ifdef DEBUG
logical_assert(Formula::active_objects.empty());
#endif
cout << "formula_test" << endl;
formula_test();
#ifdef DEBUG
logical_assert(Formula::active_objects.empty());
#endif
cout << "sequent_test" << endl;
sequent_test();
#ifdef DEBUG
logical_assert(Formula::active_objects.empty());
#endif
}
catch(const AssertionError& error)
{
cout << error.file << ":" << error.line << ": AssertionError " << error.message << endl;
// char** stack_trace = execinfo::backtrace_symbols(error.stack, error.stack_size);
// for(size_t i = 0; i < error.stack_size; i++)
// cout << " " << stack_trace[i] << endl;
}
catch(const Error& error)
{
cout << "Error " << error.message << endl;
char** stack_trace = execinfo::backtrace_symbols(error.stack, error.stack_size);
for(size_t i = 0; i < error.stack_size; i++)
cout << " " << stack_trace[i] << endl;
}
catch(const exception& error)
{
cout << "System exception: " << error.what() << endl;
}
catch(...)
{
cout << "Unknown exception" << endl;
}
return 0;
}