P4C
The P4 Compiler
Loading...
Searching...
No Matches
common.h
1/*
2 * SPDX-FileCopyrightText: 2023 Google LLC
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_COMMON_H_
8#define BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_COMMON_H_
9
10#include <filesystem>
11#include <optional>
12#include <vector>
13
14#include <inja/inja.hpp>
15
16#include "backends/p4tools/modules/testgen/lib/test_framework.h"
17#include "backends/p4tools/modules/testgen/lib/test_object.h"
18#include "backends/p4tools/modules/testgen/lib/test_spec.h"
19
21
23class Bmv2TestFramework : public TestFramework {
24 public:
25 explicit Bmv2TestFramework(const TestBackendConfiguration &testBackendConfiguration);
26
27 protected:
29 static std::string formatHexExpressionWithSeparators(const IR::Expression &expr);
30
32 virtual inja::json getControlPlane(const TestSpec *testSpec) const;
33
35 [[nodiscard]] virtual inja::json getClone(const TestObjectMap &cloneSpecs) const;
36
38 [[nodiscard]] virtual inja::json::array_t getMeter(const TestObjectMap &meterValues) const;
39
41 [[nodiscard]] virtual inja::json getControlPlaneTable(const TableConfig &tblConfig) const;
42
44 [[nodiscard]] virtual inja::json getControlPlaneForTable(
45 const TableMatchMap &matches, const std::vector<ActionArg> &args) const;
46
48 virtual inja::json getSend(const TestSpec *testSpec) const;
49
51 virtual inja::json getExpectedPacket(const TestSpec *testSpec) const;
52};
53} // namespace P4::P4Tools::P4Testgen::Bmv2
54
55#endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_COMMON_H_ */
static std::string formatHexExpressionWithSeparators(const IR::Expression &expr)
Wrapper helper function that automatically inserts separators for hex strings.
Definition common.cpp:29
virtual inja::json::array_t getMeter(const TestObjectMap &meterValues) const
Definition common.cpp:51
virtual inja::json getControlPlaneTable(const TableConfig &tblConfig) const
Converts a table configuration into Inja format.
Definition common.cpp:73
virtual inja::json getExpectedPacket(const TestSpec *testSpec) const
Converts the output packet, port, and mask into Inja format.
Definition common.cpp:210
virtual inja::json getControlPlaneForTable(const TableMatchMap &matches, const std::vector< ActionArg > &args) const
Helper function for the control plane table inja objects.
Definition common.cpp:136
virtual inja::json getControlPlane(const TestSpec *testSpec) const
Converts all the control plane objects into Inja format.
Definition common.cpp:92
virtual inja::json getClone(const TestObjectMap &cloneSpecs) const
Returns the configuration for a cloned packet configuration.
Definition common.cpp:33
virtual inja::json getSend(const TestSpec *testSpec) const
Converts the input packet and port into Inja format.
Definition common.cpp:199
Definition lib/test_spec.h:260
TestFramework(const TestBackendConfiguration &testBackendConfiguration)
Creates a generic test framework.
Definition test_framework.cpp:11
Definition lib/test_spec.h:303
Inja.
Definition targets/bmv2/cmd_stepper.cpp:37
Definition test_backend_configuration.h:22