Skip to content

Commit

Permalink
Control CTs (#258)
Browse files Browse the repository at this point in the history
Summary: Rialto Server Control CTs
Type: Feature
Test Plan: Component Tests
Jira: RIALTO-466
  • Loading branch information
skywojciechowskim authored Feb 2, 2024
1 parent 4b1c497 commit a9d4f86
Show file tree
Hide file tree
Showing 13 changed files with 488 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/cppcheck_report.txt
/cmake/ocdm-config.cmake
*__pycache__
/.vscode/*

# These files are fetched by cmake during building rialto for the native platform
/stubs/opencdm/third-party/*
Expand Down
16 changes: 16 additions & 0 deletions tests/componenttests/server/common/ActionTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,22 @@ struct GetSharedMemory
using Stub = ::firebolt::rialto::ControlModule_Stub;
static constexpr auto m_kFunction{&Stub::getSharedMemory};
};

struct RegisterClient
{
using RequestType = ::firebolt::rialto::RegisterClientRequest;
using ResponseType = ::firebolt::rialto::RegisterClientResponse;
using Stub = ::firebolt::rialto::ControlModule_Stub;
static constexpr auto m_kFunction{&Stub::registerClient};
};

struct Ack
{
using RequestType = ::firebolt::rialto::AckRequest;
using ResponseType = ::firebolt::rialto::AckResponse;
using Stub = ::firebolt::rialto::ControlModule_Stub;
static constexpr auto m_kFunction{&Stub::ack};
};
} // namespace firebolt::rialto::server::ct

#endif // FIREBOLT_RIALTO_SERVER_CT_ACTION_TRAITS_H_
17 changes: 17 additions & 0 deletions tests/componenttests/server/common/MessageBuilders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,21 @@ ::firebolt::rialto::GetSharedMemoryRequest createGetSharedMemoryRequest()
{
return ::firebolt::rialto::GetSharedMemoryRequest();
}

::firebolt::rialto::RegisterClientRequest createRegisterClientRequest()
{
::firebolt::rialto::RegisterClientRequest request;
request.mutable_client_schema_version()->set_major(std::stoul(PROJECT_VER_MAJOR));
request.mutable_client_schema_version()->set_minor(std::stoul(PROJECT_VER_MINOR));
request.mutable_client_schema_version()->set_patch(std::stoul(PROJECT_VER_PATCH));
return request;
}

::firebolt::rialto::AckRequest createAckRequest(int controlHandle, int id)
{
::firebolt::rialto::AckRequest request;
request.set_control_handle(controlHandle);
request.set_id(id);
return request;
}
} // namespace firebolt::rialto::server::ct
2 changes: 2 additions & 0 deletions tests/componenttests/server/common/MessageBuilders.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ createGetSupportedKeySystemVersionRequest(const std::string &keySystem);

// control module
::firebolt::rialto::GetSharedMemoryRequest createGetSharedMemoryRequest();
::firebolt::rialto::RegisterClientRequest createRegisterClientRequest();
::firebolt::rialto::AckRequest createAckRequest(int controlHandle, int id);
} // namespace firebolt::rialto::server::ct

#endif // FIREBOLT_RIALTO_SERVER_CT_MESSAGE_BUILDERS_H_
1 change: 1 addition & 0 deletions tests/componenttests/server/fixtures/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ add_library (
STATIC
RialtoServerComponentTest.cpp
MediaPipelineTest.cpp
ControlTest.cpp
)

set_property (
Expand Down
51 changes: 51 additions & 0 deletions tests/componenttests/server/fixtures/ControlTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2024 Sky UK
*
* 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 "ControlTest.h"
#include "ActionTraits.h"
#include "ConfigureAction.h"
#include "ExpectMessage.h"
#include "MessageBuilders.h"

namespace firebolt::rialto::server::ct
{
ControlTest::ControlTest()
{
willConfigureSocket();
configureSutInActiveState();
connectClient();
registerClient();
}

void ControlTest::registerClient()
{
ExpectMessage<ApplicationStateChangeEvent> expectedAppStateChange{m_clientStub};

auto registerClientReq(createRegisterClientRequest());
ConfigureAction<RegisterClient>(m_clientStub)
.send(registerClientReq)
.expectSuccess()
.matchResponse([&](const auto &resp) { m_controlHandle = resp.control_handle(); });

auto receivedMessage = expectedAppStateChange.getMessage();
ASSERT_TRUE(receivedMessage);
EXPECT_EQ(receivedMessage->application_state(), ApplicationStateChangeEvent_ApplicationState_RUNNING);
}
} // namespace firebolt::rialto::server::ct
42 changes: 42 additions & 0 deletions tests/componenttests/server/fixtures/ControlTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2024 Sky UK
*
* 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 FIREBOLT_RIALTO_SERVER_CT_CONTROL_TEST_H_
#define FIREBOLT_RIALTO_SERVER_CT_CONTROL_TEST_H_

#include "RialtoServerComponentTest.h"

namespace firebolt::rialto::server::ct
{
class ControlTest : public RialtoServerComponentTest
{
public:
ControlTest();
~ControlTest() override = default;

private:
void registerClient();

protected:
int m_controlHandle{-1};
};
} // namespace firebolt::rialto::server::ct

#endif // FIREBOLT_RIALTO_SERVER_CT_CONTROL_TEST_H_
26 changes: 26 additions & 0 deletions tests/componenttests/server/fixtures/RialtoServerComponentTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,32 @@ void RialtoServerComponentTest::connectClient()
EXPECT_TRUE(m_clientStub.connect());
}

void RialtoServerComponentTest::setStateActive()
{
::rialto::SetStateRequest request{createSetStateRequest(::rialto::SessionServerState::ACTIVE)};

ExpectMessage<::rialto::StateChangedEvent> expectedMessage(m_serverManagerStub);

ConfigureAction<::firebolt::rialto::server::ct::SetState>(m_serverManagerStub).send(request).expectSuccess();

auto receivedMessage = expectedMessage.getMessage();
ASSERT_TRUE(receivedMessage);
EXPECT_EQ(receivedMessage->sessionserverstate(), ::rialto::SessionServerState::ACTIVE);
}

void RialtoServerComponentTest::setStateInactive()
{
::rialto::SetStateRequest request{createSetStateRequest(::rialto::SessionServerState::INACTIVE)};

ExpectMessage<::rialto::StateChangedEvent> expectedMessage(m_serverManagerStub);

ConfigureAction<::firebolt::rialto::server::ct::SetState>(m_serverManagerStub).send(request).expectSuccess();

auto receivedMessage = expectedMessage.getMessage();
ASSERT_TRUE(receivedMessage);
EXPECT_EQ(receivedMessage->sessionserverstate(), ::rialto::SessionServerState::INACTIVE);
}

void RialtoServerComponentTest::configureWrappers() const
{
EXPECT_CALL(*m_glibWrapperFactoryMock, getGlibWrapper()).WillRepeatedly(Return(m_glibWrapperMock));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class RialtoServerComponentTest : public ::testing::Test
void willConfigureSocket();
void configureSutInActiveState();
void connectClient();
void setStateActive();
void setStateInactive();

private:
void configureWrappers() const;
Expand Down
2 changes: 2 additions & 0 deletions tests/componenttests/server/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ add_gtests (
mediaKeys/SetDrmHeaderTest.cpp
mediaKeys/LicenseRenewalTest.cpp
mediaKeysCapabilities/MediaKeysCapabilitiesTest.cpp
control/ApplicationStateChangeTest.cpp
control/HealthcheckTest.cpp
)

target_include_directories(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2024 Sky UK
*
* 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 "ActionTraits.h"
#include "ConfigureAction.h"
#include "ControlTest.h"
#include "ExpectMessage.h"
#include "MessageBuilders.h"

namespace firebolt::rialto::server::ct
{
class ApplicationStateChangeTest : public ControlTest
{
public:
ApplicationStateChangeTest() = default;
~ApplicationStateChangeTest() override = default;

void changeStateToInactive()
{
ExpectMessage<ApplicationStateChangeEvent> m_expectedInactiveNotification{m_clientStub};

setStateInactive();

auto inactiveNotification{m_expectedInactiveNotification.getMessage()};
ASSERT_TRUE(inactiveNotification);
EXPECT_EQ(inactiveNotification->application_state(), ApplicationStateChangeEvent_ApplicationState_INACTIVE);
}

void changeStateToRunning()
{
ExpectMessage<ApplicationStateChangeEvent> m_expectedRunningNotification{m_clientStub};

setStateActive();

auto runningNotification{m_expectedRunningNotification.getMessage()};
ASSERT_TRUE(runningNotification);
EXPECT_EQ(runningNotification->application_state(), ApplicationStateChangeEvent_ApplicationState_RUNNING);
}

void getSharedMemoryWillFail()
{
auto getShmReq{createGetSharedMemoryRequest()};
ConfigureAction<GetSharedMemory>(m_clientStub).send(getShmReq).expectFailure();
}

void getSharedMemoryWillSucceed()
{
auto getShmReq{createGetSharedMemoryRequest()};
ConfigureAction<GetSharedMemory>(m_clientStub).send(getShmReq).expectSuccess();
}
};
/*
* Component Test: Application state change from RUNNING->INACTIVE->RUNNING
* Test Objective:
* Test the full lifecycle of an application and verify that the client is always notified.
*
* Sequence Diagrams:
* Start Application in Running State, Application state change: Running to Inactive,
* Switch Application from Inactive to Running State, Stop Application from Running State
* - https://wiki.rdkcentral.com/display/ASP/Rialto+Application+Session+Management
*
* Test Setup:
* Language: C++
* Testing Framework: Google Test
* Components: Control
*
* Test Initialize:
* Set Rialto Server to Active
* Connect Rialto Client Stub
* Register Rialto Client Stub in RUNNING state
*
* Test Steps:
* Step 1: Change state to INACTIVE
* ServerManager requests the server to change the state to INACTIVE.
* Expect that the state change notification is propagated to the client.
* Expect that the shared memory region cannot be fetched from the server.
*
* Step 2: Change state to RUNNING
* ServerManager requests the server to change the state to ACTIVE.
* Expect that the state change notification to RUNNING is propagated to the client.
* Expect that the shared memory region is fetched from the server.
*
* Test Teardown:
* Server is terminated.
*
* Expected Results:
* The lifecycle of an application is successfully negotiated and notfied to
* listening clients.
*
* Code:
*/
TEST_F(ApplicationStateChangeTest, lifecycle)
{
// Step 1: Change state to INACTIVE
changeStateToInactive();
getSharedMemoryWillFail();

// Step 2: Change state to RUNNING
changeStateToRunning();
getSharedMemoryWillSucceed();
}
} // namespace firebolt::rialto::server::ct
Loading

0 comments on commit a9d4f86

Please sign in to comment.