forked from vprover/vampire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtest.cpp
183 lines (155 loc) · 4.35 KB
/
vtest.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* File vtest.cpp.
*
* This file is part of the source code of the software program
* Vampire. It is protected by applicable
* copyright laws.
*
* This source code is distributed under the licence found here
* https://vprover.github.io/license.html
* and in the source directory
*
* In summary, you are allowed to use Vampire for non-commercial
* purposes but not allowed to distribute, modify, copy, create derivatives,
* or use in competitions.
* For other uses of Vampire please contact developers for a different
* licence, which we will make an effort to provide.
*/
/**
* @file vtest.cpp
* Provides main function for the vtest executable which is used for unit testing.
*/
#include "Forwards.hpp"
//#include "Api/ResourceLimits.hpp"
#include "Debug/Tracer.hpp"
#include "Lib/Exception.hpp"
#include "Lib/Environment.hpp"
#include "Lib/Int.hpp"
#include "Lib/Random.hpp"
#include "Lib/Set.hpp"
#include "Lib/Stack.hpp"
#include "Lib/TimeCounter.hpp"
#include "Lib/Timer.hpp"
#include "Lib/List.hpp"
#include "Lib/System.hpp"
#include "Lib/Metaiterators.hpp"
#include "Kernel/Signature.hpp"
#include "Shell/Options.hpp"
#include "Shell/Statistics.hpp"
#include "Test/UnitTesting.hpp"
#if CHECK_LEAKS
#include "Lib/MemoryLeak.hpp"
#endif
using namespace Lib;
using namespace Kernel;
using namespace Test;
UnitList* globUnitList=0;
int globReturnValue = 1;
void explainException (Exception& exception)
{
exception.cry(cout);
} // explainException
void readAndFilterGlobalOpts(Stack<char*>& args) {
Stack<char*>::StableDelIterator it(args);
//skip the first item which is the executable name
ALWAYS(it.hasNext());
it.next();
while(it.hasNext()) {
vstring arg(it.next());
if(arg=="-tr") {
it.del();
if(!it.hasNext()) {
USER_ERROR("value for -tr option expected");
}
vstring traceStr(it.next());
it.del();
//PROCESS_TRACE_SPEC_STRING(traceStr);
}
//this part is added just for testing
else if(arg == "-t") {
it.del();
if(!it.hasNext()){
USER_ERROR("value for timelimit expected");
}
int seconds;
Int::stringToInt(it.next(), seconds);
//Api::ResourceLimits::setLimits(0,seconds*10);
}
else {
break;
}
}
}
int main(int argc, char* argv [])
{
CALL("main");
srand(1); //this is for the reproducibility
//Api::ResourceLimits::disableLimits();
System::registerArgv0(argv[0]);
System::setSignalHandlers();
// create random seed for the random number generation
Lib::Random::setSeed(123456);
Stack<char*> args;
args.loadFromIterator(getArrayishObjectIterator(argv, argc));
readAndFilterGlobalOpts(args);
try {
if(args.size()==1) {
UnitTesting::instance()->runAllTests(cout);
}
else if(args.size()==2 || args.size() == 3) {
if(!strcmp(args[1],"-l")) {
UnitTesting::instance()->printTestNames(cout);
}
else {
if(!UnitTesting::instance()->runTest(args[args.size()-1],cout)) {
cout<<"Unknown test name: "<<args[1]<<endl;
cout<<"Run \""<<args[0]<<" -l\" for the list of available tests."<<endl;
}
}
}
else {
cout<<"Invalid number of arguments ("<<(argc-1)<<")."<<endl;
cout<<"Run \""<<args[0]<<"\" to run all available tests."<<endl;
cout<<"Run \""<<args[0]<<" <test_id>\" to run a single test."<<endl;
cout<<"Run \""<<args[0]<<" -l\" for the list of available tests."<<endl;
}
#if CHECK_LEAKS
if (globUnitList) {
MemoryLeak leak;
leak.release(globUnitList);
}
delete env.signature;
env.signature = 0;
#endif
//if we got here, all went well and we can return 0
globReturnValue = 0;
}
#if VDEBUG
catch (Debug::AssertionViolationException& exception) {
#if CHECK_LEAKS
MemoryLeak::cancelReport();
#endif
}
#endif
catch (UserErrorException& exception) {
#if CHECK_LEAKS
MemoryLeak::cancelReport();
#endif
explainException(exception);
}
catch (Exception& exception) {
#if CHECK_LEAKS
MemoryLeak::cancelReport();
#endif
explainException(exception);
env.statistics->print(cout);
}
catch (std::bad_alloc& _) {
#if CHECK_LEAKS
MemoryLeak::cancelReport();
#endif
cout << "Insufficient system memory" << '\n';
}
// delete env.allocator;
return globReturnValue;
}