1#ifndef BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_TEST_SPEC_H_
2#define BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_TEST_SPEC_H_
9#include "backends/p4tools/common/lib/model.h"
10#include "backends/p4tools/common/lib/trace_event.h"
12#include "lib/cstring.h"
14#include "backends/p4tools/modules/testgen/lib/test_object.h"
16namespace P4::P4Tools::P4Testgen {
33 const IR::Expression *payload;
36 const IR::Expression *payloadIgnoreMask;
39 Packet(
int port,
const IR::Expression *payload,
const IR::Expression *payloadIgnoreMask);
46 [[nodiscard]]
int getPort()
const;
68 const IR::Parameter *param;
71 const IR::Expression *value;
74 ActionArg(
const IR::Parameter *param,
const IR::Expression *value);
80 [[nodiscard]]
const IR::Parameter *getActionParam()
const;
99 const IR::P4Action *action;
102 const std::vector<ActionArg> args;
105 ActionCall(
cstring identifier,
const IR::P4Action *action, std::vector<ActionArg> args);
107 ActionCall(
const IR::P4Action *action, std::vector<ActionArg> args);
118 [[nodiscard]]
const IR::P4Action *
getAction()
const;
121 [[nodiscard]]
const std::vector<ActionArg> *
getArgs()
const;
129 const IR::KeyElement *key;
132 explicit TableMatch(
const IR::KeyElement *key);
135 [[nodiscard]]
const IR::KeyElement *
getKey()
const;
140using TableMatchMap = std::map<cstring, const TableMatch *>;
145 const IR::Expression *value;
148 const IR::Expression *mask;
151 explicit Ternary(
const IR::KeyElement *key,
const IR::Expression *value,
152 const IR::Expression *mask);
174 const IR::Expression *value;
177 const IR::Expression *prefixLength;
180 explicit LPM(
const IR::KeyElement *key,
const IR::Expression *value,
181 const IR::Expression *prefixLength);
183 [[nodiscard]]
const LPM *
evaluate(
const Model &model,
bool doComplete)
const override;
203 const IR::Expression *value;
206 explicit Exact(
const IR::KeyElement *key,
const IR::Expression *value);
208 [[nodiscard]]
const Exact *
evaluate(
const Model &model,
bool doComplete)
const override;
222 const TableMatchMap matches;
239 [[nodiscard]]
const TableMatchMap *
getMatches()
const;
248 [[nodiscard]]
int getTTL()
const;
256 const IR::P4Table *table;
259 const std::vector<TableRule> rules;
265 explicit TableConfig(
const IR::P4Table *table, std::vector<TableRule> rules);
267 explicit TableConfig(
const IR::P4Table *table, std::vector<TableRule> rules,
270 [[nodiscard]]
const IR::P4Table *getTable()
const;
277 [[nodiscard]]
const std::vector<TableRule> *
getRules()
const;
299 const Packet ingressPacket;
303 const std::optional<Packet> egressPacket;
306 const std::vector<std::reference_wrapper<const TraceEvent>> traces;
310 std::map<cstring, TestObjectMap> testObjects;
313 TestSpec(
Packet ingressPacket, std::optional<Packet> egressPacket,
314 std::vector<std::reference_wrapper<const TraceEvent>> traces);
332 const auto *testObject =
getTestObject(category, objectLabel, checked);
333 return testObject->checkedTo<T>();
343 [[nodiscard]]
const std::map<cstring, const TableConfig> *
getTables()
const;
349 [[nodiscard]]
const std::vector<std::reference_wrapper<const TraceEvent>> *
getTraces()
const;
353 static constexpr int LOW_PRIORITY = 1;
354 static constexpr int HIGH_PRIORITY = 100;
355 static constexpr int TTL = 0;