Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/build_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
- develop
- feature*

pull_request_target:
types:
Expand All @@ -23,7 +24,7 @@ jobs:
runs-on: ubuntu-22.04
permissions: read-all
container:
image: ghcr.io/aosedge/aos-core-build-base:latest
image: ghcr.io/aosedge/aos-core-build:latest
options: "--entrypoint /usr/bin/bash"
credentials:
username: ${{ github.actor }}
Expand All @@ -33,10 +34,6 @@ jobs:
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory

steps:
# Apply solution to "HOME is overridden for containers" problem: https://github.com/actions/runner/issues/863
- name: Preserve $HOME set in the container
run: echo HOME=/root >> "$GITHUB_ENV"

- name: Checkout
uses: actions/checkout@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ set(TARGET aos_servicemanager)
# Defines
# ######################################################################################################################

add_definitions(-include config.hpp)

# ######################################################################################################################
# Includes
# ######################################################################################################################
Expand Down
2 changes: 1 addition & 1 deletion src/app/aoscore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void AosCore::Init(const std::string& configFile)

err = mLauncher.Init(mConfig.mLauncherConfig, mIAMClientPublic, mServiceManager, mLayerManager, mResourceManager,
mNetworkManager, mIAMClientPermissions, mRunner, mRuntime, mResourceMonitor, mOCISpec, mSMClient, mSMClient,
mDatabase);
mDatabase, mCryptoProvider);
AOS_ERROR_CHECK_AND_THROW(err, "can't initialize launcher");

// Initialize SM client
Expand Down
15 changes: 15 additions & 0 deletions src/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (C) 2026 EPAM Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef AOS_CORE_SM_CONFIG_HPP_
#define AOS_CORE_SM_CONFIG_HPP_

/**
* Host device name len.
*/
#define AOS_CONFIG_TYPES_DEVICE_NAME_LEN 128

#endif
9 changes: 7 additions & 2 deletions src/launcher/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ oci::LinuxDevice DeviceFromPath(const fs::path& path)
auto devPath = path;

if (fs::is_symlink(path)) {
devPath = fs::read_symlink(path);
auto target = fs::read_symlink(path);
if (target.is_relative()) {
devPath = (path.parent_path() / target).lexically_normal();
} else {
devPath = target;
}
}

struct stat sb;
Expand Down Expand Up @@ -185,7 +190,7 @@ oci::LinuxDevice DeviceFromPath(const fs::path& path)
}

return oci::LinuxDevice {
devPath.c_str(), type, major(sb.st_rdev), minor(sb.st_rdev), sb.st_mode & ~S_IFMT, sb.st_uid, sb.st_gid};
path.c_str(), type, major(sb.st_rdev), minor(sb.st_rdev), sb.st_mode & ~S_IFMT, sb.st_uid, sb.st_gid};
}

} // namespace
Expand Down
16 changes: 14 additions & 2 deletions src/resourcemanager/resourcemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,21 @@ Error HostDeviceManager::Init()

Error HostDeviceManager::CheckDevice(const String& device) const
{
auto it = mDevices.find(device.CStr());
StaticArray<StaticString<cFilePathLen>, 2> devices;

return it != mDevices.end() ? ErrorEnum::eNone : ErrorEnum::eNotFound;
if (auto err = device.Split(devices, ':'); !err.IsNone()) {
return AOS_ERROR_WRAP(err);
}

if (devices.IsEmpty()) {
return AOS_ERROR_WRAP(ErrorEnum::eFailed);
}

if (mDevices.find(devices[0].CStr()) == mDevices.end()) {
return AOS_ERROR_WRAP(ErrorEnum::eNotFound);
}

return ErrorEnum::eNone;
}

Error HostDeviceManager::CheckGroup(const String& group) const
Expand Down
2 changes: 1 addition & 1 deletion tests/launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ gtest_discover_tests(${TARGET})
# Libraries
# ######################################################################################################################

