P4C
The P4 Compiler
Loading...
Searching...
No Matches
pna/backend/ptf/ptf.h
1#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_BACKEND_PTF_PTF_H_
2#define BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_BACKEND_PTF_PTF_H_
3
4#include <cstddef>
5#include <filesystem>
6#include <fstream>
7#include <optional>
8#include <string>
9#include <utility>
10#include <vector>
11
12#include <inja/inja.hpp>
13
15#include "ir/ir.h"
16#include "lib/cstring.h"
17
18#include "backends/p4tools/modules/testgen/lib/test_framework.h"
19#include "backends/p4tools/modules/testgen/lib/test_object.h"
20#include "backends/p4tools/modules/testgen/lib/test_spec.h"
21
23
25class PTF : public TestFramework {
27 bool preambleEmitted = false;
28
30 std::ofstream ptfFileStream;
31
32 public:
33 ~PTF() override = default;
34 PTF(const PTF &) = delete;
35 PTF(PTF &&) = delete;
36 PTF &operator=(const PTF &) = delete;
37 PTF &operator=(PTF &&) = delete;
38
39 explicit PTF(const TestBackendConfiguration &testBackendConfiguration);
40
42 void writeTestToFile(const TestSpec *spec, cstring selectedBranches, size_t testId,
43 float currentCoverage) override;
44
45 private:
48 void emitPreamble();
49
55 void emitTestcase(const TestSpec *testSpec, cstring selectedBranches, size_t testId,
56 const std::string &testCase, float currentCoverage);
57
59 static std::string getTestCaseTemplate();
60
62 static inja::json getControlPlane(const TestSpec *testSpec);
63
65 static inja::json getSend(const TestSpec *testSpec);
66
68 static inja::json getVerify(const TestSpec *testSpec);
69
72 static std::vector<std::pair<size_t, size_t>> getIgnoreMasks(const IR::Constant *mask);
73
75 static inja::json getControlPlaneForTable(const TableMatchMap &matches,
76 const std::vector<ActionArg> &args);
77};
78
79} // namespace P4::P4Tools::P4Testgen::Pna
80
81#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_BACKEND_PTF_PTF_H_ */
Extracts information from the @testSpec to emit a PTF test case.
Definition pna/backend/ptf/ptf.h:25
void writeTestToFile(const TestSpec *spec, cstring selectedBranches, size_t testId, float currentCoverage) override
Produce a PTF test.
Definition pna/backend/ptf/ptf.cpp:242
Definition test_framework.h:54
Definition lib/test_spec.h:296
Definition cstring.h:85
Inja.
Definition pna/backend/metadata/metadata.cpp:24
Definition test_backend_configuration.h:16