forked from flamingoen/qspin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverificationrun.cpp
236 lines (195 loc) · 8.73 KB
/
verificationrun.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include "verificationrun.h"
/* TODO list for verification
* merge med verification output (hvorfor have to?)
* tilføje en error list, der fortæller hvilke fejl man har
* Husk exception handling til at (især vores regex)
* SMID I TRY CATCH - hvis der sker en fejl, indsæt fejl i SPINVER label hvor der står at man bliver nødt til at bruge rawlog
* Tilføj en remove ltl knap
*/
VerificationRun::VerificationRun(QString _spin, QString _compiler, QString _path, QString _fileName, VerificationType _type, bool _fairness, QString _ltl, QStringList _compileOptions, int _searchDepth, int _hashSize, bool _autoDepth) : SpinRun(_spin, _path , _fileName, Verification){
compiler = _compiler;
verificationType = _type;
fairness = _fairness;
ltl = _ltl;
compileOptions = _compileOptions;
searchDepth = _searchDepth;
hashSize = _hashSize;
autoDepth = _autoDepth;
}
VerificationRun::~VerificationRun() {
process->deleteLater();
}
void VerificationRun::start(){
process = new QProcess();
process->setWorkingDirectory(path);
connect(process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(runCompile()));
connect(process, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(error()));
setStatus("Verification: Creating model with spin -a");
// INSERT LTL IF ACCEPTANCE RUN
if(verificationType == Acceptance) tempPath = createTempPml();
process->start(spin,QStringList() << "-a" << "\""+filePath+"\"");
}
QString VerificationRun::createTempPml(){
QFile::copy(filePath,path+".qspin");
QFile tempFile(filePath+".qspin");
if ( tempFile.open(QIODevice::Append | QIODevice::ReadWrite) )
{
QTextStream stream( &tempFile );
stream << "\n " + ltl << endl;
}
return filePath+".qspin";
}
void VerificationRun::runCompile(){
QFile::remove(tempPath); // Removing the temporary file
process = new QProcess();
process->setWorkingDirectory(path);
connect(process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(runPan()));
connect(process, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(error()));
QStringList options = compileOptions;
options << "-DNFAIR="+QString::number(nFair) << "pan.c";
setStatus("Verification: Compiling " + QString(compiler) + " " + listToString(options));
process->start(compiler, options);
}
void VerificationRun::runPan(){
process = new QProcess();
process->setWorkingDirectory(path);
setStatus(path);
connect(process, SIGNAL(readyReadStandardOutput()),this,SLOT(readReadyVerification()));
connect(process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(finishedVerification()));
connect(process, SIGNAL(finished(int,QProcess::ExitStatus)), process, SLOT(deleteLater()));
connect(process, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(error()));
QStringList runOptions;
switch (verificationType) {
case Safety:
break;
case Acceptance:
runOptions << "-a";
if (fairness) runOptions << "-f";
break;
case Liveness:
runOptions << "-l";
if (fairness) runOptions << "-f";
break;
}
if (searchDepth>0) runOptions << "-m"+QString::number(searchDepth);
if (hashSize>0) runOptions << "-w"+QString::number(hashSize);
setStatus("Verification: Running verification with " + QString(PAN) + " " +listToString(runOptions));
process->start(PAN, runOptions);
}
void VerificationRun::finishedVerification() {
currentOutput.append(process->readAllStandardOutput());
processVerification(currentOutput);
emit finished(this);
}
void VerificationRun::readReadyVerification() {
QRegExp sd("error: max search depth too small");
QRegExp nf("error: too many processes");
QString newOutput = process->readAllStandardOutput();
if (newOutput.contains(nf)) {
nFair += 1;
process->disconnect();
runCompile();
setStatus("restarted with DNFAIR="+QString::number(nFair));
} else if (newOutput.contains(sd) && autoDepth) {
if (searchDepth != -1) {
searchDepth += (searchDepth/2);
setStatus("max search depth too small: restarted with search depth ="+QString::number(searchDepth));
}
else searchDepth = 15000;
process->disconnect();
runPan();
} else {
currentOutput.append(newOutput);
}
emit readReady(this);
}
void VerificationRun::processVerification(QString output){
// TIMESTAMP
timestamp = QDateTime::currentDateTimeUtc().toLocalTime().toString();
// SPIN VERSION
QRegularExpression re("(Spin Version .+)\\)");
QRegularExpressionMatch spinVerM = re.match(output);
spinVer = spinVerM.captured(1);
// EVALUATION
re.setPattern("Warning");
QRegularExpressionMatch warningM = re.match(output);
re.setPattern("errors: (\\d)");
QRegularExpressionMatch evalM = re.match(output);
if(evalM.captured(1) == "0" && !warningM.hasMatch()) eval = "GREEN";
else if (evalM.captured(1) == "0" && warningM.hasMatch()) eval = "YELLOW";
else eval = "RED";
// STATESPACEPROP *******************************************************************************************************'
re.setPattern("([-+])\\s*Partial Order Reduction");
QRegularExpressionMatch partialM = re.match(output);
if (partialM.hasMatch()) partial = partialM.captured(1);
re.setPattern("never\\s*claim\\s*(.+)");
QRegularExpressionMatch neverM = re.match(output);
never = neverM.captured(1);
re.setPattern("assertion\\s*violations\\s*(.+)");
QRegularExpressionMatch assertionM = re.match(output);
assertion = assertionM.captured(1);
re.setPattern("(\\S*)\\s*cycles\\s*(.+)");
QRegularExpressionMatch acceptanceM = re.match(output);
acceptanceType = acceptanceM.captured(1).replace(0,1,acceptanceM.captured(1)[0].toUpper()); // TO ENSURE THAT THE FIRST CHARACTER IS UPPERCASE.
acceptance = acceptanceM.captured(2);
re.setPattern("invalid\\s+end\\s*states\\s*(.+)");
QRegularExpressionMatch invalidM = re.match(output);
invalid = invalidM.captured(1);
// STATESPACESPECS ***************************************************************************************************
// ERRORS - already used in the evaluation above.
errors = evalM.captured(1);
// DEPTH
re.setPattern("depth reached ([0-9+e.]*)");
QRegularExpressionMatch depthM = re.match(output);
depth = depthM.captured(1);
// STORED STATES
re.setPattern("([0-9+e.]*) states, stored");
QRegularExpressionMatch storedStatesM = re.match(output);
storedStates = storedStatesM.captured(1);
// MATCHED STATES
re.setPattern("([0-9+e.]*) states, matched");
QRegularExpressionMatch matchedStatesM = re.match(output);
matchedStates = matchedStatesM.captured(1);
// TRANSITIONS
re.setPattern("([0-9+e.]*) transitions");
QRegularExpressionMatch transitionsM = re.match(output);
transitions = transitionsM.captured(1);
// ATOMIC STATES
re.setPattern("([0-9+e.]*) atomic steps");
QRegularExpressionMatch atomicM = re.match(output);
atomic = atomicM.captured(1);
// STATE SIZE
re.setPattern("State-vector ([0-9+e.]*) byte");
QRegularExpressionMatch statesizeM = re.match(output);
statesize = statesizeM.captured(1);
// HASH CONFLICTS
re.setPattern("hash conflicts:\\s* ([0-9+e.]*)");
QRegularExpressionMatch hashconflictM = re.match(output);
hashconflict = hashconflictM.captured(1);
// HASH SIZE
re.setPattern("memory used for hash table \\(-w(\\d+)\\)");
QRegularExpressionMatch hashsizeM = re.match(output);
hashsize = hashsizeM.captured(1);
// Memory usage **********************************************************************************
//STATE MEMORY
re.setPattern("(\\d+\\.\\d+)\\s+actual\\s+memory\\s+usage\\s+for\\s+states");
QRegularExpressionMatch statememoryM = re.match(output);
statememory = statememoryM.captured(1);
//HASH MEMORY
re.setPattern("(\\d+\\.\\d+)\\s+memory\\s+used\\s+for\\s+hash\\s+table");
QRegularExpressionMatch hashmemoryM = re.match(output);
hashmemory = hashmemoryM.captured(1);
//DFS MEMORY
re.setPattern("(\\d+\\.\\d+)\\s+memory\\s+used\\s+for\\s+.FS\\s+stack");
QRegularExpressionMatch DFSmemoryM = re.match(output);
DFSmemory = DFSmemoryM.captured(1);
//TOTAL MEMORY
re.setPattern("(\\d+\\.\\d+)\\s+total\\s+actual\\s+memory\\s+usage");
QRegularExpressionMatch totalmemoryM = re.match(output);
totalmemory = totalmemoryM.captured(1);
}
QString VerificationRun::getAcceptanceType() {
if (verificationType==Acceptance) return "Acceptance";
else if (verificationType==Liveness) return "Progress";
else return "";
}