target_link_libraries(${TARGET} launcher GTest::gmock_main)
target_link_libraries(${TARGET} launcher aostestutils GTest::gmock_main)
53 changes: 53 additions & 0 deletions tests/launcher/runtime_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <gtest/gtest.h>

#include <aos/test/log.hpp>
#include <aos/test/utils.hpp>

#include "launcher/runtime.hpp"

Expand Down Expand Up @@ -78,4 +79,56 @@ TEST_F(LauncherTest, CreateHostFSWhiteouts)
}
}

TEST_F(LauncherTest, PopulateHostDevices)
{
const auto cRootDevicePath = fs::path(cTestDirRoot) / "dev";
const auto cTestDeviceFullPath = cRootDevicePath / "device1";

if (!fs::exists(cRootDevicePath)) {
fs::create_directories(cRootDevicePath);
}

if (auto res = mknod(cTestDeviceFullPath.c_str(), S_IFCHR, 0); res != 0) {
FAIL() << "Can't create test device node: " << strerror(errno);
}

StaticArray<oci::LinuxDevice, 1> devices;

auto err = mRuntime.PopulateHostDevices(cTestDeviceFullPath.c_str(), devices);
EXPECT_TRUE(err.IsNone()) << "failed: " << test::ErrorToStr(err);

EXPECT_EQ(devices.Size(), 1);
EXPECT_STREQ(devices.Front().mPath.CStr(), cTestDeviceFullPath.c_str());
}

TEST_F(LauncherTest, PopulateHostDevicesSymlink)
{
const auto cRootDevicePath = fs::path(cTestDirRoot) / "dev";
const auto cTestDeviceFullPath = cRootDevicePath / "device1";

if (!fs::exists(cRootDevicePath)) {
fs::create_directories(cRootDevicePath);
}

if (auto res = mknod(cTestDeviceFullPath.c_str(), S_IFCHR, 0); res != 0) {
FAIL() << "Can't create test device node: " << strerror(errno);
}

const auto currentPath = fs::current_path();

fs::current_path(cRootDevicePath);

fs::create_symlink("device1", "link");

fs::current_path(currentPath);

StaticArray<oci::LinuxDevice, 1> devices;

auto err = mRuntime.PopulateHostDevices((cRootDevicePath / "link").c_str(), devices);
EXPECT_TRUE(err.IsNone()) << "failed: " << test::ErrorToStr(err);

EXPECT_EQ(devices.Size(), 1);
EXPECT_STREQ(devices.Front().mPath.CStr(), (cRootDevicePath / "link").c_str());
}

} // namespace aos::sm::launcher
2 changes: 1 addition & 1 deletion tests/resourcemanager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ gtest_discover_tests(${TARGET})
# Libraries
# ######################################################################################################################

target_link_libraries(${TARGET} resourcemanager GTest::gmock_main)
target_link_libraries(${TARGET} resourcemanager aostestutils GTest::gmock_main)
7 changes: 6 additions & 1 deletion tests/resourcemanager/resourcemanager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <gtest/gtest.h>

#include <aos/test/log.hpp>
#include <aos/test/utils.hpp>

#include "resourcemanager/resourcemanager.hpp"

Expand All @@ -29,7 +30,11 @@ TEST_F(ResourcemanagerTest, CheckDevice)
{
ASSERT_TRUE(mHostDeviceManager.Init().IsNone());

EXPECT_TRUE(mHostDeviceManager.CheckDevice("/dev/null").IsNone());
auto err = mHostDeviceManager.CheckDevice("/dev/null");
EXPECT_TRUE(err.IsNone()) << test::ErrorToStr(err);

err = mHostDeviceManager.CheckDevice("/dev/null:/dev/test");
EXPECT_TRUE(err.IsNone()) << test::ErrorToStr(err);
}

TEST_F(ResourcemanagerTest, CheckDeviceReturnsNotFound)
Expand Down
Loading