Skip to content

Commit abf6bf1

Browse files
committed
Fix relative path support in config
1 parent d0c3976 commit abf6bf1

File tree

8 files changed

+53
-50
lines changed

8 files changed

+53
-50
lines changed

examples/engagement1/if-condition/repair.conf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
revision_file=/root/project/MSV/examples/engagement1/if-condition/revision.log
2-
src_dir=/root/project/MSV/examples/engagement1/if-condition/src
3-
test_dir=/root/project/MSV/examples/engagement1/if-condition/tests
4-
build_cmd=/root/project/MSV/tools/simple-build.py
5-
test_cmd=/root/project/MSV/tools/simple-test.py
6-
ddtest_cmd=/root/project/MSV/tools/DD.py
7-
tools_dir=/root/project/MSV/tools
1+
revision_file=revision.log
2+
src_dir=src
3+
test_dir=tests
4+
build_cmd=../../../tools/simple-build.py
5+
test_cmd=../../../tools/simple-test.py
6+
ddtest_cmd=../../../tools/DD.py
7+
tools_dir=../../../tools
88
localizer=profile
99
bugged_file=test.c
1010
fixed_out_file=fixed_

examples/engagement1/off-by-one/repair.conf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
revision_file=/root/project/MSV/examples/engagement1/off-by-one/revision.log
2-
src_dir=/root/project/MSV/examples/engagement1/off-by-one/src
3-
test_dir=/root/project/MSV/examples/engagement1/off-by-one/tests
4-
build_cmd=/root/project/MSV/tools/simple-build.py
5-
test_cmd=/root/project/MSV/tools/simple-test.py
6-
ddtest_cmd=/root/project/MSV/tools/DD.py
7-
tools_dir=/root/project/MSV/tools
1+
revision_file=revision.log
2+
src_dir=src
3+
test_dir=tests
4+
build_cmd=../../../tools/simple-build.py
5+
test_cmd=../../../tools/simple-test.py
6+
ddtest_cmd=../../../tools/DD.py
7+
tools_dir=../../../tools
88
localizer=profile
99
bugged_file=prog.c
1010
fixed_out_file=fixed_

