Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libs2eplugins: optionally create test cases when forking states #20

Merged
merged 1 commit into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,16 @@ void TestCaseGenerator::initialize() {
void TestCaseGenerator::enable() {
ConfigFile *cfg = s2e()->getConfig();

bool tcOnFork = cfg->getBool(getConfigKey() + ".generateOnStateFork", false);
bool tcOnKill = cfg->getBool(getConfigKey() + ".generateOnStateKill", true);
bool tcOnSegfault = cfg->getBool(getConfigKey() + ".generateOnSegfault", true);

if (tcOnFork) {
m_stateForkConnection.disconnect();
m_stateForkConnection =
s2e()->getCorePlugin()->onStateFork.connect(sigc::mem_fun(*this, &TestCaseGenerator::onStateFork));
}

if (tcOnKill) {
m_stateKillConnection.disconnect();
m_stateKillConnection =
Expand Down Expand Up @@ -142,6 +149,7 @@ void TestCaseGenerator::enable() {
}

void TestCaseGenerator::disable() {
m_stateForkConnection.disconnect();
m_stateKillConnection.disconnect();
m_linuxSegFaultConnection.disconnect();
m_windowsKernelCrashConnection.disconnect();
Expand All @@ -162,6 +170,14 @@ void TestCaseGenerator::onSegFault(S2EExecutionState *state, uint64_t pid, uint6
generateTestCases(state, ss.str(), TC_FILE);
}

void TestCaseGenerator::onStateFork(S2EExecutionState *state, const std::vector<S2EExecutionState *> &newStates,
const std::vector<klee::ref<klee::Expr>> &newConditions) {
for (auto *newState : newStates) {
if (newState != state)
generateTestCases(newState, "fork", TC_FILE);
}
}

void TestCaseGenerator::onStateKill(S2EExecutionState *state) {
generateTestCases(state, "kill", TC_LOG | TC_TRACE | TC_FILE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,16 @@ class TestCaseGenerator : public Plugin, public IPluginInvoker {
const ConcreteFileTemplates &getTemplates(S2EExecutionState *state) const;

private:
sigc::connection m_stateForkConnection;
sigc::connection m_stateKillConnection;
sigc::connection m_linuxSegFaultConnection;
sigc::connection m_windowsUserCrashConnection;
sigc::connection m_windowsKernelCrashConnection;

ExecutionTracer *m_tracer;

void onStateFork(S2EExecutionState *state, const std::vector<S2EExecutionState *> &newStates,
const std::vector<klee::ref<klee::Expr>> &newConditions);
void onStateKill(S2EExecutionState *state);
void onSegFault(S2EExecutionState *state, uint64_t pid, uint64_t pc);
void onWindowsUserCrash(S2EExecutionState *state, const WindowsUserModeCrash &desc);
Expand Down