Skip to content

Commit

Permalink
misc stuff for report mode (non-working)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonKagstrom committed Apr 17, 2017
1 parent 1a0fdcd commit 890359c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/engines/dyninst-engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class DyninstEngine : public IEngine, public IFileParser
IConfiguration &conf = IConfiguration::getInstance();

if (conf.keyAsString("system-mode-write-file") != "" ||
conf.keyAsInt("system-mode-read-results-file"))
conf.keyAsString("system-mode-read-results-file") != "")
return match_perfect;

return match_none;
Expand Down
69 changes: 69 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,72 @@ static int runSystemModeRecord()
return runSystemModeRecordDirectory(base);
}

static int runSystemModeReportFile(const std::string &file)
{
pid_t child = fork();
if (child < 0)
{
panic("Fork failed?\n");
}
else if (child == 0)
{
IConfiguration &conf = IConfiguration::getInstance();

conf.setKey("system-mode-read-results-file", file);
conf.setKey("binary-name", file);
conf.setKey("binary-path", ""); // absolute path

runKcov(IConfiguration::MODE_COLLECT_AND_REPORT);
}
else
{
// Parent
int status;

::waitpid(child, &status, 0);
}

return 0;
}

static int runSystemModeReportDirectory(const std::string &base)
{
DIR *dir = ::opendir(base.c_str());
if (!dir)
{
error("Can't open directory %s\n", base.c_str());
return -1;
}

// Loop through the directory structure
struct dirent *de;
for (de = ::readdir(dir); de; de = ::readdir(dir)) {
std::string cur = base + "/" + de->d_name;
struct stat st;

if (lstat(cur.c_str(), &st) < 0)
continue;

// Executable file?
if (S_ISREG(st.st_mode))
{
runSystemModeReportFile(cur);
}
}
::closedir(dir);

return 0;
}

static int runSystemModeReport()
{
IConfiguration &conf = IConfiguration::getInstance();

std::string base = conf.keyAsString("binary-path") + conf.keyAsString("binary-name");

return runSystemModeReportDirectory(base);
}

int main(int argc, const char *argv[])
{
IConfiguration &conf = IConfiguration::getInstance();
Expand All @@ -406,5 +472,8 @@ int main(int argc, const char *argv[])
if (runningMode == IConfiguration::MODE_SYSTEM_RECORD)
return runSystemModeRecord();

if (runningMode == IConfiguration::MODE_SYSTEM_REPORT)
return runSystemModeReport();

return runKcov(runningMode);
}

0 comments on commit 890359c

Please sign in to comment.