src/BenchProgram.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,13 @@ ConfigFile* BenchProgram::getCurrentConfig() {
164164

165165
void BenchProgram::createSrcClone(const std::string &subDir) {
166166
assert( src_dirs.count(subDir) == 0);
167-
std::string copy = "cp -rf ";
167+
// The path name of the original src_directory from the config file
168+
// This must be present in the file system ortherwise, we will hit errors!
169+
const std::string ori_src_dir = getFullPath(config.getStr("src_dir"),
170+
this->work_dir);
171+
const std::string copy = "cp -Tfr ";
168172
std::string cmd=copy;
169-
cmd += ori_src_dir + " " + work_dir + "/" + subDir;
173+
cmd += ori_src_dir + " " + this->work_dir + "/" + subDir;
170174
execute_cmd_until_succ(cmd);
171175

172176
cmd=copy;
@@ -243,7 +247,6 @@ void BenchProgram::Init(const std::string &workDirPath, bool no_clean_up,bool in
243247
test_cnt = 0;
244248
this->cache = NULL;
245249
this->no_clean_up = no_clean_up;
246-
this->ori_src_dir = config.getStr("src_dir");
247250
this->wrap_ld = false;
248251
if (config.hasValue("wrap_ld"))
249252
this->wrap_ld = (config.getStr("wrap_ld") == "yes");
@@ -282,7 +285,7 @@ void BenchProgram::Init(const std::string &workDirPath, bool no_clean_up,bool in
282285
// We create an initial clone of the basic src direcotry
283286
src_dirs.clear();
284287
createSrcClone("src");
285-
this->src_dir = getFullPath(this->work_dir + "/src");
288+
this->src_dir = getFullPath("src", this->work_dir);
286289

287290
std::string ori_test_dir = config.getStr("test_dir");
288291
if (ori_test_dir != "") {
@@ -294,7 +297,7 @@ void BenchProgram::Init(const std::string &workDirPath, bool no_clean_up,bool in
294297
}
295298
else {
296299
this->work_dir = getFullPath(workDirPath);
297-
this->src_dir = getFullPath(work_dir + "/src");
300+
this->src_dir = getFullPath("src", this->work_dir);
298301
src_dirs.clear();
299302
// src_dirs.insert(std::make_pair("src", true));
300303

@@ -346,17 +349,18 @@ void BenchProgram::Init(const std::string &workDirPath, bool no_clean_up,bool in
346349
if (dep_dir != ""){
347350
dep_dir = getFullPath(dep_dir);
348351
}
349-
this->test_dir = getFullPath(work_dir+"/tests");
352+
this->test_dir = getFullPath("tests", this->work_dir);
350353
this->build_log_file = work_dir + "/build.log";
351354
// Clean up builg log for every execution
352355
std::string cmd = std::string("rm -rf ") + build_log_file;
353356
int ret = system(cmd.c_str());
354357
assert( ret == 0);
355-
this->build_cmd = getFullPath(config.getStr("build_cmd"));
356-
this->test_cmd = getFullPath(config.getStr("test_cmd"));
357-
this->ddtest_cmd=getFullPath(config.getStr("tools_dir"))+"/DD.py";
358-
this->prophet_src=getFullPath(config.getStr("tools_dir"))+"/../src";
359-
this->afl_cmd=getFullPath(config.getStr("tools_dir"))+"/run-afl.py";
358+
this->build_cmd = getFullPath(config.getStr("build_cmd"), this->work_dir);
359+
this->test_cmd = getFullPath(config.getStr("test_cmd"), this->work_dir);
360+
this->ddtest_cmd = getFullPath(config.getStr("tools_dir")+"/DD.py",
361+
this->work_dir);
362+
this->prophet_src = getFullPath(config.getStr("tools_dir")+"/../src",
363+
this->work_dir);
360364
this->localization_filename = work_dir + "/" + LOCALIZATION_RESULT;
361365
this->conditionNum=false;
362366

@@ -382,7 +386,8 @@ void BenchProgram::Init(const std::string &workDirPath, bool no_clean_up,bool in
382386
sin >> case_timeout;
383387
}
384388

385-
std::string revision_file = config.getStr("revision_file");
389+
std::string revision_file = getFullPath(config.getStr("revision_file"),
390+
this->work_dir);
386391
parseRevisionLog(revision_file, negative_cases, positive_cases);
387392
}
388393

@@ -483,7 +488,7 @@ bool incrementalBuild(time_t timeout_limit, const std::string &src_dir, const st
483488

484489
bool BenchProgram::buildFull(const std::string &subDir, time_t timeout_limit, bool force_reconf,std::vector<long long> compile_macro,std::vector<std::string> files,std::vector<long long> writer_macro) {
485490
assert(src_dirs.count(subDir) != 0);
486-
std::string src_dir = getFullPath(work_dir + "/" + subDir);
491+
std::string src_dir = getFullPath(subDir, this->work_dir);
487492

488493
for (int i=0;i<files.size();i++){
489494
std::string code;
@@ -1089,7 +1094,7 @@ std::vector<long long> BenchProgram::buildWithRepairedCode(const std::string &wr
10891094
outlog_printf(2,"Search %s!\n",it->first.c_str());
10901095

10911096
ExecutionTimer timer;
1092-
std::string src_dir = getFullPath(work_dir + "/src");
1097+
std::string src_dir = getFullPath("src", this->work_dir);
10931098
removeMacros(fileCodeMap,src_dir);
10941099
std::string cmd;
10951100
cmd=ddtest_cmd+" -l "+build_log_file+" -s "+src_dir;
@@ -1188,7 +1193,7 @@ std::vector<long long> BenchProgram::buildWithRepairedCode(const std::string &wr
11881193
outlog_printf(2,"Search %s!\n",it->first.c_str());
11891194

11901195
ExecutionTimer timer;
1191-
std::string src_dir = getFullPath(work_dir + "/src");
1196+
std::string src_dir = getFullPath("src", this->work_dir);
11921197
removeMacros(fileCodeMap,src_dir);
11931198
std::string cmd;
11941199
cmd=ddtest_cmd+" -l "+build_log_file+" -s "+src_dir+" -d "+BuildSubDir.getValue();
@@ -1314,9 +1319,9 @@ BenchProgram::TestCaseSetTy BenchProgram::testSet(const std::string &subDir,
13141319
// cmd+=" -s "+std::to_string(switchId)+"-"+std::to_string(caseNum);
13151320

13161321
if (!pass_basic_src_dir)
1317-
cmd = cmd + " " + getFullPath(work_dir + "/" + subDir) + " " + test_dir + " " + work_dir + " ";
1322+
cmd = cmd + " " + getFullPath(subDir, this->work_dir) + " " + test_dir + " " + work_dir + " ";
13181323
else
1319-
cmd = cmd + " -p " + getFullPath(work_dir + "/" + subDir) + " " + src_dir + " " + test_dir + " " + work_dir + " ";
1324+
cmd = cmd + " -p " + getFullPath(subDir, this->work_dir) + " " + src_dir + " " + test_dir + " " + work_dir + " ";
13201325
std::ostringstream sout;
13211326
sout << cmd;
13221327
for (TestCaseSetTy::const_iterator it = case_set.begin(); it != case_set.end(); it ++)
@@ -1573,4 +1578,4 @@ std::unique_ptr<clang::ASTUnit> BenchProgram::buildClangASTUnit(const std::strin
15731578
std::string cmd = "rm -rf " + work_dir + "/profile";
15741579
int ret = system(cmd.c_str());
15751580
assert( ret == 0);
1576-
}*/
1581+
}*/

src/BenchProgram.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,6 @@ class BenchProgram {
506506
ConfigFile config;
507507
// The name of the work directory, all paths in this class are absolute paths
508508
std::string work_dir;
509-
// The path name of the original src_directory from the config file
510-
// This must be present in the file system ortherwise, we will hit errors!
511-
std::string ori_src_dir;
512509
// The basic src directory path
513510
std::string src_dir;
514511
// The set of created src_directories, including the basic source directory,

src/Main.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,14 @@ int main(int argc, char* argv[]) {
205205
FP->resetZero(FeatureVector::MAX_FEATURE);
206206
}
207207
else {
208-
std::ifstream fin(ParameterFile.getValue(), std::ifstream::in);
209-
if (fin.is_open()) {
210-
fin >> *FP;
211-
fin.close();
208+
const auto& path = ParameterFile.getValue();
209+
std::ifstream fin {path, std::ifstream::in};
210+
if (!fin.good()) {
211+
outlog_printf(0, "%s: %s\n", strerror(errno), path.c_str());
212+
exit(1);
212213
}
214+
fin >> *FP;
215+
fin.close();
213216
}
214217
learning = true;
215218
}

src/ProfilerAction.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <clang/Frontend/FrontendPluginRegistry.h>
2828
#include <clang/Lex/Lexer.h>
2929
#include <llvm/Support/raw_ostream.h>
30+
#include <libexplain/realpath.h>
3031
#include <sstream>
3132
#include <fstream>
3233
#include <assert.h>
@@ -40,11 +41,7 @@ namespace {
4041

4142
std::string getFullPath(const std::string &path) {
4243
char tmp[PATH_MAX];
43-
char * ret = realpath(path.c_str(), tmp);
44-
if (ret != 0)
45-
return std::string(tmp);
46-
else
47-
return std::string("unkown_src_file");
44+
return std::string(explain_realpath_or_die(path.c_str(), tmp));
4845
}
4946

5047
typedef std::map<std::string, std::vector<std::string> > RewriteTextMapTy;

src/Utils.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <sys/stat.h>
2828
#include <clang/AST/RecursiveASTVisitor.h>
2929
#include <clang/AST/ASTContext.h>
30+
#include <libexplain/realpath.h>
3031
#include <fstream>
3132
#include <sstream>
3233
#include <iostream>
@@ -172,13 +173,13 @@ bool is_header(const std::string &str) {
172173
// return !((str[str.size() - 2] == '.') && (str[str.size() - 1] == 'c'));
173174
}
174175

175-
std::string getFullPath(const std::string &path) {
176-
// printf("Path: %s\n",path.c_str());
176+
std::string getFullPath(const std::string &path, const std::string &pwd) {
177177
if (path[0]=='/') return path;
178178
char tmp[PATH_MAX];
179-
char * ret = realpath(path.c_str(), tmp);
180-
if( tmp != 0 ) printf(std::string("fail to get full path of "+path+"\n").c_str());
181-
return std::string(tmp);
179+
std::string relpath = path;
180+
if (!pwd.empty())
181+
relpath = pwd + "/" + path;
182+
return std::string(explain_realpath_or_die(relpath.c_str(), tmp));
182183
}
183184

184185
int execute_with_timeout(const std::string &cmd, unsigned long timeout) {

src/Utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bool exist_directory(const std::string &dir);
5151

5252
bool is_header(const std::string &str);
5353

54-
std::string getFullPath(const std::string &path);
54+
std::string getFullPath(const std::string &path, const std::string &pwd = "");
5555

5656
std::set<std::string> splitStringWithWhite(const std::string &str);
5757

0 commit comments

Comments
 (0)