P4C
The P4 Compiler
Loading...
Searching...
No Matches
symbolic_executor.h
1#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SYMBOLIC_EXECUTOR_SYMBOLIC_EXECUTOR_H_
2#define BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SYMBOLIC_EXECUTOR_SYMBOLIC_EXECUTOR_H_
3
4#include <functional>
5#include <iosfwd>
6#include <vector>
7
8#include "ir/solver.h"
9#include "midend/coverage.h"
10
11#include "backends/p4tools/modules/testgen/core/program_info.h"
12#include "backends/p4tools/modules/testgen/core/small_step/small_step.h"
13#include "backends/p4tools/modules/testgen/lib/execution_state.h"
14#include "backends/p4tools/modules/testgen/lib/final_state.h"
15
16namespace P4::P4Tools::P4Testgen {
17
22 public:
23 virtual ~SymbolicExecutor() = default;
24
25 SymbolicExecutor(const SymbolicExecutor &) = default;
26
28
29 SymbolicExecutor &operator=(const SymbolicExecutor &) = delete;
30
31 SymbolicExecutor &operator=(SymbolicExecutor &&) = delete;
32
36 using Callback = std::function<bool(const FinalState &)>;
37
39
40 using StepResult = SmallStepEvaluator::Result;
41
45 virtual void run(const Callback &callBack);
46
47 virtual void runImpl(const Callback &callBack, ExecutionStateReference executionState) = 0;
48
50
52 void printCurrentTraceAndBranches(std::ostream &out, const ExecutionState &executionState);
53
56
58 [[nodiscard]] bool updateVisitedNodes(const P4::Coverage::CoverageSet &newNodes);
59
60 protected:
63
66
69
72
77 bool handleTerminalState(const Callback &callback, const ExecutionState &terminalState);
78
80 StepResult step(ExecutionState &state);
81
86
88 // Remove the branch from the container.
90 std::vector<SymbolicExecutor::Branch> &candidateBranches);
91
92 private:
93 SmallStepEvaluator evaluator;
94};
95
96} // namespace P4::P4Tools::P4Testgen
97
98#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SYMBOLIC_EXECUTOR_SYMBOLIC_EXECUTOR_H_ */
Provides a higher-level interface for an SMT solver.
Definition solver.h:24
Represents state of execution after having reached a program point.
Definition execution_state.h:34
Represents the final state after execution.
Definition final_state.h:19
Stores target-specific information about a P4 program.
Definition core/program_info.h:21
Definition symbolic_executor.h:21
static SymbolicExecutor::Branch popRandomBranch(std::vector< SymbolicExecutor::Branch > &candidateBranches)
Select a branch at random from the input.
Definition symbolic_executor.cpp:82
static bool evaluateBranch(const SymbolicExecutor::Branch &branch, AbstractSolver &solver)
Definition symbolic_executor.cpp:66
bool updateVisitedNodes(const P4::Coverage::CoverageSet &newNodes)
Update the set of visited nodes. Returns true if there was an update.
Definition symbolic_executor.cpp:103
StepResult step(ExecutionState &state)
Take one step in the program and return list of possible branches.
Definition symbolic_executor.cpp:25
const P4::Coverage::CoverageSet & getVisitedNodes()
Getter to access visitedNodes.
Definition symbolic_executor.cpp:111
const P4::Coverage::CoverageSet & coverableNodes
Set of all nodes, to be retrieved from programInfo.
Definition symbolic_executor.h:68
const ProgramInfo & programInfo
Target-specific information about the P4 program.
Definition symbolic_executor.h:62
AbstractSolver & solver
The SMT solver backing this executor.
Definition symbolic_executor.h:65
bool handleTerminalState(const Callback &callback, const ExecutionState &terminalState)
Definition symbolic_executor.cpp:44
std::function< bool(const FinalState &)> Callback
Definition symbolic_executor.h:36
virtual void run(const Callback &callBack)
Definition symbolic_executor.cpp:40
P4::Coverage::CoverageSet visitedNodes
Set of all nodes executed in any testcase that has been outputted.
Definition symbolic_executor.h:71
void printCurrentTraceAndBranches(std::ostream &out, const ExecutionState &executionState)
Writes a list of the selected branches into.
Definition symbolic_executor.cpp:113
std::set< const IR::Node *, SourceIdCmp > CoverageSet
Definition coverage.h:39