-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBenchProgram.h
More file actions
705 lines (579 loc) · 28 KB
/
BenchProgram.h
File metadata and controls
705 lines (579 loc) · 28 KB
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
// Copyright (C) 2016 Fan Long, Martin Rianrd and MIT CSAIL
// Prophet
//
// This file is part of Prophet.
//
// Prophet is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Prophet is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Prophet. If not, see <http://www.gnu.org/licenses/>.
#pragma once
#include "ErrorLocalizer.h"
#include "ProfileErrorLocalizer.h"
#include "RepairCandidateGenerator.h"
#include "ConfigFile.h"
#include <cjson/cJSON.h>
#include <clang/Frontend/ASTUnit.h>
#include <clang/AST/Expr.h>
#include <string>
#include <vector>
#include <set>
#include <map>
class ConfigFile;
class LocationIndex;
struct FunctionReplaceInfo{
std::string originalName;
std::map<size_t,std::string> newName;
size_t switchNum;
};
class TestCache {
std::string cache_file;
std::map<std::string, bool> cache;
void appendFile(const std::string &key, size_t v) {
FILE *f = fopen(cache_file.c_str(), "ab");
assert(f);
size_t n = key.size();
size_t ret = fwrite(&n, sizeof(n), 1, f);
assert(ret == 1);
ret = fwrite(&key[0], 1, key.size(), f);
assert( ret == key.size());
ret = fwrite(&v, sizeof(v), 1, f);
assert( ret == 1);
fclose(f);
}
public:
TestCache(const std::string &cache_file): cache_file(cache_file), cache() {
if (!existFile(cache_file)) {
FILE* f = fopen(cache_file.c_str(), "wb");
fclose(f);
}
else {
FILE* f = fopen(cache_file.c_str(), "rb");
while (!feof(f)) {
size_t n;
size_t ret = fread(&n, sizeof(n), 1, f);
if (ret != 1) {
assert(feof(f));
break;
}
std::string key;
key.resize(n);
ret = fread(&key[0], 1, n, f);
assert( ret == n);
ret = fread(&n, sizeof(n), 1, f);
if (n == 0 && (cache.count(key) == 0))
cache.insert(std::make_pair(key, false));
if (n == 1)
cache.insert(std::make_pair(key, true));
}
fclose(f);
}
}
void addCandidate(const std::string &key) {
if (cache.count(key) == 0) {
appendFile(key, 0);
cache[key] = false;
}
}
bool isNotSucc(const std::string &key) {
if (cache.count(key) != 0)
return !cache[key];
else
return false;
}
void markSucc(const std::string &key) {
if (cache.count(key) == 0 || cache[key] == false) {
cache[key] = true;
appendFile(key, 1);
}
}
};
struct Kind{
RepairCandidate::CandidateKind kind;
std::vector<size_t> cases;
};
struct Switch{
size_t switchNum;
std::map<RepairCandidate::CandidateKind,Kind> types;
Switch(){
types.clear();
Kind kind;
kind.kind=RepairCandidate::CandidateKind::TightenConditionKind;
kind.cases=std::vector<size_t>();
types[kind.kind]=kind;
Kind kind2;
kind2.kind=RepairCandidate::CandidateKind::LoosenConditionKind;
kind2.cases=std::vector<size_t>();
types[kind2.kind]=kind2;
Kind kind3;
kind3.kind=RepairCandidate::CandidateKind::GuardKind;
kind3.cases=std::vector<size_t>();
types[kind3.kind]=kind3;
Kind kind4;
kind4.kind=RepairCandidate::CandidateKind::SpecialGuardKind;
kind4.cases=std::vector<size_t>();
types[kind4.kind]=kind4;
Kind kind5;
kind5.kind=RepairCandidate::CandidateKind::IfExitKind;
kind5.cases=std::vector<size_t>();
types[kind5.kind]=kind5;
Kind kind6;
kind6.kind=RepairCandidate::CandidateKind::AddInitKind;
kind6.cases=std::vector<size_t>();
types[kind6.kind]=kind6;
Kind kind7;
kind7.kind=RepairCandidate::CandidateKind::ReplaceKind;
kind7.cases=std::vector<size_t>();
types[kind7.kind]=kind7;
Kind kind8;
kind8.kind=RepairCandidate::CandidateKind::ReplaceStringKind;
kind8.cases=std::vector<size_t>();
types[kind8.kind]=kind8;
Kind kind9;
kind9.kind=RepairCandidate::CandidateKind::ReplaceFunctionKind;
kind9.cases=std::vector<size_t>();
types[kind9.kind]=kind9;
Kind kind91;
kind91.kind=RepairCandidate::CandidateKind::AddStmtKind;
kind91.cases=std::vector<size_t>();
types[kind91.kind]=kind91;
Kind kind92;
kind92.kind=RepairCandidate::CandidateKind::AddStmtAndReplaceAtomKind;
kind92.cases=std::vector<size_t>();
types[kind92.kind]=kind92;
Kind kind93;
kind93.kind=RepairCandidate::CandidateKind::MSVExtAddIfStmtKind;
kind93.cases=std::vector<size_t>();
types[kind93.kind]=kind93;
Kind kind10;
kind10.kind=RepairCandidate::CandidateKind::MSVExtConditionKind;
kind10.cases=std::vector<size_t>();
types[kind10.kind]=kind10;
Kind kind101;
kind101.kind=RepairCandidate::CandidateKind::MSVExtFunctionReplaceKind;
kind101.cases=std::vector<size_t>();
types[kind101.kind]=kind101;
Kind kind102;
kind102.kind=RepairCandidate::CandidateKind::MSVExtReturnConditionKind;
kind102.cases=std::vector<size_t>();
types[kind102.kind]=kind102;
Kind kind103;
kind103.kind=RepairCandidate::CandidateKind::MSVExtAssignConditionKind;
kind103.cases=std::vector<size_t>();
types[kind103.kind]=kind103;
Kind kind104;
kind104.kind=RepairCandidate::CandidateKind::MSVExtReplaceFunctionInConditionKind;
kind104.cases=std::vector<size_t>();
types[kind104.kind]=kind104;
Kind kind105;
kind105.kind=RepairCandidate::CandidateKind::MSVExtRemoveStmtKind;
kind105.cases=std::vector<size_t>();
types[kind105.kind]=kind105;
Kind kind106;
kind106.kind=RepairCandidate::CandidateKind::MSVExtRemoveConditionKind;
kind106.cases=std::vector<size_t>();
types[kind106.kind]=kind106;
Kind kind107;
kind107.kind=RepairCandidate::CandidateKind::MSVExtRemoveAssignConditionKind;
kind107.cases=std::vector<size_t>();
types[kind107.kind]=kind107;
Kind kind108;
kind108.kind=RepairCandidate::CandidateKind::MSVExtReplaceAssignOperatorKind;
kind108.cases=std::vector<size_t>();
types[kind108.kind]=kind108;
Kind kind109;
kind109.kind=RepairCandidate::CandidateKind::MSVExtReplaceArrayIndexKind;
kind109.cases=std::vector<size_t>();
types[kind109.kind]=kind109;
Kind kind110;
kind110.kind=RepairCandidate::CandidateKind::MSVExtReplaceParenInConditionKind;
kind110.cases=std::vector<size_t>();
types[kind110.kind]=kind110;
Kind kind111;
kind111.kind=RepairCandidate::CandidateKind::MSVExtAddInitBackKind;
kind111.cases=std::vector<size_t>();
types[kind111.kind]=kind111;
Kind kind112;
kind112.kind=RepairCandidate::CandidateKind::MSVExtIfExitBackKind;
kind112.cases=std::vector<size_t>();
types[kind112.kind]=kind112;
Kind kind113;
kind113.kind=RepairCandidate::CandidateKind::MSVExtReplaceTrenaryOperatorKind;
kind113.cases=std::vector<size_t>();
types[kind113.kind]=kind113;
Kind kind114;
kind114.kind=RepairCandidate::CandidateKind::MSVExtMoveConditionKind;
kind114.cases=std::vector<size_t>();
types[kind114.kind]=kind114;
Kind kind115;
kind115.kind=RepairCandidate::CandidateKind::MSVExtLoopConditionKind;
kind115.cases=std::vector<size_t>();
types[kind115.kind]=kind115;
Kind kind116;
kind116.kind=RepairCandidate::CandidateKind::MSVExtParenTightenConditionKind;
kind116.cases=std::vector<size_t>();
types[kind116.kind]=kind116;
Kind kind117;
kind117.kind=RepairCandidate::CandidateKind::MSVExtParenLoosenConditionKind;
kind117.cases=std::vector<size_t>();
types[kind117.kind]=kind117;
}
};
struct Line{
size_t line;
std::vector<Switch> switches;
};
struct File{
std::string fileName;
std::vector<Line> lines;
};
static double round_score(double var)
{
double value = (int)(var * 10000 + .5);
return (double)value / 10000;
}
class BenchProgram {
public:
typedef std::set<unsigned long> TestCaseSetTy;
typedef std::map<std::string, std::string> EnvMapTy;
private:
class SwitchInfo{
std::string fileName;
std::string funcFileName;
public:
std::map<size_t,size_t> caseNum;
std::vector<std::list<size_t>> switchCluster;
// std::map<int,std::list<std::list<int>>> caseCluster;
std::map<std::pair<std::string,size_t>,std::pair<size_t,size_t>> scoreInfo;
// std::map<std::pair<size_t,size_t>,size_t> conditionCases;
std::map<std::string,std::map<std::string,std::map<size_t,std::string>>> mutationInfo;
std::vector<File> infos;
std::map<size_t,std::map<size_t,std::vector<double>>> patchScores;
std::map<std::pair<size_t,size_t>,size_t> varSizes;
std::map<std::string,std::map<std::string,std::pair<size_t,size_t>>> funcLocations;
std::vector<FunctionReplaceInfo> funcReplaceInfos;
std::map<size_t,std::pair<std::pair<size_t,size_t>,std::pair<size_t,size_t>>> originalLoc;
std::map<size_t,std::vector<std::string>> patchCodes;
public:
SwitchInfo(std::string workdir):fileName(workdir+"/switch-info.json"),funcFileName(workdir+"/func-info.json") {}
void save(){
cJSON *json=cJSON_CreateObject();
// Add total switch number
cJSON_AddNumberToObject(json,std::string("switch_num").c_str(),caseNum.size());
// Add case number of each switch
cJSON *switchCase=cJSON_CreateArray();
int i=0;
for (std::map<size_t,size_t>::iterator it=caseNum.begin();it!=caseNum.end();it++){
cJSON *caseNumber=cJSON_CreateNumber(it->second);
cJSON_AddItemToArray(switchCase,caseNumber);
}
cJSON_AddItemToObject(json,std::string("case_num").c_str(),switchCase);
// Add switch cluster
cJSON *switchClusterArray=cJSON_CreateArray();
for (std::vector<std::list<size_t>>::iterator it=switchCluster.begin();it!=switchCluster.end();it++){
cJSON *switchGroup=cJSON_CreateArray();
for (std::list<size_t>::iterator it2=it->begin();it2!=it->end();it2++){
cJSON_AddItemToArray(switchGroup,cJSON_CreateNumber(*it2));
}
cJSON_AddItemToArray(switchClusterArray,switchGroup);
}
cJSON_AddItemToObject(json,std::string("switch_cluster").c_str(),switchClusterArray);
// Save FL scores
cJSON *scoreArray=cJSON_CreateArray();
for (std::map<std::pair<std::string,size_t>,std::pair<size_t,size_t>>::iterator it=scoreInfo.begin();it!=scoreInfo.end();it++){
cJSON *localize=cJSON_CreateObject();
cJSON_AddStringToObject(localize,"file",it->first.first.c_str());
cJSON_AddNumberToObject(localize,"line",it->first.second);
cJSON_AddNumberToObject(localize,"primary_score",it->second.first);
cJSON_AddNumberToObject(localize,"second_score",it->second.second);
cJSON_AddItemToArray(scoreArray,localize);
}
cJSON_AddItemToObject(json,std::string("priority").c_str(),scoreArray);
// Save function infos
cJSON *funcArray=cJSON_CreateArray();
for (size_t i=0;i<funcReplaceInfos.size();i++){
cJSON *funcInfo=cJSON_CreateObject();
cJSON_AddStringToObject(funcInfo,"original_name",funcReplaceInfos[i].originalName.c_str());
cJSON_AddNumberToObject(funcInfo,"switch_number",funcReplaceInfos[i].switchNum);
cJSON *newFuncArray=cJSON_CreateArray();
for (std::map<size_t,std::string>::iterator it=funcReplaceInfos[i].newName.begin();it!=funcReplaceInfos[i].newName.end();it++){
cJSON *newFunc=cJSON_CreateObject();
cJSON_AddStringToObject(newFunc,"new_name",it->second.c_str());
cJSON_AddNumberToObject(newFunc,"case_number",it->first);
cJSON_AddItemToArray(newFuncArray,newFunc);
}
cJSON_AddItemToObject(funcInfo,"new_names",newFuncArray);
cJSON_AddItemToArray(funcArray,funcInfo);
}
char *fileString=cJSON_Print(funcArray);
std::ofstream ffout(funcFileName,std::ofstream::out);
ffout << fileString << "\n";
ffout.close();
cJSON_Delete(funcArray);
// Save mutation infos
cJSON *mutationArray=cJSON_CreateArray();
for(std::map<std::string,std::map<std::string,std::map<size_t,std::string>>>::iterator it=mutationInfo.begin();it!=mutationInfo.end();it++){
cJSON *mutationObject=cJSON_CreateObject();
cJSON_AddStringToObject(mutationObject,std::string("file").c_str(),it->first.c_str());
cJSON *funcArray=cJSON_CreateArray();
for (std::map<std::string,std::map<size_t,std::string>>::iterator it2=it->second.begin();it2!=it->second.end();it2++){
cJSON *funcObject=cJSON_CreateObject();
cJSON_AddStringToObject(funcObject,std::string("function").c_str(),it2->first.c_str());
cJSON *varArray=cJSON_CreateArray();
for (std::map<size_t,std::string>::iterator it3=it2->second.begin();it3!=it2->second.end();it3++){
cJSON *varObject=cJSON_CreateObject();
cJSON_AddNumberToObject(varObject,std::string("number").c_str(),it3->first);
cJSON_AddStringToObject(varObject,std::string("variable").c_str(),it3->second.c_str());
cJSON_AddItemToArray(varArray,varObject);
}
cJSON_AddItemToObject(funcObject,std::string("variables").c_str(),varArray);
cJSON_AddItemToArray(funcArray,funcObject);
}
cJSON_AddItemToObject(mutationObject,std::string("functions").c_str(),funcArray);
cJSON_AddItemToArray(mutationArray,mutationObject);
}
cJSON_AddItemToObject(json,std::string("mutation_info").c_str(),mutationArray);
// Save each patch rules
cJSON *ruleArray=cJSON_CreateArray();
for (std::vector<File>::iterator it=infos.begin();it!=infos.end();it++){
cJSON *fileObject=cJSON_CreateObject();
cJSON_AddStringToObject(fileObject,"file_name",it->fileName.c_str());
cJSON *lineArray=cJSON_CreateArray();
for (std::vector<Line>::iterator it2=it->lines.begin();it2!=it->lines.end();it2++){
cJSON *infoObject=cJSON_CreateObject();
cJSON_AddNumberToObject(infoObject,std::string("line").c_str(),it2->line);
cJSON *switchArray=cJSON_CreateArray();
for (size_t i=0;i<it2->switches.size();i++){
Switch currentSwitch=it2->switches[i];
cJSON *typeArray=cJSON_CreateArray();
cJSON *switchObject=cJSON_CreateObject();
cJSON_AddNumberToObject(switchObject,"switch",currentSwitch.switchNum);
for (std::map<RepairCandidate::CandidateKind,Kind>::iterator j=currentSwitch.types.begin();j!=currentSwitch.types.end();j++){
Kind currentType=j->second;
cJSON *caseArray=cJSON_CreateArray();
for (size_t k=0;k<currentType.cases.size();k++){
size_t currentCase=currentType.cases[k];
cJSON_AddItemToArray(caseArray,cJSON_CreateNumber(currentCase));
}
cJSON_AddItemToArray(typeArray,caseArray);
}
cJSON_AddItemToObject(switchObject,"types",typeArray);
cJSON_AddNumberToObject(switchObject,"begin_line",originalLoc[currentSwitch.switchNum].first.first);
cJSON_AddNumberToObject(switchObject,"begin_column",originalLoc[currentSwitch.switchNum].first.second);
cJSON_AddNumberToObject(switchObject,"end_line",originalLoc[currentSwitch.switchNum].second.first);
cJSON_AddNumberToObject(switchObject,"end_column",originalLoc[currentSwitch.switchNum].second.second);
cJSON *patchArray=cJSON_CreateArray();
for (size_t j=0;j<patchCodes[currentSwitch.switchNum].size();j++){
cJSON_AddItemToArray(patchArray,cJSON_CreateString(patchCodes[currentSwitch.switchNum][j].c_str()));
}
cJSON_AddItemToObject(switchObject,"patch_codes",patchArray);
// Add Prophet score
cJSON *prophetScoreArray=cJSON_CreateArray();
for (std::map<size_t,std::vector<double>>::iterator it3=patchScores[currentSwitch.switchNum].begin();it3!=patchScores[currentSwitch.switchNum].end();it3++){
cJSON *caseScoreObject=cJSON_CreateObject();
cJSON_AddNumberToObject(caseScoreObject,"case",it3->first);
cJSON *caseScoreArray=cJSON_CreateArray();
for (size_t k=0;k<it3->second.size();k++)
cJSON_AddItemToArray(caseScoreArray,cJSON_CreateNumber(it3->second[k]));
cJSON_AddItemToObject(caseScoreObject,"scores",caseScoreArray);
cJSON_AddItemToArray(prophetScoreArray,caseScoreObject);
}
cJSON_AddItemToObject(switchObject,"prophet_scores",prophetScoreArray);
cJSON_AddItemToArray(switchArray,switchObject);
}
cJSON_AddItemToObject(infoObject,"switches",switchArray);
cJSON_AddItemToArray(lineArray,infoObject);
}
cJSON_AddItemToObject(fileObject,"lines",lineArray);
cJSON_AddItemToArray(ruleArray,fileObject);
}
cJSON_AddItemToObject(json,"rules",ruleArray);
cJSON *sizesArray=cJSON_CreateArray();
for (std::map<std::pair<size_t,size_t>,size_t>::iterator it=varSizes.begin();it!=varSizes.end();it++){
cJSON *sizeObject=cJSON_CreateObject();
cJSON_AddNumberToObject(sizeObject,"switch",it->first.first);
cJSON_AddNumberToObject(sizeObject,"case",it->first.second);
cJSON_AddNumberToObject(sizeObject,"size",it->second);
cJSON_AddItemToArray(sizesArray,sizeObject);
}
cJSON_AddItemToObject(json,"sizes",sizesArray);
cJSON *fileArray=cJSON_CreateArray();
for (std::map<std::string,std::map<std::string,std::pair<size_t,size_t>>>::iterator it=funcLocations.begin();it!=funcLocations.end();it++){
cJSON *fileObject=cJSON_CreateObject();
cJSON_AddStringToObject(fileObject,"file",it->first.c_str());
cJSON *funcArray=cJSON_CreateArray();
for (std::map<std::string,std::pair<size_t,size_t>>::iterator it2=it->second.begin();it2!=it->second.end();it2++){
cJSON *funcObject=cJSON_CreateObject();
cJSON_AddStringToObject(funcObject,"function",it2->first.c_str());
cJSON_AddNumberToObject(funcObject,"begin",it2->second.first);
cJSON_AddNumberToObject(funcObject,"end",it2->second.second);
cJSON_AddItemToArray(funcArray,funcObject);
}
cJSON_AddItemToObject(fileObject,"functions",funcArray);
cJSON_AddItemToArray(fileArray,fileObject);
}
cJSON_AddItemToObject(json,"func_locations",fileArray);
// Save JSON to file
char *jsonString=cJSON_Print(json);
std::ofstream fout(fileName,std::ofstream::out);
fout << jsonString << "\n";
fout.close();
cJSON_Delete(json);
}
};
private:
SwitchInfo switchInfo;
ConfigFile config;
// The name of the work directory, all paths in this class are absolute paths
std::string work_dir;
// The path name of the original src_directory from the config file
// This must be present in the file system ortherwise, we will hit errors!
std::string ori_src_dir;
// The basic src directory path
std::string src_dir;
// The set of created src_directories, including the basic source directory,
// all of them are cped from the ori_src_dir. The map indicates whether this
// gets built or not
std::map<std::string, bool> src_dirs;
// The test directory path inside work_dir, this is an absolute path!
std::string test_dir;
// The dependency directory path, this is an absolute path!
std::string dep_dir;
// The build command script path, this is an absolute path!
std::string build_cmd;
// The test command script path, this is an absolute path!
std::string test_cmd;
std::string prophet_src;
std::string ddtest_cmd;
std::string afl_cmd;
std::string profile_dir;
std::string localization_filename;
std::string build_log_file;
bool no_clean_up;
bool wrap_ld;
std::string infile_build_dir;
std::vector<std::string> infile_args;
time_t total_repair_build_time;
size_t repair_build_cnt;
size_t case_timeout;
TestCaseSetTy positive_cases, negative_cases;
unsigned long compile_cnt;
unsigned long test_cnt;
int count;
// For testing with specific switch id and case, instead of using AFL
size_t switchId;
size_t caseNum;
size_t conditionNum;
std::vector<long long> failMacros;
TestCache *cache;
std::map<std::string,std::string> build_dir_save;
std::map<std::string,std::vector<std::string>> build_args_save;
void Init(const std::string &workDirPath, bool no_clean_up,bool init_only=false);
bool buildFull(const std::string &subDir, time_t timeout_limit = 0, bool force_reconf = false,std::vector<long long> compile_macro=std::vector<long long>(),std::vector<std::string> files=std::vector<std::string>(),
std::vector<long long> writer_macro=std::vector<long long>());
void getCompileMisc(const std::string &src_file, std::string &build_dir, std::vector<std::string> &build_args);
EnvMapTy ori_env_map;
std::string ori_path_for_wrap_path;
void deleteLibraryFile(const std::map<std::string, std::string> &fileCodeMap);
public:
bool isCondition;
bool skip_profile;
bool skip_build;
// We create the work dir from a configuration file, and we will put workdir
// in the workDirPath path. If it is empty string, we will create a work dir
// with an empty directory
BenchProgram(const std::string &configFileName, const std::string &workDirPath,
bool no_clean_up = false,bool init_only=false,int switchId=-1,int caseNum=-1);
BenchProgram(const std::string &workDirPath,bool init_only=false,int switchId=-1,int caseNum=-1);
TestCaseSetTy getPositiveCaseSet() {
return positive_cases;
}
TestCaseSetTy getNegativeCaseSet() {
return negative_cases;
}
ConfigFile* getCurrentConfig();
SwitchInfo &getSwitchInfo(){return switchInfo;}
void createSrcClone(const std::string &subDir);
void clearSrcClone(const std::string &subDir);
void addExistingSrcClone(const std::string &subDir, bool built);
void pushEnvMap(const EnvMapTy &envMap);
void popEnvMap(const EnvMapTy &envMap);
void pushWrapPath(const std::string &wrapPath, const std::string &cc_path);
void popWrapPath();
std::unique_ptr<clang::ASTUnit> buildClangASTUnit(const std::string &src_file,
const std::string &code,std::vector<long long> macros=std::vector<long long>());
// bool runDG(std::vector<ASTLocTy> criteriaLocation);
bool runDG(std::vector<std::string> files,std::map<std::string,std::set<unsigned>> lines);
bool buildSubDir(const std::string &subDir, const std::string &wrapScript,
const EnvMapTy &envMap,std::vector<long long> compile_macro=std::vector<long long>());
void saveFixedFiles(std::map<std::string, std::string> &fileCodeMap,std::string output_name);
void applyRepairedCode(std::map<std::string, std::string> &fileCodeMap,EnvMapTy &envMap,std::string wrapScript);
void rollbackOriginalCode(std::map<std::string, std::string> &fileCodeMap,EnvMapTy &envMap);
std::vector<long long> buildWithRepairedCode(const std::string &wrapScript, const EnvMapTy &envMap,
const std::map<std::string, std::string> &fileCodeMap,const std::map<long long,std::string> ¯oWithCode,
const std::map<std::string,std::vector<long long>> ¯oFile,
std::string output_name="",
std::vector<long long> macros=std::vector<long long>());
TestCaseSetTy testSet(const std::string &subDir, const TestCaseSetTy &case_set,
const EnvMapTy &envMap, size_t totalSwitch=0,size_t chooseSwitch=0,size_t chooseCase=0,size_t pid=0,bool pass_basic_src_dir = false);
bool test(const std::string &subDir, size_t id, const EnvMapTy &envMap,size_t totalSwitch,size_t chooseSwitch=0,size_t chooseCase=0,size_t pid=0,
bool pass_basic_src_dir=false);
/* BenchProgram(const std::string &src_dir, const std::string &test_dir,
const std::string &build_cmd, const std::string &test_cmd,
const std::string &run_work_dir, bool using_ramfs = false,
bool no_clean_up = false, size_t case_timeout = 60);*/
std::string getLocalizationResultFilename() {
return localization_filename;
}
std::string getLocalizationResultBackupFilename();
std::string getWorkdir() { return work_dir; }
std::string getSrcdir() { return src_dir; }
std::string getTestScript(){return test_cmd;}
std::string getAFLScript(){return afl_cmd;}
std::string normalizePath(const std::string &);
void setSwitch(size_t id,size_t caseNumber){
this->switchId=id;
this->caseNum=caseNumber;
}
std::pair<size_t,size_t> getSwitch(){
return std::make_pair(switchId,caseNum);
}
size_t getConditionNum(){
return conditionNum;
}
void setConditionNum(size_t num){
conditionNum=num;
isCondition=true;
}
std::string getProphetSrc(){
return prophet_src;
}
void addFailMacros(long long macro){
failMacros.push_back(macro);
}
//void setArgFile(const std::string &fixtest_argfile);
//void clearProfileBuild();
//void skipProfileBuild();
//void buildProfile();
//void configOnly();
//void prepare_test();
//std::set<size_t> test(const std::set<size_t> &case_set,
// const std::map<std::string, std::string> &env_pairs);
//bool testProfile(size_t id, std::map<SourcePositionTy, ProfileInfoTy> &M);
bool verifyTestCases();
virtual ~BenchProgram();
// Create a testcache object, this can only be called once
TestCache *getTestCache() {
if (cache == NULL)
cache = new TestCache(work_dir + "/test.cache");
return cache;
}
};