P4C
The P4 Compiler
Loading...
Searching...
No Matches
bmv2/test_backend/ptf.h
1#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_PTF_H_
2#define BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_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_object.h"
19#include "backends/p4tools/modules/testgen/lib/test_spec.h"
20#include "backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.h"
21
23
25class PTF : public Bmv2TestFramework {
26 public:
27 explicit PTF(const TestBackendConfiguration &testBackendConfiguration);
28
30 void writeTestToFile(const TestSpec *spec, cstring selectedBranches, size_t testId,
31 float currentCoverage) override;
32
33 private:
35 bool preambleEmitted = false;
36
38 std::ofstream ptfFileStream;
39
42 void emitPreamble();
43
49 void emitTestcase(const TestSpec *testSpec, cstring selectedBranches, size_t testId,
50 const std::string &testCase, float currentCoverage);
51
53 static std::string getTestCaseTemplate();
54
55 inja::json getExpectedPacket(const TestSpec *testSpec) const override;
56
59 static std::vector<std::pair<size_t, size_t>> getIgnoreMasks(const IR::Constant *mask);
60};
61
62} // namespace P4::P4Tools::P4Testgen::Bmv2
63
64#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_PTF_H_ */
Bmv2TestFramework provides common utility functions for BMv2-style test frameworks.
Definition common.h:17
Extracts information from the @testSpec to emit a PTF test case.
Definition bmv2/test_backend/ptf.h:25
void writeTestToFile(const TestSpec *spec, cstring selectedBranches, size_t testId, float currentCoverage) override
Produce a PTF test.
Definition bmv2/test_backend/ptf.cpp:129
Definition lib/test_spec.h:296
Definition cstring.h:85
Inja.
Definition targets/bmv2/cmd_stepper.cpp:33
Definition test_backend_configuration.h:16