P4C
The P4 Compiler
Loading...
Searching...
No Matches
protobuf.h
1#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_PROTOBUF_H_
2#define BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_PROTOBUF_H_
3
4#include <cstddef>
5#include <optional>
6#include <string>
7#include <vector>
8
9#include <inja/inja.hpp>
10
11#include "backends/p4tools/common/control_plane/p4info_map.h"
12#include "control-plane/p4RuntimeSerializer.h"
13#include "ir/ir.h"
14#include "lib/cstring.h"
15
16#include "backends/p4tools/modules/testgen/lib/test_spec.h"
17#include "backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.h"
18
20
21using P4::ControlPlaneAPI::p4rt_id_t;
22
23struct ProtobufTest : public AbstractTest {
24 private:
26 std::string formattedTest_;
27
28 public:
29 explicit ProtobufTest(std::string formattedTest) : formattedTest_(std::move(formattedTest)) {}
30
32 [[nodiscard]] const std::string &getFormattedTest() const { return formattedTest_; }
33
34 DECLARE_TYPEINFO(ProtobufTest);
35};
36
39 public:
40 explicit Protobuf(const TestBackendConfiguration &testBackendConfiguration,
41 P4::P4RuntimeAPI p4RuntimeApi);
42
43 void writeTestToFile(const TestSpec *testSpec, cstring selectedBranches, size_t testId,
44 float currentCoverage) override;
45
46 AbstractTestReferenceOrError produceTest(const TestSpec *testSpec, cstring selectedBranches,
47 size_t testIdx, float currentCoverage) override;
48
49 private:
52 P4::P4RuntimeAPI p4RuntimeApi;
53
56
57 inja::json getControlPlane(const TestSpec *testSpec) const override;
58
59 [[nodiscard]] inja::json getSend(const TestSpec *testSpec) const override;
60
61 [[nodiscard]] inja::json getExpectedPacket(const TestSpec *testSpec) const override;
62
64 static std::string formatHexExprWithSep(const IR::Expression *expr);
65
68 [[nodiscard]] std::optional<p4rt_id_t> lookupP4RuntimeId(cstring controlPlaneName) const;
69
72 void emitPreamble(const std::string &preamble);
73
79 inja::json produceTestCase(const TestSpec *testSpec, cstring selectedBranches, size_t testId,
80 float currentCoverage) const;
81
83 static std::string getTestCaseTemplate();
84
88 [[nodiscard]] inja::json getControlPlaneForTable(cstring tableName, cstring actionName,
89 const TableMatchMap &matches,
90 const std::vector<ActionArg> &args) const;
91};
92
93} // namespace P4::P4Tools::P4Testgen::Bmv2
94
95#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_PROTOBUF_H_ */
Definition p4info_map.h:37
Bmv2TestFramework provides common utility functions for BMv2-style test frameworks.
Definition common.h:17
Extracts information from the @testSpec to emit a Protobuf test case.
Definition protobuf.h:38
AbstractTestReferenceOrError produceTest(const TestSpec *testSpec, cstring selectedBranches, size_t testIdx, float currentCoverage) override
Definition protobuf.cpp:242
void writeTestToFile(const TestSpec *testSpec, cstring selectedBranches, size_t testId, float currentCoverage) override
Definition protobuf.cpp:227
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.h:32
Definition test_backend_configuration.h:16