-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GenericTestbed and ControlInterface interfaces.
- Loading branch information
1 parent
f480c52
commit 95b34f1
Showing
9 changed files
with
283 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright (c) 2024, Google Inc. | ||
// | ||
// 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 | ||
// | ||
// http://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_THINKIT_GENERIC_TESTBED_TEST_FIXTURE_H_ | ||
#define GOOGLE_THINKIT_GENERIC_TESTBED_TEST_FIXTURE_H_ | ||
|
||
#include <memory> | ||
|
||
#include "absl/memory/memory.h" | ||
#include "gtest/gtest.h" | ||
#include "thinkit/generic_testbed.h" | ||
|
||
namespace thinkit { | ||
|
||
// The ThinKit `GenericTestbedInterface` defines an interface every test | ||
// platform should implement. The expectations are such that the GenericTestbed | ||
// should only be accessed after SetUp() is called and before TearDown() is | ||
// called. | ||
class GenericTestbedInterface { | ||
public: | ||
virtual ~GenericTestbedInterface() = default; | ||
|
||
virtual void SetUp() = 0; | ||
virtual void TearDown() = 0; | ||
|
||
virtual GenericTestbed& GetGenericTestbed() = 0; | ||
}; | ||
|
||
// The Thinkit `TestParams` defines test parameters to | ||
// `GenericTestbedFixture` class. | ||
struct TestParams { | ||
// Ownership transferred in GenericTestbedFixture class. | ||
GenericTestbedInterface* generic_testbed; | ||
std::string gnmi_config; | ||
absl::optional<std::vector<int>> port_ids; | ||
}; | ||
|
||
// The ThinKit `GenericTestbedFixture` class acts as a base test fixture for | ||
// platform independent PINS tests. Any platform specific SetUp or TearDown | ||
// requirements are abstracted through the ThinKit GenericTestbedInterface which | ||
// is passed as a parameter. | ||
// | ||
// New PINS tests should extend this fixture, and if needed can extend the | ||
// SetUp() and/or TearDown() methods: | ||
// class MyPinsTest : public thinkit::GenericTestbedFixture { | ||
// void SetUp() override { | ||
// GenericTestbedFixture::SetUp(); // called first. | ||
// | ||
// // custom setup steps ... | ||
// } | ||
// | ||
// void TearDown() override { | ||
// // custom tear down steps ... | ||
// | ||
// GenericTestbedFixture::TearDown(); // called last. | ||
// } | ||
// }; | ||
// | ||
// Individual tests should use the new suite name: | ||
// TEST_P(MyPinsTest, MyTestName) {} | ||
class GenericTestbedFixture : public testing::TestWithParam<TestParams> { | ||
protected: | ||
// A derived class that needs/wants to do its own setup can override this | ||
// method. However, it should take care to call this base setup first. That | ||
// will ensure the platform is ready, and in a healthy state. | ||
void SetUp() override { generic_testbed_interface_->SetUp(); } | ||
|
||
// A derived class that needs/wants to do its own teardown can override this | ||
// method. However, it should take care to call this base teardown last. Once | ||
// this method is called accessing the platform can result in unexpected | ||
// behaviors. | ||
void TearDown() override { generic_testbed_interface_->TearDown(); } | ||
|
||
// Accessor for the Generic testbed. This is only safe to be called after the | ||
// SetUp has completed. | ||
GenericTestbed& GetGenericTestbed() { | ||
return generic_testbed_interface_->GetGenericTestbed(); | ||
} | ||
|
||
std::string GetGnmiConfig() { return GetParam().gnmi_config; } | ||
|
||
private: | ||
// Takes ownership of the GenericTestbedInterface parameter. | ||
std::unique_ptr<GenericTestbedInterface> generic_testbed_interface_ = | ||
absl::WrapUnique<GenericTestbedInterface>(GetParam().generic_testbed); | ||
}; | ||
|
||
} // namespace thinkit | ||
|
||
#endif // GOOGLE_THINKIT_GENERIC_TESTBED_TEST_FIXTURE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2024, Google Inc. | ||
// | ||
// 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 | ||
// | ||
// http://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_THINKIT_MOCK_CONTROL_INTERFACE_H_ | ||
#define GOOGLE_THINKIT_MOCK_CONTROL_INTERFACE_H_ | ||
|
||
#include "absl/container/flat_hash_set.h" | ||
#include "absl/status/statusor.h" | ||
#include "diag/diag.grpc.pb.h" | ||
#include "gmock/gmock.h" | ||
#include "thinkit/control_interface.h" | ||
|
||
namespace thinkit { | ||
class MockControlInterface : public ControlInterface { | ||
public: | ||
MOCK_METHOD(absl::Status, SetAdminLinkState, | ||
(absl::Span<const std::string> sut_ports, LinkState state), | ||
(override)); | ||
MOCK_METHOD(absl::Status, Reboot, (RebootType reboot_Type), (override)); | ||
MOCK_METHOD(absl::StatusOr<gnoi::diag::StartBERTResponse>, StartBERT, | ||
(const gnoi::diag::StartBERTRequest& request), (override)); | ||
MOCK_METHOD(absl::StatusOr<gnoi::diag::StopBERTResponse>, StopBERT, | ||
(const gnoi::diag::StopBERTRequest& request), (override)); | ||
MOCK_METHOD(absl::StatusOr<gnoi::diag::GetBERTResultResponse>, GetBERTResult, | ||
(const gnoi::diag::GetBERTResultRequest& request)); | ||
MOCK_METHOD(absl::StatusOr<absl::flat_hash_set<std::string>>, GetUpLinks, | ||
(absl::Span<const std::string> sut_ports), (override)); | ||
MOCK_METHOD(absl::Status, CheckUp, (), (override)); | ||
}; | ||
|
||
} // namespace thinkit | ||
|
||
#endif // GOOGLE_THINKIT_MOCK_CONTROL_INTERFACE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) 2024, Google Inc. | ||
// | ||
// 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 | ||
// | ||
// http://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 "thinkit/mock_control_interface.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
namespace thinkit { | ||
namespace { | ||
|
||
TEST(MockControlInterface, TestBuild) { MockControlInterface mock; } | ||
|
||
} // namespace | ||
} // namespace thinkit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// 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 | ||
// | ||
// http://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. | ||
|
||
syntax = "proto3"; | ||
|
||
package third_party.pins_infra.thinkit; | ||
|
||
option cc_generic_services = false; | ||
|
||
// Mode types for the SUT interfaces are connected.. | ||
enum InterfaceMode { | ||
UNKNOWN_MODE = 0; | ||
DISCONNECTED = 1; | ||
LOOPBACK = 2; | ||
CONTROL_INTERFACE = 3; | ||
TRAFFIC_GENERATOR = 4; | ||
} | ||
|
||
// This message represents the mode of interface(s) and the number of | ||
// which are required. | ||
message InterfaceRequirement { | ||
InterfaceMode interface_mode = 1; | ||
int32 count = 2; | ||
} | ||
|
||
// This message represents interface(s) requirement for a test. | ||
message TestRequirements { | ||
repeated InterfaceRequirement interface_requirements = 1; | ||
} |