Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an explicit optional match key type. #3920

Merged
merged 3 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add optional matches for now.
  • Loading branch information
fruffy committed Mar 13, 2023
commit b9a25459398155283673334837ae5a0363e4d040
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@
#include "backends/p4tools/modules/testgen/lib/tf.h"
#include "backends/p4tools/modules/testgen/targets/bmv2/test_spec.h"

namespace P4Tools {

namespace P4Testgen {

namespace Bmv2 {
namespace P4Tools::P4Testgen::Bmv2 {

/// Wrapper helper function that automatically inserts separators for hex strings.
std::string formatHexExprWithSep(const IR::Expression *expr) {
Expand Down Expand Up @@ -178,6 +174,7 @@ inja::json Protobuf::getControlPlaneForTable(const std::map<cstring, const Field
rulesJson["range_matches"] = inja::json::array();
rulesJson["ternary_matches"] = inja::json::array();
rulesJson["lpm_matches"] = inja::json::array();
rulesJson["optional_matches"] = inja::json::array();
rulesJson["act_args"] = inja::json::array();
rulesJson["needs_priority"] = false;

Expand Down Expand Up @@ -240,6 +237,9 @@ inja::json Protobuf::getControlPlaneForTable(const std::map<cstring, const Field
inja::json j;
j["field_name"] = fieldName;
j["value"] = formatHexExpr(elem.getEvaluatedValue()).c_str();
auto p4RuntimeId = getIdAnnotation(elem.getKey());
BUG_CHECK(p4RuntimeId, "Id not present for key. Can not generate test.");
j["id"] = *p4RuntimeId;
rulesJson["needs_priority"] = true;
rulesJson["optional_matches"].push_back(j);
}
Expand Down Expand Up @@ -449,8 +449,4 @@ void Protobuf::outputTest(const TestSpec *testSpec, cstring selectedBranches, si
emitTestcase(testSpec, selectedBranches, testIdx, testCase, currentCoverage);
}

} // namespace Bmv2

} // namespace P4Testgen

} // namespace P4Tools
} // namespace P4Tools::P4Testgen::Bmv2
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ inja::json PTF::getControlPlaneForTable(const std::map<cstring, const FieldMatch
rulesJson["range_matches"] = inja::json::array();
rulesJson["ternary_matches"] = inja::json::array();
rulesJson["lpm_matches"] = inja::json::array();
rulesJson["optional_matches"] = inja::json::array();

rulesJson["act_args"] = inja::json::array();
rulesJson["needs_priority"] = false;
Expand Down
12 changes: 2 additions & 10 deletions backends/p4tools/modules/testgen/targets/bmv2/backend/stf/stf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@
#include "backends/p4tools/modules/testgen/lib/tf.h"
#include "backends/p4tools/modules/testgen/targets/bmv2/test_spec.h"

namespace P4Tools {

namespace P4Testgen {

namespace Bmv2 {
namespace P4Tools::P4Testgen::Bmv2 {

STF::STF(cstring testName, boost::optional<unsigned int> seed = boost::none) : TF(testName, seed) {
boost::filesystem::path testFile(testName + ".stf");
Expand Down Expand Up @@ -339,8 +335,4 @@ void STF::outputTest(const TestSpec *testSpec, cstring selectedBranches, size_t
emitTestcase(testSpec, selectedBranches, testIdx, testCase, currentCoverage);
}

} // namespace Bmv2

} // namespace P4Testgen

} // namespace P4Tools
} // namespace P4Tools::P4Testgen::Bmv2