Skip to content

Commit

Permalink
Add L1 test cases for DobbyManager hibernate/wakeupContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianM27 committed Feb 5, 2025
1 parent f509cd3 commit 5ffd6b6
Show file tree
Hide file tree
Showing 5 changed files with 470 additions and 2 deletions.
74 changes: 74 additions & 0 deletions tests/L1_testing/mocks/DobbyHibernate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2025 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.
*/
/*
* File: DobbyHibernate.h
*
*/
#pragma once

#include <sys/types.h>
#include <stdint.h>
#include <string>

class DobbyHibernateImpl;

class DobbyHibernate
{
public:

enum Error
{
ErrorNone = 0,
ErrorGeneral = 1,
ErrorTimeout = 2
};

enum CompressionAlg
{
AlgNone = 0,
AlgLz4 = 1,
AlgZstd = 2,
AlgDefault = 3
};

static const std::string DFL_LOCATOR;
static const uint32_t DFL_TIMEOUTE_MS;

static void setImpl(DobbyHibernateImpl* newImpl);

static Error HibernateProcess(const pid_t pid, const uint32_t timeout = DFL_TIMEOUTE_MS,
const std::string &locator = DFL_LOCATOR, const std::string &dumpDirPath = std::string(), CompressionAlg compression = AlgDefault);
static Error WakeupProcess(const pid_t pid, const uint32_t timeout = DFL_TIMEOUTE_MS, const std::string &locator = DFL_LOCATOR);

protected:
static DobbyHibernateImpl* impl;
};


class DobbyHibernateImpl
{
public:

virtual ~DobbyHibernateImpl() = default;

virtual DobbyHibernate::Error HibernateProcess(const pid_t pid, const uint32_t timeout,
const std::string &locator, const std::string &dumpDirPath, DobbyHibernate::CompressionAlg compression) = 0;

virtual DobbyHibernate::Error WakeupProcess(const pid_t pid, const uint32_t timeout, const std::string &locator) = 0;
};
45 changes: 45 additions & 0 deletions tests/L1_testing/mocks/DobbyHibernateMock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2025 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 "DobbyHibernateMock.h"

DobbyHibernate::Error DobbyHibernate::HibernateProcess(const pid_t pid, const uint32_t timeout, const std::string &locator, const std::string &dumpDirPath, CompressionAlg compression)
{
EXPECT_NE(impl, nullptr);

return impl->HibernateProcess(pid, timeout, locator, dumpDirPath, compression);

}

DobbyHibernate::Error DobbyHibernate::WakeupProcess(const pid_t pid, const uint32_t timeout, const std::string &locator)
{
EXPECT_NE(impl, nullptr);

return impl->WakeupProcess(pid, timeout, locator);
}

void DobbyHibernate::setImpl(DobbyHibernateImpl* newImpl)
{
// Handles both resetting 'impl' to nullptr and assigning a new value to 'impl'
EXPECT_TRUE ((nullptr == impl) || (nullptr == newImpl));
impl = newImpl;
}

const std::string DobbyHibernate::DFL_LOCATOR = "";
const uint32_t DobbyHibernate::DFL_TIMEOUTE_MS = 0;
32 changes: 32 additions & 0 deletions tests/L1_testing/mocks/DobbyHibernateMock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2025 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 <gmock/gmock.h>
#include "DobbyHibernate.h"

class DobbyHibernateMock : public DobbyHibernateImpl {
public:

virtual ~DobbyHibernateMock() = default;

MOCK_METHOD(DobbyHibernate::Error, HibernateProcess, (const pid_t pid, const uint32_t timeout,
const std::string &locator, const std::string &dumpDirPath, DobbyHibernate::CompressionAlg compression), (override));

MOCK_METHOD(DobbyHibernate::Error, WakeupProcess, (const pid_t pid, const uint32_t timeout, const std::string &locator), (override));
};
2 changes: 1 addition & 1 deletion tests/L1_testing/tests/DobbyManagerTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ include_directories(${GTEST_INCLUDE_DIRS})

add_library(DaemonDobbyManagerTest SHARED STATIC
../../../../daemon/lib/source/DobbyManager.cpp
../../../../daemon/lib/source/DobbyHibernate.cpp
../../../../AppInfrastructure/Logging/source/Logging.cpp
../../mocks/DobbyBundleConfigMock.cpp
../../mocks/DobbyRunCMock.cpp
Expand All @@ -51,6 +50,7 @@ add_library(DaemonDobbyManagerTest SHARED STATIC
../../mocks/IpcFileDescriptorMock.cpp
../../mocks/DobbyStartStateMock.cpp
../../mocks/DobbyUtilsMock.cpp
../../mocks/DobbyHibernateMock.cpp
)

target_include_directories(DaemonDobbyManagerTest
Expand Down
Loading

0 comments on commit 5ffd6b6

Please sign in to comment.