P4C
The P4 Compiler
Loading...
Searching...
No Matches
lib/test_backend.h
1#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_TEST_BACKEND_H_
2#define BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_TEST_BACKEND_H_
3
4#include <cstdint>
5#include <functional>
6#include <optional>
7#include <vector>
8
9#include "backends/p4tools/common/lib/model.h"
10#include "backends/p4tools/common/lib/trace_event.h"
11#include "ir/ir.h"
12
13#include "backends/p4tools/modules/testgen/core/program_info.h"
14#include "backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.h"
15#include "backends/p4tools/modules/testgen/lib/execution_state.h"
16#include "backends/p4tools/modules/testgen/lib/final_state.h"
17#include "backends/p4tools/modules/testgen/lib/test_framework.h"
18#include "backends/p4tools/modules/testgen/lib/test_spec.h"
19#include "backends/p4tools/modules/testgen/options.h"
20
21namespace P4::P4Tools::P4Testgen {
22
24 private:
26 int64_t testCount = 0;
27
29 static const int64_t RESET_THRESHOLD = 10000;
30
32 std::reference_wrapper<const ProgramInfo> programInfo;
33
35 std::reference_wrapper<const TestBackendConfiguration> testBackendConfiguration;
36
37 protected:
40
44
46 int64_t maxTests;
47
49 float coverage = 0;
50
52 AbstractTestList tests;
53
54 explicit TestBackEnd(const ProgramInfo &programInfo,
55 const TestBackendConfiguration &testBackendConfiguration,
57
58 [[nodiscard]] bool needsToTerminate(int64_t testCount) const;
59
60 public:
61 TestBackEnd(const TestBackEnd &) = default;
62
63 TestBackEnd(TestBackEnd &&) = default;
64
65 TestBackEnd &operator=(const TestBackEnd &) = delete;
66
67 TestBackEnd &operator=(TestBackEnd &&) = delete;
68
69 virtual ~TestBackEnd() = default;
70
71 struct TestInfo {
74 const IR::Constant *inputPacket;
75
78
80 const IR::Constant *outputPacket;
81
84
86 const IR::Constant *packetTaintMask;
87
89 const std::vector<std::reference_wrapper<const TraceEvent>> programTraces;
90
92 bool packetIsDropped = false;
93 };
94
96 virtual const TestSpec *createTestSpec(const ExecutionState *executionState,
97 const Model *finalModel, const TestInfo &testInfo) = 0;
98
102 virtual bool printTestInfo(const ExecutionState *executionState, const TestInfo &testInfo,
103 const IR::Expression *outputPortExpr);
104
106 [[nodiscard]] std::optional<std::reference_wrapper<const FinalState>> computeConcolicVariables(
107 const FinalState &state) const;
108
112 const ExecutionState *executionState, const Model *finalModel,
113 const IR::Expression *outputPacketExpr, const IR::Expression *outputPortExpr,
114 const std::vector<std::reference_wrapper<const TraceEvent>> *programTraces);
115
117 virtual bool run(const FinalState &state);
118
120 [[nodiscard]] int64_t getTestCount() const;
121
123 [[nodiscard]] float getCoverage() const;
124
126 [[nodiscard]] const ProgramInfo &getProgramInfo() const;
127
129 [[nodiscard]] const TestBackendConfiguration &getTestBackendConfiguration() const;
130
133 [[nodiscard]] const AbstractTestList &getTests() const { return tests; }
134};
135
136} // namespace P4::P4Tools::P4Testgen
137
138#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_TEST_BACKEND_H_ */
Definition backends/p4tools/common/lib/model.h:19
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
Definition lib/test_backend.h:23
int inputPort
The input port of the packet.
Definition lib/test_backend.h:77
const IR::Constant * packetTaintMask
The taint mask.
Definition lib/test_backend.h:86
const AbstractTestList & getTests() const
Definition lib/test_backend.h:133
int64_t getTestCount() const
Returns test count.
Definition lib/test_backend.cpp:270
TestFramework * testWriter
Writes the tests out to a file.
Definition lib/test_backend.h:39
float coverage
The accumulated coverage of all finished test cases. Number in range [0, 1].
Definition lib/test_backend.h:49
AbstractTestList tests
The list of tests accumulated in the test back end.
Definition lib/test_backend.h:52
int64_t maxTests
Test maximum number of tests that are to be produced.
Definition lib/test_backend.h:46
int outputPort
The output port of the packet.
Definition lib/test_backend.h:83
std::optional< std::reference_wrapper< const FinalState > > computeConcolicVariables(const FinalState &state) const
virtual TestInfo produceTestInfo(const ExecutionState *executionState, const Model *finalModel, const IR::Expression *outputPacketExpr, const IR::Expression *outputPortExpr, const std::vector< std::reference_wrapper< const TraceEvent > > *programTraces)
Definition lib/test_backend.cpp:185
const IR::Constant * outputPacket
The concrete value of the output packet as modified by the packet.
Definition lib/test_backend.h:80
const IR::Constant * inputPacket
Definition lib/test_backend.h:74
SymbolicExecutor & symbex
Definition lib/test_backend.h:43
virtual bool run(const FinalState &state)
The callback that is executed by the symbolic executor.
Definition lib/test_backend.cpp:43
const std::vector< std::reference_wrapper< const TraceEvent > > programTraces
The traces that have been collected during execution of this particular test path.
Definition lib/test_backend.h:89
const TestBackendConfiguration & getTestBackendConfiguration() const
Returns the configuration options for the test back end.
Definition lib/test_backend.cpp:276
virtual bool printTestInfo(const ExecutionState *executionState, const TestInfo &testInfo, const IR::Expression *outputPortExpr)
Definition lib/test_backend.cpp:223
virtual const TestSpec * createTestSpec(const ExecutionState *executionState, const Model *finalModel, const TestInfo &testInfo)=0
bool packetIsDropped
Indicates whether the packet is dropped.
Definition lib/test_backend.h:92
float getCoverage() const
Returns coverage achieved by all the processed tests.
Definition lib/test_backend.cpp:272
const ProgramInfo & getProgramInfo() const
Returns the program info.
Definition lib/test_backend.cpp:274
Definition lib/test_backend.h:71
Definition test_framework.h:54
Definition lib/test_spec.h:296
Definition test_backend_configuration.h:16