Skip to content

Commit

Permalink
[Thinkit] Instantiate configure_mirror_testbed_test in PINS. (#988)
Browse files Browse the repository at this point in the history
* Adding gnmi port breakout tests

* Instantiate configure_mirror_testbed_test in PINS

---------

Co-authored-by: Srikishen Pondicherry Shanmugam <[email protected]>
  • Loading branch information
bibhuprasad-hcl and kishanps authored Feb 11, 2025
1 parent db76ab0 commit 42c433d
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/forwarding/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ cc_library(
alwayslink = True,
)

cc_library(
name = "configure_mirror_testbed_test",
testonly = True,
srcs = ["configure_mirror_testbed_test.cc"],
hdrs = ["configure_mirror_testbed_test.h"],
deps = [
"//gutil:status_matchers",
"//tests/lib:switch_test_setup_helpers",
"//thinkit:mirror_testbed_fixture",
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
"@com_google_googletest//:gtest",
],
alwayslink = True,
)

cc_library(
name = "smoke_test",
testonly = True,
Expand Down
42 changes: 42 additions & 0 deletions tests/forwarding/configure_mirror_testbed_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2025 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/forwarding/configure_mirror_testbed_test.h"

#include "absl/log/log.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "gutil/status_matchers.h"
#include "tests/lib/switch_test_setup_helpers.h"

namespace pins {
namespace {

TEST_P(ConfigureMirrorTestbedTestFixture, ConfigureMirrorTestbedTest) {
LOG(INFO) << "Pushing P4Info/gNMI to the control switch";
ASSERT_OK(pins_test::ConfigureSwitchAndReturnP4RuntimeSession(
GetParam().mirror_testbed->GetMirrorTestbed().ControlSwitch(),
GetParam().control_switch_gnmi_config,
GetParam().control_switch_p4info)
.status());

LOG(INFO) << "Pushing P4Info/gNMI to the SUT";
ASSERT_OK(pins_test::ConfigureSwitchAndReturnP4RuntimeSession(
GetParam().mirror_testbed->GetMirrorTestbed().Sut(),
GetParam().sut_gnmi_config, GetParam().sut_p4info)
.status());
}

} // namespace
} // namespace pins
46 changes: 46 additions & 0 deletions tests/forwarding/configure_mirror_testbed_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2025 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 PINS_TESTS_FORWARDING_CONFIGURE_MIRROR_TESTBED_TEST_H_
#define PINS_TESTS_FORWARDING_CONFIGURE_MIRROR_TESTBED_TEST_H_

#include <string>

#include "p4/config/v1/p4info.pb.h"
#include "thinkit/mirror_testbed_fixture.h"

namespace pins {

struct ConfigureMirrorTestbedTestParams {
std::shared_ptr<thinkit::MirrorTestbedInterface> mirror_testbed;
// The test assumes that the switches are pre-configured if no gNMI or P4Info
// is given (default), or otherwise pushes the given configs.
std::optional<std::string> sut_gnmi_config;
std::optional<std::string> control_switch_gnmi_config;
std::optional<p4::config::v1::P4Info> sut_p4info;
std::optional<p4::config::v1::P4Info> control_switch_p4info;
};

// Optionally pushes P4Info or gNMI to SUT and/or control switch.
// TODO: Remove when installation_test also pushes P4Info.
class ConfigureMirrorTestbedTestFixture
: public testing::TestWithParam<ConfigureMirrorTestbedTestParams> {
protected:
void SetUp() override { GetParam().mirror_testbed->SetUp(); }
void TearDown() override { GetParam().mirror_testbed->TearDown(); }
};

} // namespace pins

#endif // PINS_TESTS_FORWARDING_CONFIGURE_MIRROR_TESTBED_TEST_H_

0 comments on commit 42c433d

Please sign in to comment.