Update sdv_packager (#6)

This commit is contained in:
tompzf
2026-03-27 14:12:49 +01:00
committed by GitHub
parent 234be8917f
commit aefefd52f7
717 changed files with 42252 additions and 11334 deletions

View File

@@ -1,3 +1,16 @@
#*******************************************************************************
# Copyright (c) 2025-2026 ZF Friedrichshafen AG
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
#
# Contributors:
# Erik Verhoeven - initial API and implementation
#*******************************************************************************
# Define project
project(RepositoryTests VERSION 1.0 LANGUAGES CXX)

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Erik Verhoeven - initial API and implementation
********************************************************************************/
#include <interfaces/core.idl>
/**

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Erik Verhoeven - initial API and implementation
********************************************************************************/
#include <gtest/gtest.h>
#include "../../../global/process_watchdog.h"
#include "mock.h"
@@ -7,12 +20,14 @@
#include "../../../sdv_services/core/toml_parser/parser_node_toml.cpp"
#include "../../../sdv_services/core/toml_parser/character_reader_utf_8.cpp"
#include "../../../sdv_services/core/toml_parser/miscellaneous.cpp"
#include "../../../sdv_services/core/toml_parser/code_snippet.cpp"
#include "../../../sdv_services/core/module_control.cpp"
#include "../../../sdv_services/core/module.cpp"
#include "../../../sdv_services/core/repository.cpp"
#include "../../../sdv_services/core/iso_monitor.cpp"
#include "../../../sdv_services/core/object_lifetime_control.cpp"
#include "../../../sdv_services/core/app_config.cpp"
#include "../../../sdv_services/core/app_config_file.cpp"
#include "../../../sdv_services/core/installation_manifest.cpp"
#if defined(_WIN32) && defined(_UNICODE)

View File

@@ -1,41 +1,109 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Erik Verhoeven - initial API and implementation
********************************************************************************/
#ifndef MOCK_H
#define MOCK_H
#include <interfaces/app.h>
#define DO_NOT_INCLUDE_IN_UNIT_TEST
#include "../../../sdv_services/core/app_control.h"
#include "../../../sdv_services/core/sdv_core.h"
#include <support/component_impl.h>
#include "../../../global/exec_dir_helper.h"
#include "../../../sdv_services/core/installation_manifest.h"
class CMock
// Prevent including app_settings.h and app_control.h
#define APP_SETTINGS_H
#define APP_CONTROL_H
#define LOGGER_H
#define LOGGER_CONTROL_H
/**
* @brief CAppSettings redefined
*/
class CAppSettings : public sdv::IInterfaceAccess
{
public:
//void DestroyModuleObjects(sdv::core::TModuleID) {}
BEGIN_SDV_INTERFACE_MAP()
END_SDV_INTERFACE_MAP()
// CAppSettings mocked functions
sdv::app::EAppContext GetContextType() const { return sdv::app::EAppContext::standalone; }
bool IsStandaloneApplication() { return true; }
bool IsEssentialApplication() { return false; }
bool IsMainApplication() { return false; }
bool IsIsolatedApplication() { return false; }
bool IsMaintenanceApplication() { return false; }
bool IsExternalApplication() { return false; }
bool IsExternalApplication() const { return false; }
bool IsConsoleSilent() { return true; }
bool IsConsoleVerbose() { return false; }
uint32_t GetInstanceID() { return 1000u; }
void RequestShutdown() {}
sdv::app::EAppOperationState GetOperationState() const { return sdv::app::EAppOperationState::running; }
std::filesystem::path GetInstallDir() const { return std::filesystem::path(); }
std::filesystem::path FindInstalledModule(const std::filesystem::path&) const { return {}; }
std::optional<CInstallManifest::SComponent> FindInstalledComponent(const std::string&) const { return {}; }
std::string FindInstalledModuleManifest(const std::filesystem::path&) { return {}; }
std::filesystem::path GetRootDir() const { return GetExecDirectory(); }
std::filesystem::path GetInstallDir() const { return GetExecDirectory(); }
std::vector<std::filesystem::path> GetSystemConfigPaths() const { return {}; }
std::filesystem::path GetUserConfigPath() const { return {}; }
};
inline CMock& GetMock()
/**
* @brief Return the application settings class.
* @return Reference to the application settings.
*/
inline CAppSettings& GetAppSettings()
{
static CMock mock;
return mock;
static CAppSettings app_settings;
return app_settings;
}
#define CAppControl CMock
#define GetAppControl GetMock
#define GetAppConfig GetMock
/**
* @brief CAppControl redefined
*/
class CAppControl : public sdv::IInterfaceAccess
{
public:
BEGIN_SDV_INTERFACE_MAP()
END_SDV_INTERFACE_MAP()
// CAppControl mocked functions
void RequestShutdown() {}
sdv::app::EAppOperationState GetOperationState() const { return sdv::app::EAppOperationState::running; }
};
/**
* @brief Return the application control.
* @return Reference to the application control.
*/
inline CAppControl& GetAppControl()
{
static CAppControl app_control;
return app_control;
}
/**
* @brief CLoggerControl redefined
*/
class CLoggerControl : public sdv::IInterfaceAccess
{
public:
BEGIN_SDV_INTERFACE_MAP()
END_SDV_INTERFACE_MAP()
};
/**
* @brief Return the logger control.
* @return Reference to the logger control.
*/
inline CLoggerControl& GetLoggerControl()
{
static CLoggerControl logger_control;
return logger_control;
}
#include "../../../sdv_services/core/toml_parser/parser_toml.h"
#include "../../../sdv_services/core/toml_parser/parser_node_toml.h"
@@ -43,7 +111,8 @@ inline CMock& GetMock()
#include "../../../sdv_services/core/repository.h"
#include "../../../sdv_services/core/app_config.h"
inline std::filesystem::path GetCoreDirectory() { return "../../bin"; }
//inline std::filesystem::path GetCoreDirectoryMock() { return "../../bin"; }
//#define GetCoreDirectory GetCoreDirectoryMock
class CHelper
{
@@ -69,5 +138,7 @@ public:
inline CModuleControl& GetModuleControl() { return CHelper::GetModuleControl(); }
inline CRepository& GetRepository() { return CHelper::GetRepository(); }
#define GetModuleControl GetModuleControl
#define GetRepository GetRepository
#endif // !defined MOCK_H

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Erik Verhoeven - initial API and implementation
********************************************************************************/
#include <gtest/gtest.h>
#include <fstream>
#include "mock.h"
@@ -16,47 +29,52 @@ public:
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
END_SDV_INTERFACE_MAP()
virtual void Initialize([[maybe_unused]] const sdv::u8string& ssObjectConfig)
virtual void Initialize([[maybe_unused]] const sdv::u8string& ssObjectConfig) override
{
FAIL() << "Error: Initialize should not be called by Repo Service!";
//m_eObjectStatus = sdv::EObjectStatus::initialization_failure;
//m_eObjectState = sdv::EObjectState::initialization_failure;
}
virtual sdv::EObjectStatus GetStatus() const
virtual sdv::EObjectState GetObjectState() const override
{
return m_eObjectStatus;
return m_eObjectState;
}
/**
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
* @param[in] eMode The operation mode, the component should run in.
*/
void SetOperationMode(sdv::EOperationMode eMode)
virtual void SetOperationMode(sdv::EOperationMode eMode) override
{
switch (eMode)
{
case sdv::EOperationMode::configuring:
if (m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized)
m_eObjectStatus = sdv::EObjectStatus::configuring;
if (m_eObjectState == sdv::EObjectState::running || m_eObjectState == sdv::EObjectState::initialized)
m_eObjectState = sdv::EObjectState::configuring;
break;
case sdv::EOperationMode::running:
if (m_eObjectStatus == sdv::EObjectStatus::configuring || m_eObjectStatus == sdv::EObjectStatus::initialized)
m_eObjectStatus = sdv::EObjectStatus::running;
if (m_eObjectState == sdv::EObjectState::configuring || m_eObjectState == sdv::EObjectState::initialized)
m_eObjectState = sdv::EObjectState::running;
break;
default:
break;
}
}
virtual void Shutdown()
virtual sdv::u8string GetObjectConfig() const override
{
m_eObjectStatus = sdv::EObjectStatus::shutdown_in_progress;
return {};
}
virtual void Shutdown() override
{
m_eObjectState = sdv::EObjectState::shutdown_in_progress;
FAIL() << "Error: Shutdown should not be called by Repo Service!";
//m_eObjectStatus = sdv::EObjectStatus::destruction_pending;
//m_eObjectState = sdv::EObjectState::destruction_pending;
}
sdv::EObjectStatus m_eObjectStatus = sdv::EObjectStatus::initialization_pending;
sdv::EObjectState m_eObjectState = sdv::EObjectState::initialization_pending;
};
TEST(RepositoryTest, LoadNonexistentModule)

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Erik Verhoeven - initial API and implementation
********************************************************************************/
#include <gtest/gtest.h>
#include <iostream>
#include <mutex>
@@ -7,8 +20,7 @@
#include "generated/IComponent.h"
#include "../../../global/tracefifo/trace_fifo.cpp"
class CTestLockService
: public sdv::CSdvObject, public ITestLock
class CTestLockService : public sdv::CSdvObject, public ITestLock
{
public:
@@ -16,7 +28,7 @@ public:
SDV_INTERFACE_ENTRY(ITestLock)
END_SDV_INTERFACE_MAP()
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
DECLARE_OBJECT_CLASS_NAME("TestLockService")
void Lock() override
@@ -38,79 +50,26 @@ DEFINE_SDV_OBJECT(CTestLockService)
/**
* @brief Example component testing IObjectControl
*/
class CTestObjectControl
: public sdv::CSdvObject
, public sdv::IObjectControl
class CTestObjectControl : public sdv::CSdvObject
{
public:
~CTestObjectControl()
{
EXPECT_EQ(m_eObjectStatus, sdv::EObjectStatus::destruction_pending);
}
BEGIN_SDV_INTERFACE_MAP()
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
END_SDV_INTERFACE_MAP()
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
DECLARE_OBJECT_CLASS_NAME("Example_Object")
/**
* @brief Initialization method. On success, a subsequent call to GetStatus returns EObjectStatus::running
* @param[in] ssObjectConfig Optional configuration string.
* @brief Initialization event, called after object configuration was loaded. Overload of sdv::CSdvObject::OnInitialize.
* @return Returns 'true' when the initialization was successful, 'false' when not.
*/
virtual void Initialize([[maybe_unused]] const sdv::u8string& ssObjectConfig)
virtual bool OnInitialize() override
{
EXPECT_EQ(m_eObjectStatus, sdv::EObjectStatus::initialization_pending);
m_eObjectStatus = sdv::EObjectStatus::initialized;
return true;
}
/**
* @brief Gets the current status of the object
* @return EObjectStatus The current status of the object
* @brief Shutdown the object. Overload of sdv::CSdvObject::OnShutdown.
*/
virtual sdv::EObjectStatus GetStatus() const
{
return m_eObjectStatus;
}
/**
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
* @param[in] eMode The operation mode, the component should run in.
*/
void SetOperationMode(sdv::EOperationMode eMode)
{
switch (eMode)
{
case sdv::EOperationMode::configuring:
if (m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized)
m_eObjectStatus = sdv::EObjectStatus::configuring;
break;
case sdv::EOperationMode::running:
if (m_eObjectStatus == sdv::EObjectStatus::configuring || m_eObjectStatus == sdv::EObjectStatus::initialized)
m_eObjectStatus = sdv::EObjectStatus::running;
break;
default:
break;
}
}
/**
* @brief Shutdown method called before the object is destroyed.
* @attention Implement calls to other SDV objects here as this is no longer considered safe during the destructor of the object!
* After a call to shutdown any threads/callbacks/etc that could call other SDV objects need to have been stopped.
* The SDV object itself is to remain in a state where it can respond to calls to its interfaces as other objects may still call it during the shutdown sequence!
* Any subsequent call to GetStatus should return EObjectStatus::destruction_pending
*/
virtual void Shutdown()
{
m_eObjectStatus = sdv::EObjectStatus::destruction_pending;
}
private:
sdv::EObjectStatus m_eObjectStatus = sdv::EObjectStatus::initialization_pending;
virtual void OnShutdown() override
{}
};
DEFINE_SDV_OBJECT(CTestObjectControl)
@@ -118,72 +77,27 @@ DEFINE_SDV_OBJECT(CTestObjectControl)
/**
* @brief Example component testing IObjectControl
*/
class CTestObjectControlFail : public sdv::CSdvObject, public sdv::IObjectControl
class CTestObjectControlFail : public sdv::CSdvObject
{
public:
BEGIN_SDV_INTERFACE_MAP()
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
END_SDV_INTERFACE_MAP()
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
DECLARE_OBJECT_CLASS_NAME("TestObject_IObjectControlFail")
/**
* @brief Initialization method. On success, a subsequent call to GetStatus returns EObjectStatus::running
* @param[in] ssObjectConfig Optional configuration string.
* @brief Initialization event, called after object configuration was loaded. Overload of sdv::CSdvObject::OnInitialize.
* @return Returns 'true' when the initialization was successful, 'false' when not.
*/
virtual void Initialize([[maybe_unused]] const sdv::u8string& ssObjectConfig)
virtual bool OnInitialize() override
{
m_eObjectStatus = sdv::EObjectStatus::initialization_failure;
return false;
}
/**
* @brief Gets the current status of the object
* @return EObjectStatus The current status of the object
* @brief Shutdown the object. Overload of sdv::CSdvObject::OnShutdown.
*/
virtual sdv::EObjectStatus GetStatus() const
{
return m_eObjectStatus;
}
/**
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
* @param[in] eMode The operation mode, the component should run in.
*/
void SetOperationMode(sdv::EOperationMode eMode)
{
switch (eMode)
{
case sdv::EOperationMode::configuring:
if (m_eObjectStatus == sdv::EObjectStatus::running || m_eObjectStatus == sdv::EObjectStatus::initialized)
m_eObjectStatus = sdv::EObjectStatus::configuring;
break;
case sdv::EOperationMode::running:
if (m_eObjectStatus == sdv::EObjectStatus::configuring || m_eObjectStatus == sdv::EObjectStatus::initialized)
m_eObjectStatus = sdv::EObjectStatus::running;
break;
default:
break;
}
}
/**
* @brief Shutdown method called before the object is destroyed.
* @attention Implement calls to other SDV objects here as this is no longer considered safe during the destructor of the object!
* After a call to shutdown any threads/callbacks/etc that could call other SDV objects need to have been stopped.
* The SDV object itself is to remain in a state where it can respond to calls to its interfaces as other objects may still call it during the shutdown sequence!
* Any subsequent call to GetStatus should return EObjectStatus::destruction_pending
*/
virtual void Shutdown()
{
m_eObjectStatus = sdv::EObjectStatus::shutdown_in_progress;
m_eObjectStatus = sdv::EObjectStatus::destruction_pending;
}
private:
sdv::EObjectStatus m_eObjectStatus = sdv::EObjectStatus::initialization_pending;
virtual void OnShutdown() override
{}
};
DEFINE_SDV_OBJECT(CTestObjectControlFail)