Skip to content

Commit

Permalink
Review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy-g committed Nov 21, 2023
1 parent bf964c5 commit a9f7462
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ inja::json Protobuf::getExpectedPacket(const TestSpec *testSpec) const {

std::string Protobuf::getTestCaseTemplate() {
static std::string TEST_CASE(
R"""(# A P4TestGen-generated test case for {{test_name}}.p4
R"""(
# proto-file: p4testgen.proto
# proto-message: TestCase
# A P4TestGen-generated test case for {{test_name}}.p4
metadata: "p4testgen seed: {{ default(seed, "none") }}"
metadata: "Date generated: {{timestamp}}"
## if length(selected_branches) > 0
Expand All @@ -241,99 +244,97 @@ expected_output_packet {
## endif
## if control_plane
entities : [
## for table in control_plane.tables
## for rule in table.rules
# Table {{table.table_name}}
{
table_entry {
table_id: {{table.id}}
# Table {{table.table_name}}
entities {
table_entry {
table_id: {{table.id}}
## if rule.rules.needs_priority
priority: {{rule.priority}}
priority: {{rule.priority}}
## endif
## for r in rule.rules.single_exact_matches
# Match field {{r.field_name}}
match {
field_id: {{r.id}}
exact {
value: "{{r.value}}"
}
}
## endfor
## for r in rule.rules.optional_matches
# Match field {{r.field_name}}
match {
field_id: {{r.id}}
optional {
exact {
value: "{{r.value}}"
}
}
## endfor
## for r in rule.rules.optional_matches
# Match field {{r.field_name}}
match {
field_id: {{r.id}}
optional {
value: "{{r.value}}"
}
}
## endfor
## for r in rule.rules.range_matches
# Match field {{r.field_name}}
match {
field_id: {{r.id}}
range {
low: "{{r.lo}}"
high: "{{r.hi}}"
}
# Match field {{r.field_name}}
match {
field_id: {{r.id}}
range {
low: "{{r.lo}}"
high: "{{r.hi}}"
}
}
## endfor
## for r in rule.rules.ternary_matches
# Match field {{r.field_name}}
match {
field_id: {{r.id}}
ternary {
value: "{{r.value}}"
mask: "{{r.mask}}"
}
# Match field {{r.field_name}}
match {
field_id: {{r.id}}
ternary {
value: "{{r.value}}"
mask: "{{r.mask}}"
}
}
## endfor
## for r in rule.rules.lpm_matches
# Match field {{r.field_name}}
match {
field_id: {{r.id}}
lpm {
value: "{{r.value}}"
prefix_len: {{r.prefix_len}}
}
# Match field {{r.field_name}}
match {
field_id: {{r.id}}
lpm {
value: "{{r.value}}"
prefix_len: {{r.prefix_len}}
}
}
## endfor
# Action {{rule.action_name}}
action {
# Action {{rule.action_name}}
action {
## if existsIn(table, "has_ap")
action_profile_action_set {
action_profile_actions {
action {
action_id: {{rule.action_id}}
action_profile_action_set {
action_profile_actions {
action {
action_id: {{rule.action_id}}
## for act_param in rule.rules.act_args
# Param {{act_param.param}}
params {
param_id: {{act_param.id}}
value: "{{act_param.value}}"
}
## endfor
# Param {{act_param.param}}
params {
param_id: {{act_param.id}}
value: "{{act_param.value}}"
}
## endfor
}
}
}
## else
action {
action_id: {{rule.action_id}}
action {
action_id: {{rule.action_id}}
## for act_param in rule.rules.act_args
# Param {{act_param.param}}
params {
param_id: {{act_param.id}}
value: "{{act_param.value}}"
}
## endfor
# Param {{act_param.param}}
params {
param_id: {{act_param.id}}
value: "{{act_param.value}}"
}
## endif
}
## endfor
}
## endif
}
}{% if not loop.is_last %},{% endif %}
## endfor
]
}
}
## endfor
## endif
)""");
return TEST_CASE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ ProtobufIr::ProtobufIr(std::filesystem::path basePath, std::optional<unsigned in

std::string ProtobufIr::getTestCaseTemplate() {
static std::string TEST_CASE(
R"""(# A P4TestGen-generated test case for {{test_name}}.p4
R"""(# proto-file: p4testgen_ir.proto
# proto-message: TestCase
# A P4TestGen-generated test case for {{test_name}}.p4
metadata: "p4testgen seed: {{ default(seed, "none") }}"
metadata: "Date generated: {{timestamp}}"
## if length(selected_branches) > 0
Expand All @@ -45,95 +48,93 @@ expected_output_packet {
## endif
## if control_plane
entities : [
## for table in control_plane.tables
## for rule in table.rules
# Table {{table.table_name}}
{
table_entry {
table_name: "{{table.table_name}}"
# Table {{table.table_name}}
entities {
table_entry {
table_name: "{{table.table_name}}"
## if rule.rules.needs_priority
priority: {{rule.priority}}
priority: {{rule.priority}}
## endif
## for r in rule.rules.single_exact_matches
# Match field {{r.field_name}}
matches {
name: "{{r.field_name}}"
exact: { hex_str: "{{r.value}}" }
}
## endfor
## for r in rule.rules.optional_matches
# Match field {{r.field_name}}
matches {
name: "{{r.field_name}}"
optional {
value: { hex_str: "{{r.value}}" }
}
exact: { hex_str: "{{r.value}}" }
}
## endfor
## for r in rule.rules.optional_matches
# Match field {{r.field_name}}
matches {
name: "{{r.field_name}}"
optional {
value: { hex_str: "{{r.value}}" }
}
}
## endfor
## for r in rule.rules.range_matches
# Match field {{r.field_name}}
matches {
name: "{{r.field_name}}"
range {
low: { hex_str: "{{r.lo}}" }
high: { hex_str: "{{r.hi}}" }
}
# Match field {{r.field_name}}
matches {
name: "{{r.field_name}}"
range {
low: { hex_str: "{{r.lo}}" }
high: { hex_str: "{{r.hi}}" }
}
}
## endfor
## for r in rule.rules.ternary_matches
# Match field {{r.field_name}}
matches {
name: "{{r.field_name}}"
ternary {
value: { hex_str: "{{r.value}}" }
mask: { hex_str: "{{r.mask}}" }
}
# Match field {{r.field_name}}
matches {
name: "{{r.field_name}}"
ternary {
value: { hex_str: "{{r.value}}" }
mask: { hex_str: "{{r.mask}}" }
}
}
## endfor
## for r in rule.rules.lpm_matches
# Match field {{r.field_name}}
matches {
name: "{{r.field_name}}"
lpm {
value: { hex_str: "{{r.value}}" }
prefix_length: {{r.prefix_len}}
}
# Match field {{r.field_name}}
matches {
name: "{{r.field_name}}"
lpm {
value: { hex_str: "{{r.value}}" }
prefix_length: {{r.prefix_len}}
}
}
## endfor
# Action {{rule.action_name}}
# Action {{rule.action_name}}
## if existsIn(table, "has_ap")
action_set {
actions {
action {
name: "{{rule.action_name}}"
action_set {
actions {
action {
name: "{{rule.action_name}}"
## for act_param in rule.rules.act_args
# Param {{act_param.param}}
params {
name: "{{act_param.param}}"
value: { hex_str: "{{act_param.value}}" }
}
## endfor
# Param {{act_param.param}}
params {
name: "{{act_param.param}}"
value: { hex_str: "{{act_param.value}}" }
}
## endfor
}
}
}
## else
action {
name: "{{rule.action_name}}"
action {
name: "{{rule.action_name}}"
## for act_param in rule.rules.act_args
# Param {{act_param.param}}
params {
name: "{{act_param.param}}"
value: { hex_str: "{{act_param.value}}" }
}
# Param {{act_param.param}}
params {
name: "{{act_param.param}}"
value: { hex_str: "{{act_param.value}}" }
}
## endfor
}
}
## endif
## endfor
}
}{% if not loop.is_last %},{% endif %}
}
}
## endfor
]
## endif
)""");
return TEST_CASE;
Expand Down

0 comments on commit a9f7462

Please sign in to comment.