Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into saip4_31
  • Loading branch information
divyagayathri-hcl committed Oct 5, 2024
2 parents 1a8b72d + dc7277b commit b5a65c6
Show file tree
Hide file tree
Showing 37 changed files with 2,059 additions and 455 deletions.
9 changes: 9 additions & 0 deletions gutil/proto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ absl::StatusOr<std::string> ProtoDiff(
return diff;
}

bool ProtoEqual(const google::protobuf::Message &message1,
const google::protobuf::Message &message2,
google::protobuf::util::MessageDifferencer &differ) {
if (message1.GetDescriptor() != message2.GetDescriptor()) {
return false;
}
return differ.Compare(message1, message2);
}

absl::StatusOr<std::string> GetOneOfFieldName(
const google::protobuf::Message &message, const std::string &oneof_name) {
const auto *oneof_descriptor =
Expand Down
5 changes: 5 additions & 0 deletions gutil/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ absl::StatusOr<std::string> ProtoDiff(
google::protobuf::util::MessageDifferencer differ =
google::protobuf::util::MessageDifferencer());

// Similar to `ProtoDiff`, execpt returns boolean result of equality comparison.
bool ProtoEqual(const google::protobuf::Message &message1,
const google::protobuf::Message &message2,
google::protobuf::util::MessageDifferencer &differ);

// Get the name of the oneof enum that is set.
// Eg:
// message IrValue {
Expand Down
88 changes: 60 additions & 28 deletions p4_fuzzer/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@com_github_p4lang_p4c//:bazel/p4_library.bzl", "p4_library")
load("//p4_pdpi/testing:diff_test.bzl", "cmd_diff_test")

package(
licenses = ["notice"],
Expand All @@ -25,7 +26,9 @@ cc_library(
deps = [
"//p4_pdpi:entity_keys",
"//gutil:collections",
"//gutil:proto",
"//gutil:status",
"//p4_pdpi:ir",
"//p4_pdpi:ir_cc_proto",
"//p4_pdpi/internal:ordered_map",
"@com_github_google_glog//:glog",
Expand All @@ -38,7 +41,9 @@ cc_library(
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/types:optional",
],
"@com_google_absl//absl/types:span",
"@com_google_protobuf//:protobuf",
],
)

cc_test(
Expand All @@ -48,15 +53,18 @@ cc_test(
":switch_state",
":test_utils",
"//gutil:collections",
"//gutil:proto",
"//gutil:proto_matchers",
"//gutil:status_matchers",
"//p4_pdpi:ir",
"//p4_pdpi/testing:main_p4_pd_cc_proto",
"//p4_pdpi/testing:test_p4info_cc",
"//p4_pdpi:pd",
"@com_github_google_glog//:glog",
"@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:optional",
"@com_google_googletest//:gtest_main",
],
)
Expand Down Expand Up @@ -92,7 +100,11 @@ cc_library(
"fuzzer_config.h",
],
deps = [
":table_entry_key",
"//p4_pdpi:ir_cc_proto",
"@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
"@com_google_absl//absl/container:btree",
"@com_google_absl//absl/container:flat_hash_set",
],
)

Expand All @@ -113,15 +125,10 @@ cc_library(
":switch_state",
"//gutil:collections",
"//gutil:status",
"//p4_pdpi:ir",
"//p4_pdpi:ir_cc_proto",
"//p4_pdpi:pd",
"//p4_pdpi/internal:ordered_map",
"//p4_pdpi/netaddr:ipv6_address",
"//p4_pdpi/utils:ir",
"//sai_p4/instantiations/google:instantiations",
"//sai_p4/instantiations/google:sai_p4info_cc",
"//sai_p4/fixed:p4_ids",
"@com_github_google_glog//:glog",
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
"@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
Expand Down Expand Up @@ -152,17 +159,12 @@ cc_test(
":mutation_and_fuzz_util",
":test_utils",
"//gutil:collections",
"//gutil:proto",
"//gutil:proto_matchers",
"//gutil:status_matchers",
"//gutil:testing",
"//p4_pdpi:ir",
"//p4_pdpi:ir_cc_proto",
"//p4_pdpi:pd",
"//sai_p4/instantiations/google:instantiations",
"//sai_p4/instantiations/google:sai_p4info_cc",
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
"@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/random",
"@com_google_absl//absl/random:distributions",
"@com_google_absl//absl/random:seed_sequences",
Expand Down Expand Up @@ -276,6 +278,33 @@ cc_test(
],
)

cc_library(
name = "test_utils",
testonly = True,
srcs = ["test_utils.cc"],
hdrs = ["test_utils.h"],
deps = [
":fuzzer_config",
":mutation_and_fuzz_util",
":switch_state",
"//gutil:collections",
"//gutil:testing",
"//p4_pdpi:ir",
"//p4_pdpi:ir_cc_proto",
"//p4_pdpi/internal:ordered_map",
"//p4_pdpi/testing:test_p4info_cc",
"//sai_p4/instantiations/google:sai_p4info_cc",
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
"@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
"@com_google_absl//absl/random",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
],
)

# -- P4 libraries for testing -------------------------------------------------

p4_library(
name = "single_table_single_entry",
src = "p4_programs/single_table_single_entry.p4",
Expand Down Expand Up @@ -308,40 +337,43 @@ p4_library(
],
)

p4_library(
name = "sai_main",
src = "p4_programs/sai-p4-google/sai_main.p4",
p4info_out = "sai_main_info.pb.txt",
deps = glob(["p4_programs/sai-p4-google/*"]),
)

cc_library(
name = "acl_table_test_ids",
hdrs = ["p4_programs/sai-p4-google/ids.h"],
)

cc_library(
name = "test_utils",
testonly = True,
srcs = ["test_utils.cc"],
hdrs = ["test_utils.h"],
# go/golden-test-with-coverage
cc_test(
name = "switch_state_assert_entry_equality_test_runner",
srcs = ["switch_state_assert_entry_equality_test_runner.cc"],
linkstatic = True,
deps = [
":fuzzer_config",
":mutation_and_fuzz_util",
":switch_state",
"//gutil:collections",
"//gutil:testing",
"//p4_pdpi:ir",
"//p4_pdpi:ir_cc_proto",
"//p4_pdpi/internal:ordered_map",
"//p4_pdpi/testing:test_p4info_cc",
"//sai_p4/instantiations/google:sai_p4info_cc",
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
"@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
"@com_google_absl//absl/random",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:span",
"@com_google_protobuf//:protobuf",
],
)

p4_library(
name = "sai_main",
src = "p4_programs/sai-p4-google/sai_main.p4",
p4info_out = "sai_main_info.pb.txt",
deps = glob(["p4_programs/sai-p4-google/*"]),
cmd_diff_test(
name = "switch_state_assert_entry_equality_test",
actual_cmd = "$(execpath :switch_state_assert_entry_equality_test_runner)",
expected = ":switch_state_assert_entry_equality_test.expected.output",
tools = [":switch_state_assert_entry_equality_test_runner"],
)

Loading

0 comments on commit b5a65c6

Please sign in to comment.