Skip to content

Commit

Permalink
[Comb] Add StartBERT test. (sonic-net#351)
Browse files Browse the repository at this point in the history
* Fixing helper function to take care of OC paths containing values in [1/1] format. Implement portable Bazel test environment.

* Add thinkit MirrorTestbedTestFixture

PiperOrigin-RevId: 356313307

* Add StartBERT test.

---------

Co-authored-by: Srikishen Pondicherry Shanmugam <[email protected]>
Co-authored-by: bhagatgit <[email protected]>
  • Loading branch information
3 people authored Jul 18, 2024
1 parent 368d8d1 commit add04f9
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/gnoi/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//p4_pdpi/testing:diff_test.bzl", "cmd_diff_test", "diff_test")
load("//p4_pdpi:pdgen.bzl", "p4_pd_proto")
load("@com_github_p4lang_p4c//:bazel/p4_library.bzl", "p4_library")

package(
default_visibility = ["//visibility:public"],
licenses = ["notice"],
)

cc_library(
name = "bert_tests",
testonly = 1,
srcs = [
"bert_tests.cc",
],
hdrs = [
"bert_tests.h",
],
deps = [
"//gutil:status_matchers",
"//thinkit:mirror_testbed_fixture",
"@com_github_gnoi//diag:diag_cc_proto",
"@com_github_google_glog//:glog",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest",
"@com_google_protobuf//:protobuf",
],
alwayslink = True,
)
67 changes: 67 additions & 0 deletions tests/gnoi/bert_tests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "tests/gnoi/bert_tests.h"

#include "absl/strings/substitute.h"
#include "diag/diag.pb.h"
#include "glog/logging.h"
#include "google/protobuf/text_format.h"
#include "gtest/gtest.h"
#include "gutil/status_matchers.h"

namespace bert {

// Test StartBERT with test duration longer than maximum allowed duration.
TEST_P(BertTest, StartBertFailsIfTestDurationTooLong) {
thinkit::Switch& sut = GetMirrorTestbed().Sut();
ASSERT_OK_AND_ASSIGN(auto sut_gnoi_diag_stub, sut.CreateGnoiDiagStub());

// Set BERT test duration to more than 24 hours: (24 hours + 1 sec).
constexpr uint32_t kTesDurationInSecs = (60 * 60 * 24) + 1;

// TODO (ashishksingh) : Before using the "Ethernet0", run sanity test to
// ensure the ports are oper-state "up" on the SUT switch.
const std::string kStartBertRequest =
absl::Substitute(R"PROTO(
bert_operation_id: "OpId-1"
per_port_requests {
interface {
origin: "openconfig"
elem {
name: "interface"
key { key: "name" value: "Ethernet0" }
}
}
prbs_polynomial: PRBS_POLYNOMIAL_PRBS23
test_duration_in_secs: $0
}
)PROTO",
kTesDurationInSecs);

gnoi::diag::StartBERTRequest request;
ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(kStartBertRequest,
&request));

gnoi::diag::StartBERTResponse response;
grpc::ClientContext context;
LOG(INFO) << "Sending StartBERT request: " << request.ShortDebugString();

EXPECT_THAT(gutil::GrpcStatusToAbslStatus(
sut_gnoi_diag_stub->StartBERT(&context, request, &response)),
gutil::StatusIs(absl::StatusCode::kInvalidArgument,
testing::HasSubstr("too long")));
}

} // namespace bert
26 changes: 26 additions & 0 deletions tests/gnoi/bert_tests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef GOOGLE_TESTS_GNOI_BERT_TESTS_H_
#define GOOGLE_TESTS_GNOI_BERT_TESTS_H_

#include "thinkit/mirror_testbed_fixture.h"

namespace bert {

class BertTest : public thinkit::MirrorTestbedFixture {};

} // namespace bert

#endif // GOOGLE_TESTS_GNOI_BERT_TESTS_H_
2 changes: 2 additions & 0 deletions thinkit/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ cc_library(
hdrs = ["switch.h"],
deps = [
"@com_github_gnmi//proto/gnmi:gnmi_cc_grpc_proto",
"@com_github_gnoi//diag:diag_cc_grpc_proto",
"@com_github_gnoi//system:system_cc_grpc_proto",
"@com_github_grpc_grpc//:grpc++",
"@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
Expand All @@ -53,6 +54,7 @@ cc_library(
deps = [
":switch",
"@com_github_gnmi//proto/gnmi:gnmi_cc_grpc_proto",
"@com_github_gnoi//diag:diag_cc_grpc_proto",
"@com_github_gnoi//system:system_cc_grpc_proto",
"@com_github_p4lang_p4runtime//:p4runtime_cc_grpc",
"@com_google_absl//absl/status:statusor",
Expand Down
3 changes: 3 additions & 0 deletions thinkit/mock_switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "diag/diag.grpc.pb.h"
#include "gmock/gmock.h"
#include "p4/v1/p4runtime.grpc.pb.h"
#include "proto/gnmi/gnmi.grpc.pb.h"
Expand All @@ -38,6 +39,8 @@ class MockSwitch : public Switch {
MOCK_METHOD(absl::StatusOr<std::unique_ptr<gnoi::system::System::Stub>>,

CreateGnoiSystemStub, (), (override));
MOCK_METHOD(absl::StatusOr<std::unique_ptr<gnoi::diag::Diag::Stub>>,
CreateGnoiDiagStub, (), (override));
};

} // namespace thinkit
Expand Down
5 changes: 5 additions & 0 deletions thinkit/switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "diag/diag.grpc.pb.h"
#include "p4/v1/p4runtime.grpc.pb.h"
#include "proto/gnmi/gnmi.grpc.pb.h"
#include "system/system.grpc.pb.h"
Expand Down Expand Up @@ -50,6 +51,10 @@ class Switch {
// Creates and returns a stub to the gNOI System service.
virtual absl::StatusOr<std::unique_ptr<gnoi::system::System::Stub>>
CreateGnoiSystemStub() = 0;

// Creates and returns a stub to the gNOI Diag service.
virtual absl::StatusOr<std::unique_ptr<gnoi::diag::Diag::Stub>>
CreateGnoiDiagStub() = 0;
};

} // namespace thinkit
Expand Down

0 comments on commit add04f9

Please sign in to comment.