Skip to content

Commit

Permalink
Add optional matches for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy committed Mar 13, 2023
1 parent 6af3b44 commit 56c9e73
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
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

0 comments on commit 56c9e73

Please sign in to comment.