P4C
The P4 Compiler
Loading...
Searching...
No Matches
protobuf_ir.h
1#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_PROTOBUF_IR_H_
2#define BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_PROTOBUF_IR_H_
3
4#include <cstddef>
5#include <string>
6#include <utility>
7
8#include <inja/inja.hpp>
9
10#include "control-plane/p4RuntimeSerializer.h"
11#include "lib/cstring.h"
12
13#include "backends/p4tools/modules/testgen/lib/test_spec.h"
14#include "backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.h"
15
17
19 private:
21 std::string formattedTest_;
22
23 public:
24 explicit ProtobufIrTest(std::string formattedTest) : formattedTest_(std::move(formattedTest)) {}
25
27 [[nodiscard]] const std::string &getFormattedTest() const { return formattedTest_; }
28
29 DECLARE_TYPEINFO(ProtobufIrTest);
30};
31
34 public:
35 explicit ProtobufIr(const TestBackendConfiguration &testBackendConfiguration,
36 P4::P4RuntimeAPI p4RuntimeApi);
37
38 ~ProtobufIr() override = default;
39 ProtobufIr(const ProtobufIr &) = default;
40 ProtobufIr(ProtobufIr &&) = default;
41 ProtobufIr &operator=(const ProtobufIr &) = default;
42 ProtobufIr &operator=(ProtobufIr &&) = default;
43
44 void writeTestToFile(const TestSpec *testSpec, cstring selectedBranches, size_t testId,
45 float currentCoverage) override;
46
47 AbstractTestReferenceOrError produceTest(const TestSpec *testSpec, cstring selectedBranches,
48 size_t testIdx, float currentCoverage) override;
49
50 private:
53 P4::P4RuntimeAPI p4RuntimeApi;
54
55 [[nodiscard]] inja::json getControlPlaneTable(const TableConfig &tblConfig) const override;
56
57 [[nodiscard]] inja::json getControlPlaneForTable(
58 const TableMatchMap &matches, const std::vector<ActionArg> &args) const override;
59
60 [[nodiscard]] inja::json getSend(const TestSpec *testSpec) const override;
61
62 [[nodiscard]] inja::json getExpectedPacket(const TestSpec *testSpec) const override;
63
69 inja::json produceTestCase(const TestSpec *testSpec, cstring selectedBranches, size_t testId,
70 float currentCoverage) const;
71
73 static std::string getTestCaseTemplate();
74
77 static std::optional<std::string> checkForP4RuntimeTranslationAnnotation(
78 const IR::IAnnotated *node);
79
82 static std::map<cstring, cstring> getP4RuntimeTranslationMappings(const IR::IAnnotated *node);
83
86 static std::string getFormatOfNode(const IR::IAnnotated *node);
87
89 static std::string formatNetworkValue(const std::string &type, const IR::Expression *value);
90
92 static std::string formatNetworkValue(const IR::IAnnotated *node, const std::string &type,
93 const IR::Expression *value);
94
97 static void createKeyMatch(cstring fieldName, const TableMatch &fieldMatch,
98 inja::json &rulesJson);
99};
100
101} // namespace P4::P4Tools::P4Testgen::Bmv2
102
103#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_PROTOBUF_IR_H_ */
Bmv2TestFramework provides common utility functions for BMv2-style test frameworks.
Definition common.h:17
Extracts information from the @testSpec to emit a Protobuf IR test case.
Definition protobuf_ir.h:33
AbstractTestReferenceOrError produceTest(const TestSpec *testSpec, cstring selectedBranches, size_t testIdx, float currentCoverage) override
Definition protobuf_ir.cpp:339
void writeTestToFile(const TestSpec *testSpec, cstring selectedBranches, size_t testId, float currentCoverage) override
Definition protobuf_ir.cpp:324
Definition lib/test_spec.h:253
Definition lib/test_spec.h:126
Definition lib/test_spec.h:296
Definition cstring.h:85
Inja.
Definition targets/bmv2/cmd_stepper.cpp:33
Definition p4RuntimeSerializer.h:57
Type definitions for abstract tests.
Definition test_framework.h:29
const std::string & getFormattedTest() const
Definition protobuf_ir.h:27
Definition test_backend_configuration.h:16