From 2a73cb0f26f9c23879dfb255b6b03123dabf31ea Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 17 Feb 2026 11:09:14 +0100 Subject: [PATCH 01/19] Began refactor for better code coverage --- .../include/client-manager/client_manager.hpp | 9 ++++++-- capio/server/src/client_manager.cpp | 22 +++++++++---------- capio/tests/unit/server/CMakeLists.txt | 2 +- .../src/{capio_file.cpp => capio_file.hpp} | 9 ++++---- .../tests/unit/server/src/client_manager.hpp | 4 ++++ capio/tests/unit/server/src/main.cpp | 5 +++++ 6 files changed, 32 insertions(+), 19 deletions(-) rename capio/tests/unit/server/src/{capio_file.cpp => capio_file.hpp} (95%) create mode 100644 capio/tests/unit/server/src/client_manager.hpp create mode 100644 capio/tests/unit/server/src/main.cpp diff --git a/capio/server/include/client-manager/client_manager.hpp b/capio/server/include/client-manager/client_manager.hpp index 8c963b55b..824fed74b 100644 --- a/capio/server/include/client-manager/client_manager.hpp +++ b/capio/server/include/client-manager/client_manager.hpp @@ -21,8 +21,13 @@ class ClientManager { * Data buffers variables */ struct ClientDataBuffers { - SPSCQueue *ClientToServer; - SPSCQueue *ServerToClient; + SPSCQueue ClientToServer; + SPSCQueue ServerToClient; + + /// @brief Constructor for struct so that try_emplace can be called with no explicit call to + /// new() + ClientDataBuffers(const std::string &clientToServerName, + const std::string &serverToClientName, const std::string &workflow_name); }; std::unordered_map data_buffers; diff --git a/capio/server/src/client_manager.cpp b/capio/server/src/client_manager.cpp index df69215a9..f4cedc976 100644 --- a/capio/server/src/client_manager.cpp +++ b/capio/server/src/client_manager.cpp @@ -8,6 +8,12 @@ #include "utils/capiocl_adapter.hpp" #include "utils/common.hpp" +ClientManager::ClientDataBuffers::ClientDataBuffers(const std::string &clientToServerName, + const std::string &serverToClientName, + const std::string &wf_name) + : ClientToServer(clientToServerName, get_cache_lines(), get_cache_line_size(), wf_name), + ServerToClient(serverToClientName, get_cache_lines(), get_cache_line_size(), wf_name) {} + ClientManager::ClientManager() : requests{SHM_COMM_CHAN_NAME, CAPIO_REQ_BUFF_CNT, CAPIO_REQ_MAX_SIZE, CapioCLEngine::get().getWorkflowName()} { @@ -21,13 +27,9 @@ ClientManager::~ClientManager() { void ClientManager::registerClient(pid_t tid, const std::string &app_name, const bool wait) { START_LOG(gettid(), "call(tid=%ld, app_name=%s)", tid, app_name.c_str()); - ClientDataBuffers buffers{ - new SPSCQueue(SHM_SPSC_PREFIX_WRITE + std::to_string(tid), get_cache_lines(), - get_cache_line_size(), CapioCLEngine::get().getWorkflowName()), - new SPSCQueue(SHM_SPSC_PREFIX_READ + std::to_string(tid), get_cache_lines(), - get_cache_line_size(), CapioCLEngine::get().getWorkflowName())}; - - data_buffers.emplace(tid, buffers); + data_buffers.try_emplace(tid, SHM_SPSC_PREFIX_WRITE + std::to_string(tid), + SHM_SPSC_PREFIX_READ + std::to_string(tid), + CapioCLEngine::get().getWorkflowName()); app_names.emplace(tid, app_name); files_created_by_producer.emplace(tid, std::initializer_list{}); files_created_by_app_name.emplace(app_name, std::initializer_list{}); @@ -63,8 +65,6 @@ void ClientManager::unlockClonedChild(const pid_t tid) { void ClientManager::removeClient(const pid_t tid) { START_LOG(gettid(), "call(tid=%ld)", tid); if (const auto it_resp = data_buffers.find(tid); it_resp != data_buffers.end()) { - delete it_resp->second.ClientToServer; - delete it_resp->second.ServerToClient; data_buffers.erase(it_resp); } const std::string &app_name = this->getAppName(tid); @@ -87,7 +87,7 @@ void ClientManager::replyToClient(const int tid, const off64_t offset, char *buf if (const auto out = data_buffers.find(tid); out != data_buffers.end()) { this->replyToClient(tid, offset + count); - out->second.ServerToClient->write(buf + offset, count); + out->second.ServerToClient.write(buf + offset, count); return; } LOG("Err: no such buffer for provided tid"); @@ -161,7 +161,7 @@ const std::string &ClientManager::getAppName(const pid_t tid) const { } SPSCQueue &ClientManager::getClientToServerDataBuffers(const pid_t tid) { - return *data_buffers.at(tid).ClientToServer; + return data_buffers.at(tid).ClientToServer; } size_t ClientManager::getConnectedPosixClients() const { return data_buffers.size(); } diff --git a/capio/tests/unit/server/CMakeLists.txt b/capio/tests/unit/server/CMakeLists.txt index d872b453c..b0ebfd8ba 100644 --- a/capio/tests/unit/server/CMakeLists.txt +++ b/capio/tests/unit/server/CMakeLists.txt @@ -4,7 +4,7 @@ set(TARGET_NAME capio_server_unit_tests) set(TARGET_INCLUDE_FOLDER "${PROJECT_SOURCE_DIR}/capio/server") set(TARGET_SOURCES - src/capio_file.cpp + src/main.cpp ) ##################################### diff --git a/capio/tests/unit/server/src/capio_file.cpp b/capio/tests/unit/server/src/capio_file.hpp similarity index 95% rename from capio/tests/unit/server/src/capio_file.cpp rename to capio/tests/unit/server/src/capio_file.hpp index 88ab96d90..fab618e65 100644 --- a/capio/tests/unit/server/src/capio_file.cpp +++ b/capio/tests/unit/server/src/capio_file.hpp @@ -1,7 +1,5 @@ -#include - -#include - +#ifndef CAPIO_CAPIO_FILE_HPP +#define CAPIO_CAPIO_FILE_HPP #include "common/env.hpp" #include "utils/capio_file.hpp" @@ -59,4 +57,5 @@ TEST(ServerTest, TestInsertTwoOverlappingSectorsNested) { auto §ors = c_file.get_sectors(); EXPECT_EQ(sectors.size(), 1); EXPECT_NE(sectors.find({1L, 4L}), sectors.end()); -} \ No newline at end of file +} +#endif // CAPIO_CAPIO_FILE_HPP diff --git a/capio/tests/unit/server/src/client_manager.hpp b/capio/tests/unit/server/src/client_manager.hpp new file mode 100644 index 000000000..ff59b6da2 --- /dev/null +++ b/capio/tests/unit/server/src/client_manager.hpp @@ -0,0 +1,4 @@ +#ifndef CAPIO_CLIENT_MANAGER_HPP +#define CAPIO_CLIENT_MANAGER_HPP + +#endif // CAPIO_CLIENT_MANAGER_HPP diff --git a/capio/tests/unit/server/src/main.cpp b/capio/tests/unit/server/src/main.cpp new file mode 100644 index 000000000..a84388a26 --- /dev/null +++ b/capio/tests/unit/server/src/main.cpp @@ -0,0 +1,5 @@ +#include +#include + +#include "capio_file.hpp" +#include "client_manager.hpp" \ No newline at end of file From b94e039625f18baafcb74a5998a5406d86fdfd18 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 17 Feb 2026 12:56:38 +0000 Subject: [PATCH 02/19] Tests --- CMakeLists.txt | 10 ++++++ capio/server/CMakeLists.txt | 6 ---- capio/server/capio_server.cpp | 2 +- capio/server/include/storage/manager.hpp | 9 +++++- capio/server/src/client_manager.cpp | 2 +- capio/server/src/storage_manager.cpp | 4 +-- capio/tests/unit/server/CMakeLists.txt | 32 +++++++++++++++++-- .../tests/unit/server/src/client_manager.hpp | 17 ++++++++++ 8 files changed, 69 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bbd164c4..dc0842141 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,16 @@ IF (CAPIO_LOG AND CMAKE_BUILD_TYPE STREQUAL "Debug") include_directories("${PROJECT_BINARY_DIR}/include/syscall") ENDIF (CAPIO_LOG AND CMAKE_BUILD_TYPE STREQUAL "Debug") + +##################################### +# Global required dependencies +##################################### +FetchContent_Declare( + capio_cl + GIT_REPOSITORY https://github.com/High-Performance-IO/CAPIO-CL.git + GIT_TAG v1.3.4 +) + ##################################### # Targets ##################################### diff --git a/capio/server/CMakeLists.txt b/capio/server/CMakeLists.txt index a7f5cf2db..7d6788fa5 100644 --- a/capio/server/CMakeLists.txt +++ b/capio/server/CMakeLists.txt @@ -19,12 +19,6 @@ FetchContent_Declare( set(ARGS_BUILD_EXAMPLE OFF CACHE INTERNAL "") set(ARGS_BUILD_UNITTESTS OFF CACHE INTERNAL "") -FetchContent_Declare( - capio_cl - GIT_REPOSITORY https://github.com/High-Performance-IO/CAPIO-CL.git - GIT_TAG v1.3.4 -) - FetchContent_MakeAvailable(args capio_cl) ##################################### diff --git a/capio/server/capio_server.cpp b/capio/server/capio_server.cpp index c0c29afa8..c60d2d522 100644 --- a/capio/server/capio_server.cpp +++ b/capio/server/capio_server.cpp @@ -296,8 +296,8 @@ int main(int argc, char **argv) { open_files_location(); shm_canary = new CapioShmCanary(capio_cl_engine->getWorkflowName()); - storage_manager = new StorageManager(); client_manager = new ClientManager(); + storage_manager = new StorageManager(client_manager); std::thread server_thread(capio_server, std::ref(internal_server_sem)); LOG("capio_server thread started"); diff --git a/capio/server/include/storage/manager.hpp b/capio/server/include/storage/manager.hpp index 069c99132..04bb8b239 100644 --- a/capio/server/include/storage/manager.hpp +++ b/capio/server/include/storage/manager.hpp @@ -7,6 +7,8 @@ #include "utils/capio_file.hpp" #include "utils/shared_mutex.hpp" +#include "client-manager/client_manager.hpp" + #include #include @@ -20,6 +22,10 @@ * and their respective offsets. */ class StorageManager { + + ///@brief reference to ClientManager to avoid using the global instanced variable + ClientManager *_client_manager; + /** * @brief Mutex to protect access to _storage internal data structure. */ @@ -109,8 +115,9 @@ class StorageManager { * @brief Constructs a new StorageService instance. * * Initializes the server and logs its completion. + * @param client_manager Reference to ClientManager instance */ - StorageManager(); + StorageManager(ClientManager *client_manager); /** * @brief Destroys the StorageService instance. diff --git a/capio/server/src/client_manager.cpp b/capio/server/src/client_manager.cpp index f4cedc976..78628636d 100644 --- a/capio/server/src/client_manager.cpp +++ b/capio/server/src/client_manager.cpp @@ -90,7 +90,7 @@ void ClientManager::replyToClient(const int tid, const off64_t offset, char *buf out->second.ServerToClient.write(buf + offset, count); return; } - LOG("Err: no such buffer for provided tid"); + throw std::runtime_error("Err: no such buffer for provided tid"); } // NOTE: do not use const reference for path here as the emplace method leaves the original in an diff --git a/capio/server/src/storage_manager.cpp b/capio/server/src/storage_manager.cpp index d4f7eb55a..eff266ab2 100644 --- a/capio/server/src/storage_manager.cpp +++ b/capio/server/src/storage_manager.cpp @@ -60,12 +60,12 @@ void StorageManager::addDirectoryEntry(const pid_t tid, const std::filesystem::p c_file.insert_sector(base_offset, data_size); ++c_file.n_files; - client_manager->registerProducedFile(tid, dir); + _client_manager->registerProducedFile(tid, dir); if (c_file.n_files == c_file.n_files_expected) { c_file.set_complete(); } } -StorageManager::StorageManager() { +StorageManager::StorageManager(ClientManager *client_manager) : _client_manager(client_manager) { server_println(CAPIO_LOG_SERVER_CLI_LEVEL_INFO, "StorageManager initialization completed."); } diff --git a/capio/tests/unit/server/CMakeLists.txt b/capio/tests/unit/server/CMakeLists.txt index b0ebfd8ba..038903d49 100644 --- a/capio/tests/unit/server/CMakeLists.txt +++ b/capio/tests/unit/server/CMakeLists.txt @@ -2,9 +2,18 @@ # Target information ##################################### set(TARGET_NAME capio_server_unit_tests) + +FetchContent_MakeAvailable(capio_cl) + set(TARGET_INCLUDE_FOLDER "${PROJECT_SOURCE_DIR}/capio/server") + +file(GLOB_RECURSE SERVER_SOURCES + "${CMAKE_SOURCE_DIR}/capio/server/**/*.cpp" +) + set(TARGET_SOURCES src/main.cpp + ${SERVER_SOURCES} ) ##################################### @@ -20,12 +29,15 @@ target_sources(${TARGET_NAME} PRIVATE "${CAPIO_COMMON_HEADERS}" "${CAPIO_SERVER_HEADERS}" ) -target_include_directories(${TARGET_NAME} PRIVATE "${TARGET_INCLUDE_FOLDER}/include") +target_include_directories(${TARGET_NAME} PRIVATE + "${TARGET_INCLUDE_FOLDER}/include" + ${capio_cl_SOURCE_DIR} +) ##################################### # Link libraries ##################################### -target_link_libraries(${TARGET_NAME} PRIVATE GTest::gtest_main rt) +target_link_libraries(${TARGET_NAME} PRIVATE GTest::gtest_main rt libcapio_cl) ##################################### # Configure tests @@ -34,6 +46,22 @@ gtest_discover_tests(${TARGET_NAME} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} ) +##################################### +# Code coverage +##################################### +IF (ENABLE_COVERAGE) + IF (CMAKE_BUILD_TYPE STREQUAL "Debug") + target_compile_definitions(${TARGET_NAME} PRIVATE CAPIO_COVERAGE) + target_compile_options(${TARGET_NAME} PRIVATE --coverage -fprofile-arcs -ftest-coverage) + target_link_options(${TARGET_NAME} PRIVATE --coverage -fprofile-arcs -ftest-coverage) + IF (CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") + target_link_libraries(${TARGET_NAME} PRIVATE gcov) + ENDIF (CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") + ELSE (CMAKE_BUILD_TYPE STREQUAL "Debug") + message(WARNING "Code coverage is disabled in release mode.") + ENDIF (CMAKE_BUILD_TYPE STREQUAL "Debug") +ENDIF (ENABLE_COVERAGE) + ##################################### # Install rules ##################################### diff --git a/capio/tests/unit/server/src/client_manager.hpp b/capio/tests/unit/server/src/client_manager.hpp index ff59b6da2..6565c20f3 100644 --- a/capio/tests/unit/server/src/client_manager.hpp +++ b/capio/tests/unit/server/src/client_manager.hpp @@ -1,4 +1,21 @@ #ifndef CAPIO_CLIENT_MANAGER_HPP #define CAPIO_CLIENT_MANAGER_HPP +char *node_name; +std::string workflow_name; + +#include "capiocl.hpp" +#include "utils/capiocl_adapter.hpp" +capiocl::Engine capio_cl_engine; +const capiocl::Engine &CapioCLEngine::get() { return capio_cl_engine; } + +#include "client-manager/client_manager.hpp" +ClientManager *clientManager; + +TEST(clientManagerTestSuite, testReplyToNonClient) { + clientManager = new ClientManager(); + char buffer[1024]; + EXPECT_THROW(clientManager->replyToClient(-1, 0, buffer, 0), std::runtime_error); +} + #endif // CAPIO_CLIENT_MANAGER_HPP From b6fe558c0cbb077410e71f59b9492fae8272bf84 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 17 Feb 2026 13:56:36 +0000 Subject: [PATCH 03/19] tests --- .github/workflows/ci-tests.yaml | 3 ++ capio/server/src/client_manager.cpp | 4 +- .../tests/unit/server/src/client_manager.hpp | 51 +++++++++++++++---- capio/tests/unit/server/src/main.cpp | 11 +++- 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci-tests.yaml b/.github/workflows/ci-tests.yaml index 6862c58a8..ad802ca14 100644 --- a/.github/workflows/ci-tests.yaml +++ b/.github/workflows/ci-tests.yaml @@ -191,6 +191,9 @@ jobs: --gtest_break_on_failure \ --gtest_print_time=1 + # clean shm after unit tests + rm -rf /dev/shm/* + echo "Run CAPIO syscall Unit tests" LD_PRELOAD=libcapio_posix.so \ capio_syscall_unit_tests \ diff --git a/capio/server/src/client_manager.cpp b/capio/server/src/client_manager.cpp index 78628636d..b3e96ff34 100644 --- a/capio/server/src/client_manager.cpp +++ b/capio/server/src/client_manager.cpp @@ -153,11 +153,11 @@ const std::vector &ClientManager::getProducedFiles(const pid_t tid) const std::string &ClientManager::getAppName(const pid_t tid) const { START_LOG(gettid(), "call(tid=%ld)", tid); - static std::string default_app_name = CAPIO_DEFAULT_APP_NAME; if (const auto itm = app_names.find(tid); itm != app_names.end()) { return itm->second; + } else { + return CAPIO_DEFAULT_APP_NAME; } - return default_app_name; } SPSCQueue &ClientManager::getClientToServerDataBuffers(const pid_t tid) { diff --git a/capio/tests/unit/server/src/client_manager.hpp b/capio/tests/unit/server/src/client_manager.hpp index 6565c20f3..e6decc322 100644 --- a/capio/tests/unit/server/src/client_manager.hpp +++ b/capio/tests/unit/server/src/client_manager.hpp @@ -1,21 +1,50 @@ #ifndef CAPIO_CLIENT_MANAGER_HPP #define CAPIO_CLIENT_MANAGER_HPP -char *node_name; -std::string workflow_name; - -#include "capiocl.hpp" -#include "utils/capiocl_adapter.hpp" -capiocl::Engine capio_cl_engine; -const capiocl::Engine &CapioCLEngine::get() { return capio_cl_engine; } - #include "client-manager/client_manager.hpp" -ClientManager *clientManager; + +#include TEST(clientManagerTestSuite, testReplyToNonClient) { - clientManager = new ClientManager(); + ClientManager client_manager; char buffer[1024]; - EXPECT_THROW(clientManager->replyToClient(-1, 0, buffer, 0), std::runtime_error); + EXPECT_THROW(client_manager.replyToClient(-1, 0, buffer, 0), std::runtime_error); +} + +TEST(clientManagerTestSuite, testGetNumberOfConnectedClients) { + ClientManager client_manager; + EXPECT_EQ(client_manager.getConnectedPosixClients(), 0); + + client_manager.registerClient(1234); + + EXPECT_EQ(client_manager.getConnectedPosixClients(), 1); + + client_manager.removeClient(1234); + + EXPECT_EQ(client_manager.getConnectedPosixClients(), 0); +} + +TEST(ClientManagerTestSuite, testFailedRequestCode) { + + ClientManager client_manager; + + // NOTE: there is no need to delete this object as it is only attaching to the shm allocated by + // client_manager. Also calling delete on this raises std::terminate as an exception is thrown + // in the destructor + // TODO: change behaviour of ERR_EXIT to not throw exceptions but only print error and continue + const auto request_queue = + new CircularBuffer(SHM_COMM_CHAN_NAME, CAPIO_REQ_BUFF_CNT, CAPIO_REQ_MAX_SIZE); + + char req[CAPIO_REQ_MAX_SIZE], new_req[CAPIO_REQ_MAX_SIZE]; + sprintf(req, "123 aaaa bbbb cccc"); + request_queue->write(req, CAPIO_REQ_MAX_SIZE); + + EXPECT_EQ(client_manager.readNextRequest(new_req), 123); + + sprintf(req, "abc aaaa bbbb cccc"); + request_queue->write(req, CAPIO_REQ_MAX_SIZE); + + EXPECT_EQ(client_manager.readNextRequest(new_req), -1); } #endif // CAPIO_CLIENT_MANAGER_HPP diff --git a/capio/tests/unit/server/src/main.cpp b/capio/tests/unit/server/src/main.cpp index a84388a26..f896dc577 100644 --- a/capio/tests/unit/server/src/main.cpp +++ b/capio/tests/unit/server/src/main.cpp @@ -1,5 +1,14 @@ +#include "common/constants.hpp" + #include -#include + +char *node_name; +std::string workflow_name = CAPIO_DEFAULT_WORKFLOW_NAME; + +#include "capiocl.hpp" +#include "utils/capiocl_adapter.hpp" +capiocl::Engine capio_cl_engine; +const capiocl::Engine &CapioCLEngine::get() { return capio_cl_engine; } #include "capio_file.hpp" #include "client_manager.hpp" \ No newline at end of file From 3feefeece5dd6d371b194560100f4741726f4b2d Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 17 Feb 2026 14:46:05 +0000 Subject: [PATCH 04/19] Fixed workflow execution sequence --- .github/workflows/ci-tests.yaml | 3 --- capio/server/src/client_manager.cpp | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-tests.yaml b/.github/workflows/ci-tests.yaml index ad802ca14..6862c58a8 100644 --- a/.github/workflows/ci-tests.yaml +++ b/.github/workflows/ci-tests.yaml @@ -191,9 +191,6 @@ jobs: --gtest_break_on_failure \ --gtest_print_time=1 - # clean shm after unit tests - rm -rf /dev/shm/* - echo "Run CAPIO syscall Unit tests" LD_PRELOAD=libcapio_posix.so \ capio_syscall_unit_tests \ diff --git a/capio/server/src/client_manager.cpp b/capio/server/src/client_manager.cpp index b3e96ff34..b73ddb6d9 100644 --- a/capio/server/src/client_manager.cpp +++ b/capio/server/src/client_manager.cpp @@ -153,10 +153,11 @@ const std::vector &ClientManager::getProducedFiles(const pid_t tid) const std::string &ClientManager::getAppName(const pid_t tid) const { START_LOG(gettid(), "call(tid=%ld)", tid); + static std::string default_app_name = CAPIO_DEFAULT_APP_NAME; if (const auto itm = app_names.find(tid); itm != app_names.end()) { return itm->second; } else { - return CAPIO_DEFAULT_APP_NAME; + return default_app_name; } } From 80b8507e04e2a9001e778cae896ee7b3d393c1a7 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 17 Feb 2026 15:13:42 +0000 Subject: [PATCH 05/19] Cleanup --- capio/server/include/client-manager/client_manager.hpp | 3 +++ capio/server/src/client_manager.cpp | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/capio/server/include/client-manager/client_manager.hpp b/capio/server/include/client-manager/client_manager.hpp index 824fed74b..3c91eb705 100644 --- a/capio/server/include/client-manager/client_manager.hpp +++ b/capio/server/include/client-manager/client_manager.hpp @@ -17,6 +17,9 @@ class ClientManager { CircularBuffer requests; std::unordered_map> responses; + /// @brief default app name + const std::string default_app_name = CAPIO_DEFAULT_APP_NAME; + /** * Data buffers variables */ diff --git a/capio/server/src/client_manager.cpp b/capio/server/src/client_manager.cpp index b73ddb6d9..aef6d9538 100644 --- a/capio/server/src/client_manager.cpp +++ b/capio/server/src/client_manager.cpp @@ -153,7 +153,6 @@ const std::vector &ClientManager::getProducedFiles(const pid_t tid) const std::string &ClientManager::getAppName(const pid_t tid) const { START_LOG(gettid(), "call(tid=%ld)", tid); - static std::string default_app_name = CAPIO_DEFAULT_APP_NAME; if (const auto itm = app_names.find(tid); itm != app_names.end()) { return itm->second; } else { From 90fd943b8a41a63b41b4ff945c138afe194be5a7 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 17 Feb 2026 15:35:25 +0000 Subject: [PATCH 06/19] More tests --- capio/server/src/client_manager.cpp | 12 ++++++------ capio/tests/unit/server/src/client_manager.hpp | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/capio/server/src/client_manager.cpp b/capio/server/src/client_manager.cpp index aef6d9538..857f369a2 100644 --- a/capio/server/src/client_manager.cpp +++ b/capio/server/src/client_manager.cpp @@ -115,16 +115,16 @@ void ClientManager::registerProducedFile(const pid_t tid, std::string path) { } void ClientManager::removeProducedFile(const pid_t tid, const std::filesystem::path &path) { - if (const auto itm = files_created_by_producer.find(tid); - itm != files_created_by_producer.end()) { - auto &v = itm->second; + const auto itm0 = files_created_by_producer.find(tid); + if (itm0 != files_created_by_producer.end()) { + auto &v = itm0->second; v.erase(std::remove(v.begin(), v.end(), path), v.end()); } const std::string &app_name = this->getAppName(tid); - if (const auto itm = files_created_by_app_name.find(app_name); - itm != files_created_by_app_name.end()) { - auto &v = itm->second; + const auto itm1 = files_created_by_app_name.find(app_name); + if (itm1 != files_created_by_app_name.end()) { + auto &v = itm1->second; v.erase(std::remove(v.begin(), v.end(), path), v.end()); } } diff --git a/capio/tests/unit/server/src/client_manager.hpp b/capio/tests/unit/server/src/client_manager.hpp index e6decc322..b548c8dc5 100644 --- a/capio/tests/unit/server/src/client_manager.hpp +++ b/capio/tests/unit/server/src/client_manager.hpp @@ -47,4 +47,19 @@ TEST(ClientManagerTestSuite, testFailedRequestCode) { EXPECT_EQ(client_manager.readNextRequest(new_req), -1); } +TEST(ClientManagerTestSuite, testAddAndRemoveProducedFiles) { + ClientManager client_manager; + + client_manager.registerClient(1234, "test_app"); + client_manager.registerProducedFile(1234, "test.txt"); + + EXPECT_TRUE(client_manager.isProducer(1234, "test.txt")); + + client_manager.removeProducedFile(1234, "test.txt"); + EXPECT_FALSE(client_manager.isProducer(1234, "test.txt")); + + client_manager.registerProducedFile(1111, "test1.txt"); + EXPECT_FALSE(client_manager.isProducer(1111, "test1.txt")); +} + #endif // CAPIO_CLIENT_MANAGER_HPP From 973dcaf610c1f563cfbcb70666e5b7474f06bf49 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 17 Feb 2026 17:42:30 +0000 Subject: [PATCH 07/19] Added more tests --- capio/server/src/client_manager.cpp | 12 ++++---- capio/server/src/storage_manager.cpp | 6 ++-- capio/tests/unit/server/src/main.cpp | 3 +- .../tests/unit/server/src/storage_manager.hpp | 29 +++++++++++++++++++ 4 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 capio/tests/unit/server/src/storage_manager.hpp diff --git a/capio/server/src/client_manager.cpp b/capio/server/src/client_manager.cpp index 857f369a2..aef6d9538 100644 --- a/capio/server/src/client_manager.cpp +++ b/capio/server/src/client_manager.cpp @@ -115,16 +115,16 @@ void ClientManager::registerProducedFile(const pid_t tid, std::string path) { } void ClientManager::removeProducedFile(const pid_t tid, const std::filesystem::path &path) { - const auto itm0 = files_created_by_producer.find(tid); - if (itm0 != files_created_by_producer.end()) { - auto &v = itm0->second; + if (const auto itm = files_created_by_producer.find(tid); + itm != files_created_by_producer.end()) { + auto &v = itm->second; v.erase(std::remove(v.begin(), v.end(), path), v.end()); } const std::string &app_name = this->getAppName(tid); - const auto itm1 = files_created_by_app_name.find(app_name); - if (itm1 != files_created_by_app_name.end()) { - auto &v = itm1->second; + if (const auto itm = files_created_by_app_name.find(app_name); + itm != files_created_by_app_name.end()) { + auto &v = itm->second; v.erase(std::remove(v.begin(), v.end(), path), v.end()); } } diff --git a/capio/server/src/storage_manager.cpp b/capio/server/src/storage_manager.cpp index eff266ab2..f036d2b24 100644 --- a/capio/server/src/storage_manager.cpp +++ b/capio/server/src/storage_manager.cpp @@ -228,9 +228,11 @@ void StorageManager::clone(const pid_t parent_tid, const pid_t child_tid) { std::vector StorageManager::getPaths() const { const shared_lock_guard slg(_mutex_storage); - std::vector paths(_storage.size()); + std::vector paths; for (const auto &[file_path, _] : _storage) { - paths.emplace_back(file_path); + if (!file_path.empty()) { + paths.emplace_back(file_path); + } } return paths; } diff --git a/capio/tests/unit/server/src/main.cpp b/capio/tests/unit/server/src/main.cpp index f896dc577..9906cfc8a 100644 --- a/capio/tests/unit/server/src/main.cpp +++ b/capio/tests/unit/server/src/main.cpp @@ -11,4 +11,5 @@ capiocl::Engine capio_cl_engine; const capiocl::Engine &CapioCLEngine::get() { return capio_cl_engine; } #include "capio_file.hpp" -#include "client_manager.hpp" \ No newline at end of file +#include "client_manager.hpp" +#include "storage_manager.hpp" \ No newline at end of file diff --git a/capio/tests/unit/server/src/storage_manager.hpp b/capio/tests/unit/server/src/storage_manager.hpp new file mode 100644 index 000000000..f6a106550 --- /dev/null +++ b/capio/tests/unit/server/src/storage_manager.hpp @@ -0,0 +1,29 @@ +#ifndef CAPIO_STORAGE_MANAGER_TEST_HPP +#define CAPIO_STORAGE_MANAGER_TEST_HPP +#include "storage/manager.hpp" + +TEST(StorageMAnagerTestSuite, testGetPaths) { + ClientManager client_manager; + StorageManager storage_manager(&client_manager); + + std::vector test_file_paths = { + "test1.txt", + "test2.txt", + "test3.txt", + }; + + for (const auto &path : test_file_paths) { + storage_manager.add(path, false, 0); + } + + const auto storage_paths = storage_manager.getPaths(); + + EXPECT_EQ(storage_paths.size(), test_file_paths.size()); + + for (const auto &path : test_file_paths) { + EXPECT_TRUE(std::find(storage_paths.begin(), storage_paths.end(), path) != + storage_paths.end()); + } +} + +#endif // CAPIO_STORAGE_MANAGER_TEST_HPP From 3e089c214e40fe8319b5c8d6f65590db99ea6810 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 17 Feb 2026 18:55:07 +0000 Subject: [PATCH 08/19] More tests --- capio/server/src/storage_manager.cpp | 2 +- .../tests/unit/server/src/storage_manager.hpp | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/capio/server/src/storage_manager.cpp b/capio/server/src/storage_manager.cpp index f036d2b24..1cc75683e 100644 --- a/capio/server/src/storage_manager.cpp +++ b/capio/server/src/storage_manager.cpp @@ -187,7 +187,7 @@ CapioFile &StorageManager::add(const std::filesystem::path &path, bool is_dir, s auto n_close_count = CapioCLEngine::get().getCommitCloseCount(path); if (n_file > 1) { - // NODE: This is probably because it needs to be filled even when dealing with directories + // NOTE: This is probably because it needs to be filled even when dealing with directories init_size = CAPIO_DEFAULT_DIR_INITIAL_SIZE; } diff --git a/capio/tests/unit/server/src/storage_manager.hpp b/capio/tests/unit/server/src/storage_manager.hpp index f6a106550..ad117c14a 100644 --- a/capio/tests/unit/server/src/storage_manager.hpp +++ b/capio/tests/unit/server/src/storage_manager.hpp @@ -1,6 +1,7 @@ #ifndef CAPIO_STORAGE_MANAGER_TEST_HPP #define CAPIO_STORAGE_MANAGER_TEST_HPP #include "storage/manager.hpp" +#include "utils/location.hpp" TEST(StorageMAnagerTestSuite, testGetPaths) { ClientManager client_manager; @@ -26,4 +27,50 @@ TEST(StorageMAnagerTestSuite, testGetPaths) { } } +TEST(StorageMAnagerTestSuite, testExceptions) { + ClientManager client_manager; + StorageManager storage_manager(&client_manager); + + EXPECT_THROW(storage_manager.get("test.txt"), std::runtime_error); + EXPECT_THROW(storage_manager.get(1234, 1234), std::runtime_error); +} + +TEST(StorageMAnagerTestSuite, testInitDirectory) { + ClientManager client_manager; + StorageManager storage_manager(&client_manager); + node_name = new char[HOST_NAME_MAX]; + gethostname(node_name, HOST_NAME_MAX); + open_files_location(); + + capio_cl_engine.setDirectory("myDirectory"); + capio_cl_engine.setDirectoryFileCount("myDirectory", 10); + + storage_manager.add("myDirectory", true, 0); + + const auto &dir = storage_manager.get("myDirectory"); + + EXPECT_EQ(dir.get_buf_size(), CAPIO_DEFAULT_DIR_INITIAL_SIZE); + + storage_manager.updateDirectory(1, "myDirectory"); + const auto &dir1 = storage_manager.get("myDirectory"); + + EXPECT_FALSE(dir1.first_write); +} + +TEST(StorageMAnagerTestSuite, testAddDirectoryFailure) { + char *old_capio_dir = getenv("CAPIO_DIR"); + setenv("CAPIO_DIR", "/", 1); + node_name = new char[HOST_NAME_MAX]; + gethostname(node_name, HOST_NAME_MAX); + open_files_location(); + ClientManager client_manager; + StorageManager storage_manager(&client_manager); + storage_manager.add("/tmp", true, 0); + EXPECT_EQ(storage_manager.addDirectory(1, "/tmp/newDirectoryFail"), 0); + EXPECT_EQ(storage_manager.addDirectory(1, "/tmp/newDirectoryFail"), 1); + if (old_capio_dir != nullptr) { + setenv("CAPIO_DIR", old_capio_dir, 1); + } +} + #endif // CAPIO_STORAGE_MANAGER_TEST_HPP From b00268c6fcb20eacc2fbb6a746cc76dcc98ef8d6 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 17 Feb 2026 19:08:28 +0000 Subject: [PATCH 09/19] Rename test --- capio/server/src/storage_manager.cpp | 4 +-- .../tests/unit/server/src/storage_manager.hpp | 25 ++++++++++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/capio/server/src/storage_manager.cpp b/capio/server/src/storage_manager.cpp index 1cc75683e..c02dca051 100644 --- a/capio/server/src/storage_manager.cpp +++ b/capio/server/src/storage_manager.cpp @@ -230,9 +230,7 @@ std::vector StorageManager::getPaths() const { const shared_lock_guard slg(_mutex_storage); std::vector paths; for (const auto &[file_path, _] : _storage) { - if (!file_path.empty()) { - paths.emplace_back(file_path); - } + paths.emplace_back(file_path); } return paths; } diff --git a/capio/tests/unit/server/src/storage_manager.hpp b/capio/tests/unit/server/src/storage_manager.hpp index ad117c14a..6adce56d6 100644 --- a/capio/tests/unit/server/src/storage_manager.hpp +++ b/capio/tests/unit/server/src/storage_manager.hpp @@ -3,7 +3,7 @@ #include "storage/manager.hpp" #include "utils/location.hpp" -TEST(StorageMAnagerTestSuite, testGetPaths) { +TEST(StorageManagerTestSuite, testGetPaths) { ClientManager client_manager; StorageManager storage_manager(&client_manager); @@ -27,7 +27,7 @@ TEST(StorageMAnagerTestSuite, testGetPaths) { } } -TEST(StorageMAnagerTestSuite, testExceptions) { +TEST(StorageManagerTestSuite, testExceptions) { ClientManager client_manager; StorageManager storage_manager(&client_manager); @@ -35,7 +35,7 @@ TEST(StorageMAnagerTestSuite, testExceptions) { EXPECT_THROW(storage_manager.get(1234, 1234), std::runtime_error); } -TEST(StorageMAnagerTestSuite, testInitDirectory) { +TEST(StorageManagerTestSuite, testInitDirectory) { ClientManager client_manager; StorageManager storage_manager(&client_manager); node_name = new char[HOST_NAME_MAX]; @@ -57,7 +57,7 @@ TEST(StorageMAnagerTestSuite, testInitDirectory) { EXPECT_FALSE(dir1.first_write); } -TEST(StorageMAnagerTestSuite, testAddDirectoryFailure) { +TEST(StorageManagerTestSuite, testAddDirectoryFailure) { char *old_capio_dir = getenv("CAPIO_DIR"); setenv("CAPIO_DIR", "/", 1); node_name = new char[HOST_NAME_MAX]; @@ -73,4 +73,21 @@ TEST(StorageMAnagerTestSuite, testAddDirectoryFailure) { } } +TEST(StorageManagerTestSuite, testRemameFile) { + ClientManager client_manager; + StorageManager storage_manager(&client_manager); + + storage_manager.add("oldName", false, 0); + storage_manager.add("oldNameNoChange", false, 0); + + storage_manager.addFileToTid(1234, 3, "oldName", 0); + storage_manager.addFileToTid(1234, 4, "oldNameNoChange", 0); + + storage_manager.add("oldNameNoChange", false, 0); + storage_manager.rename("oldName", "newName"); + + EXPECT_THROW(storage_manager.get("oldName"), std::runtime_error); + EXPECT_NO_THROW(storage_manager.get("oldNameNoChange")); +} + #endif // CAPIO_STORAGE_MANAGER_TEST_HPP From e1bc2abd87a5bc02493436c2675c1ba8af953e07 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 18 Feb 2026 11:32:10 +0000 Subject: [PATCH 10/19] wip --- capio/tests/unit/server/src/main.cpp | 5 +++-- .../tests/unit/server/src/storage_manager.hpp | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/capio/tests/unit/server/src/main.cpp b/capio/tests/unit/server/src/main.cpp index 9906cfc8a..b1738dc77 100644 --- a/capio/tests/unit/server/src/main.cpp +++ b/capio/tests/unit/server/src/main.cpp @@ -6,9 +6,10 @@ char *node_name; std::string workflow_name = CAPIO_DEFAULT_WORKFLOW_NAME; #include "capiocl.hpp" +#include "capiocl/engine.h" #include "utils/capiocl_adapter.hpp" -capiocl::Engine capio_cl_engine; -const capiocl::Engine &CapioCLEngine::get() { return capio_cl_engine; } +capiocl::engine::Engine capio_cl_engine(true); +const capiocl::engine::Engine &CapioCLEngine::get() { return capio_cl_engine; } #include "capio_file.hpp" #include "client_manager.hpp" diff --git a/capio/tests/unit/server/src/storage_manager.hpp b/capio/tests/unit/server/src/storage_manager.hpp index 6adce56d6..9d35ce1ad 100644 --- a/capio/tests/unit/server/src/storage_manager.hpp +++ b/capio/tests/unit/server/src/storage_manager.hpp @@ -90,4 +90,23 @@ TEST(StorageManagerTestSuite, testRemameFile) { EXPECT_NO_THROW(storage_manager.get("oldNameNoChange")); } +TEST(StorageManagerTestSuite, testNumberOfOpensAfterClone) { + + ClientManager client_manager; + StorageManager storage_manager(&client_manager); + + storage_manager.add("myFile", false, 0); + storage_manager.addFileToTid(1234, 3, "myFile", 0); + storage_manager.clone(1234, 5678); + + EXPECT_FALSE(storage_manager.get("myFile").is_deletable()); + + storage_manager.removeFromTid(1234, 3); + EXPECT_FALSE(storage_manager.get("myFile").is_deletable()); + + storage_manager.removeFromTid(5678, 3); + + EXPECT_TRUE(storage_manager.get("myFile").is_deletable()); +} + #endif // CAPIO_STORAGE_MANAGER_TEST_HPP From 1d26510272e2c8a7ebcde84438978e37943a67ea Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 18 Feb 2026 15:11:10 +0000 Subject: [PATCH 11/19] Improved test env --- capio/tests/unit/server/src/client_manager.hpp | 8 ++++---- capio/tests/unit/server/src/main.cpp | 11 +++++++++-- capio/tests/unit/server/src/storage_manager.hpp | 16 ++++++++-------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/capio/tests/unit/server/src/client_manager.hpp b/capio/tests/unit/server/src/client_manager.hpp index b548c8dc5..2b2bbb0d8 100644 --- a/capio/tests/unit/server/src/client_manager.hpp +++ b/capio/tests/unit/server/src/client_manager.hpp @@ -5,13 +5,13 @@ #include -TEST(clientManagerTestSuite, testReplyToNonClient) { +TEST_F(CapioServerUnitTestEnviron, testReplyToNonClient) { ClientManager client_manager; char buffer[1024]; EXPECT_THROW(client_manager.replyToClient(-1, 0, buffer, 0), std::runtime_error); } -TEST(clientManagerTestSuite, testGetNumberOfConnectedClients) { +TEST_F(CapioServerUnitTestEnviron, testGetNumberOfConnectedClients) { ClientManager client_manager; EXPECT_EQ(client_manager.getConnectedPosixClients(), 0); @@ -24,7 +24,7 @@ TEST(clientManagerTestSuite, testGetNumberOfConnectedClients) { EXPECT_EQ(client_manager.getConnectedPosixClients(), 0); } -TEST(ClientManagerTestSuite, testFailedRequestCode) { +TEST_F(CapioServerUnitTestEnviron, testFailedRequestCode) { ClientManager client_manager; @@ -47,7 +47,7 @@ TEST(ClientManagerTestSuite, testFailedRequestCode) { EXPECT_EQ(client_manager.readNextRequest(new_req), -1); } -TEST(ClientManagerTestSuite, testAddAndRemoveProducedFiles) { +TEST_F(CapioServerUnitTestEnviron, testAddAndRemoveProducedFiles) { ClientManager client_manager; client_manager.registerClient(1234, "test_app"); diff --git a/capio/tests/unit/server/src/main.cpp b/capio/tests/unit/server/src/main.cpp index b1738dc77..153b65aee 100644 --- a/capio/tests/unit/server/src/main.cpp +++ b/capio/tests/unit/server/src/main.cpp @@ -8,8 +8,15 @@ std::string workflow_name = CAPIO_DEFAULT_WORKFLOW_NAME; #include "capiocl.hpp" #include "capiocl/engine.h" #include "utils/capiocl_adapter.hpp" -capiocl::engine::Engine capio_cl_engine(true); -const capiocl::engine::Engine &CapioCLEngine::get() { return capio_cl_engine; } +capiocl::engine::Engine *capio_cl_engine; +const capiocl::engine::Engine &CapioCLEngine::get() { return *capio_cl_engine; } + +class CapioServerUnitTestEnviron : public testing::Test { + protected: + void SetUp() override { capio_cl_engine = new capiocl::engine::Engine(true); } + + void TearDown() override { delete capio_cl_engine; } +}; #include "capio_file.hpp" #include "client_manager.hpp" diff --git a/capio/tests/unit/server/src/storage_manager.hpp b/capio/tests/unit/server/src/storage_manager.hpp index 9d35ce1ad..6cafef670 100644 --- a/capio/tests/unit/server/src/storage_manager.hpp +++ b/capio/tests/unit/server/src/storage_manager.hpp @@ -3,7 +3,7 @@ #include "storage/manager.hpp" #include "utils/location.hpp" -TEST(StorageManagerTestSuite, testGetPaths) { +TEST_F(CapioServerUnitTestEnviron, testGetPaths) { ClientManager client_manager; StorageManager storage_manager(&client_manager); @@ -27,7 +27,7 @@ TEST(StorageManagerTestSuite, testGetPaths) { } } -TEST(StorageManagerTestSuite, testExceptions) { +TEST_F(CapioServerUnitTestEnviron, testExceptions) { ClientManager client_manager; StorageManager storage_manager(&client_manager); @@ -35,15 +35,15 @@ TEST(StorageManagerTestSuite, testExceptions) { EXPECT_THROW(storage_manager.get(1234, 1234), std::runtime_error); } -TEST(StorageManagerTestSuite, testInitDirectory) { +TEST_F(CapioServerUnitTestEnviron, testInitDirectory) { ClientManager client_manager; StorageManager storage_manager(&client_manager); node_name = new char[HOST_NAME_MAX]; gethostname(node_name, HOST_NAME_MAX); open_files_location(); - capio_cl_engine.setDirectory("myDirectory"); - capio_cl_engine.setDirectoryFileCount("myDirectory", 10); + capio_cl_engine->setDirectory("myDirectory"); + capio_cl_engine->setDirectoryFileCount("myDirectory", 10); storage_manager.add("myDirectory", true, 0); @@ -57,7 +57,7 @@ TEST(StorageManagerTestSuite, testInitDirectory) { EXPECT_FALSE(dir1.first_write); } -TEST(StorageManagerTestSuite, testAddDirectoryFailure) { +TEST_F(CapioServerUnitTestEnviron, testAddDirectoryFailure) { char *old_capio_dir = getenv("CAPIO_DIR"); setenv("CAPIO_DIR", "/", 1); node_name = new char[HOST_NAME_MAX]; @@ -73,7 +73,7 @@ TEST(StorageManagerTestSuite, testAddDirectoryFailure) { } } -TEST(StorageManagerTestSuite, testRemameFile) { +TEST_F(CapioServerUnitTestEnviron, testRemameFile) { ClientManager client_manager; StorageManager storage_manager(&client_manager); @@ -90,7 +90,7 @@ TEST(StorageManagerTestSuite, testRemameFile) { EXPECT_NO_THROW(storage_manager.get("oldNameNoChange")); } -TEST(StorageManagerTestSuite, testNumberOfOpensAfterClone) { +TEST_F(CapioServerUnitTestEnviron, testNumberOfOpensAfterClone) { ClientManager client_manager; StorageManager storage_manager(&client_manager); From b6c0b249330ffdf7fd822f4d191f488917ba6bca Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 18 Feb 2026 15:23:02 +0000 Subject: [PATCH 12/19] Refactored structure of tests --- .../tests/unit/server/src/client_manager.hpp | 48 ++++------ capio/tests/unit/server/src/main.cpp | 45 +++++++++- .../tests/unit/server/src/storage_manager.hpp | 87 ++++++++----------- 3 files changed, 94 insertions(+), 86 deletions(-) diff --git a/capio/tests/unit/server/src/client_manager.hpp b/capio/tests/unit/server/src/client_manager.hpp index 2b2bbb0d8..dc57607f0 100644 --- a/capio/tests/unit/server/src/client_manager.hpp +++ b/capio/tests/unit/server/src/client_manager.hpp @@ -1,32 +1,23 @@ #ifndef CAPIO_CLIENT_MANAGER_HPP #define CAPIO_CLIENT_MANAGER_HPP -#include "client-manager/client_manager.hpp" - -#include - -TEST_F(CapioServerUnitTestEnviron, testReplyToNonClient) { - ClientManager client_manager; +TEST_F(ClientManagerTestEnvironment, testReplyToNonClient) { char buffer[1024]; - EXPECT_THROW(client_manager.replyToClient(-1, 0, buffer, 0), std::runtime_error); + EXPECT_THROW(client_manager->replyToClient(-1, 0, buffer, 0), std::runtime_error); } -TEST_F(CapioServerUnitTestEnviron, testGetNumberOfConnectedClients) { - ClientManager client_manager; - EXPECT_EQ(client_manager.getConnectedPosixClients(), 0); +TEST_F(ClientManagerTestEnvironment, testGetNumberOfConnectedClients) { - client_manager.registerClient(1234); + EXPECT_EQ(client_manager->getConnectedPosixClients(), 0); - EXPECT_EQ(client_manager.getConnectedPosixClients(), 1); + client_manager->registerClient(1234); + EXPECT_EQ(client_manager->getConnectedPosixClients(), 1); - client_manager.removeClient(1234); - - EXPECT_EQ(client_manager.getConnectedPosixClients(), 0); + client_manager->removeClient(1234); + EXPECT_EQ(client_manager->getConnectedPosixClients(), 0); } -TEST_F(CapioServerUnitTestEnviron, testFailedRequestCode) { - - ClientManager client_manager; +TEST_F(ClientManagerTestEnvironment, testFailedRequestCode) { // NOTE: there is no need to delete this object as it is only attaching to the shm allocated by // client_manager. Also calling delete on this raises std::terminate as an exception is thrown @@ -39,27 +30,26 @@ TEST_F(CapioServerUnitTestEnviron, testFailedRequestCode) { sprintf(req, "123 aaaa bbbb cccc"); request_queue->write(req, CAPIO_REQ_MAX_SIZE); - EXPECT_EQ(client_manager.readNextRequest(new_req), 123); + EXPECT_EQ(client_manager->readNextRequest(new_req), 123); sprintf(req, "abc aaaa bbbb cccc"); request_queue->write(req, CAPIO_REQ_MAX_SIZE); - EXPECT_EQ(client_manager.readNextRequest(new_req), -1); + EXPECT_EQ(client_manager->readNextRequest(new_req), -1); } -TEST_F(CapioServerUnitTestEnviron, testAddAndRemoveProducedFiles) { - ClientManager client_manager; +TEST_F(ClientManagerTestEnvironment, testAddAndRemoveProducedFiles) { - client_manager.registerClient(1234, "test_app"); - client_manager.registerProducedFile(1234, "test.txt"); + client_manager->registerClient(1234, "test_app"); + client_manager->registerProducedFile(1234, "test.txt"); - EXPECT_TRUE(client_manager.isProducer(1234, "test.txt")); + EXPECT_TRUE(client_manager->isProducer(1234, "test.txt")); - client_manager.removeProducedFile(1234, "test.txt"); - EXPECT_FALSE(client_manager.isProducer(1234, "test.txt")); + client_manager->removeProducedFile(1234, "test.txt"); + EXPECT_FALSE(client_manager->isProducer(1234, "test.txt")); - client_manager.registerProducedFile(1111, "test1.txt"); - EXPECT_FALSE(client_manager.isProducer(1111, "test1.txt")); + client_manager->registerProducedFile(1111, "test1.txt"); + EXPECT_FALSE(client_manager->isProducer(1111, "test1.txt")); } #endif // CAPIO_CLIENT_MANAGER_HPP diff --git a/capio/tests/unit/server/src/main.cpp b/capio/tests/unit/server/src/main.cpp index 153b65aee..8e923269f 100644 --- a/capio/tests/unit/server/src/main.cpp +++ b/capio/tests/unit/server/src/main.cpp @@ -1,23 +1,60 @@ -#include "common/constants.hpp" - #include char *node_name; -std::string workflow_name = CAPIO_DEFAULT_WORKFLOW_NAME; #include "capiocl.hpp" #include "capiocl/engine.h" +#include "client-manager/client_manager.hpp" +#include "common/constants.hpp" +#include "storage/manager.hpp" #include "utils/capiocl_adapter.hpp" +#include "utils/location.hpp" + capiocl::engine::Engine *capio_cl_engine; const capiocl::engine::Engine &CapioCLEngine::get() { return *capio_cl_engine; } class CapioServerUnitTestEnviron : public testing::Test { protected: - void SetUp() override { capio_cl_engine = new capiocl::engine::Engine(true); } + void SetUp() override { + capio_cl_engine = new capiocl::engine::Engine(true); + node_name = new char[HOST_NAME_MAX]; + gethostname(node_name, HOST_NAME_MAX); + } void TearDown() override { delete capio_cl_engine; } }; +class ClientManagerTestEnvironment : public CapioServerUnitTestEnviron { + protected: + ClientManager *client_manager = nullptr; + void SetUp() override { + CapioServerUnitTestEnviron::SetUp(); + client_manager = new ClientManager(); + } + + void TearDown() override { + delete client_manager; + CapioServerUnitTestEnviron::TearDown(); + } +}; + +class StorageManagerTestEnvironment : public ClientManagerTestEnvironment { + protected: + StorageManager *storage_manager = nullptr; + void SetUp() override { + open_files_location(); + ClientManagerTestEnvironment::SetUp(); + storage_manager = new StorageManager(client_manager); + } + + void TearDown() override { + delete storage_manager; + ClientManagerTestEnvironment::TearDown(); + } +}; + +/// Include test sources + #include "capio_file.hpp" #include "client_manager.hpp" #include "storage_manager.hpp" \ No newline at end of file diff --git a/capio/tests/unit/server/src/storage_manager.hpp b/capio/tests/unit/server/src/storage_manager.hpp index 6cafef670..bcea9a8c0 100644 --- a/capio/tests/unit/server/src/storage_manager.hpp +++ b/capio/tests/unit/server/src/storage_manager.hpp @@ -1,11 +1,7 @@ #ifndef CAPIO_STORAGE_MANAGER_TEST_HPP #define CAPIO_STORAGE_MANAGER_TEST_HPP -#include "storage/manager.hpp" -#include "utils/location.hpp" -TEST_F(CapioServerUnitTestEnviron, testGetPaths) { - ClientManager client_manager; - StorageManager storage_manager(&client_manager); +TEST_F(StorageManagerTestEnvironment, testGetPaths) { std::vector test_file_paths = { "test1.txt", @@ -14,10 +10,10 @@ TEST_F(CapioServerUnitTestEnviron, testGetPaths) { }; for (const auto &path : test_file_paths) { - storage_manager.add(path, false, 0); + storage_manager->add(path, false, 0); } - const auto storage_paths = storage_manager.getPaths(); + const auto storage_paths = storage_manager->getPaths(); EXPECT_EQ(storage_paths.size(), test_file_paths.size()); @@ -27,86 +23,71 @@ TEST_F(CapioServerUnitTestEnviron, testGetPaths) { } } -TEST_F(CapioServerUnitTestEnviron, testExceptions) { - ClientManager client_manager; - StorageManager storage_manager(&client_manager); +TEST_F(StorageManagerTestEnvironment, testExceptions) { - EXPECT_THROW(storage_manager.get("test.txt"), std::runtime_error); - EXPECT_THROW(storage_manager.get(1234, 1234), std::runtime_error); + EXPECT_THROW(storage_manager->get("test.txt"), std::runtime_error); + EXPECT_THROW(storage_manager->get(1234, 1234), std::runtime_error); } -TEST_F(CapioServerUnitTestEnviron, testInitDirectory) { - ClientManager client_manager; - StorageManager storage_manager(&client_manager); - node_name = new char[HOST_NAME_MAX]; - gethostname(node_name, HOST_NAME_MAX); - open_files_location(); +TEST_F(StorageManagerTestEnvironment, testInitDirectory) { capio_cl_engine->setDirectory("myDirectory"); capio_cl_engine->setDirectoryFileCount("myDirectory", 10); - storage_manager.add("myDirectory", true, 0); + storage_manager->add("myDirectory", true, 0); - const auto &dir = storage_manager.get("myDirectory"); + const auto &dir = storage_manager->get("myDirectory"); EXPECT_EQ(dir.get_buf_size(), CAPIO_DEFAULT_DIR_INITIAL_SIZE); - storage_manager.updateDirectory(1, "myDirectory"); - const auto &dir1 = storage_manager.get("myDirectory"); + storage_manager->updateDirectory(1, "myDirectory"); + const auto &dir1 = storage_manager->get("myDirectory"); EXPECT_FALSE(dir1.first_write); } -TEST_F(CapioServerUnitTestEnviron, testAddDirectoryFailure) { +TEST_F(StorageManagerTestEnvironment, testAddDirectoryFailure) { char *old_capio_dir = getenv("CAPIO_DIR"); setenv("CAPIO_DIR", "/", 1); - node_name = new char[HOST_NAME_MAX]; - gethostname(node_name, HOST_NAME_MAX); open_files_location(); - ClientManager client_manager; - StorageManager storage_manager(&client_manager); - storage_manager.add("/tmp", true, 0); - EXPECT_EQ(storage_manager.addDirectory(1, "/tmp/newDirectoryFail"), 0); - EXPECT_EQ(storage_manager.addDirectory(1, "/tmp/newDirectoryFail"), 1); + + storage_manager->add("/tmp", true, 0); + EXPECT_EQ(storage_manager->addDirectory(1, "/tmp/newDirectoryFail"), 0); + EXPECT_EQ(storage_manager->addDirectory(1, "/tmp/newDirectoryFail"), 1); if (old_capio_dir != nullptr) { setenv("CAPIO_DIR", old_capio_dir, 1); } } -TEST_F(CapioServerUnitTestEnviron, testRemameFile) { - ClientManager client_manager; - StorageManager storage_manager(&client_manager); +TEST_F(StorageManagerTestEnvironment, testRemameFile) { - storage_manager.add("oldName", false, 0); - storage_manager.add("oldNameNoChange", false, 0); + storage_manager->add("oldName", false, 0); + storage_manager->add("oldNameNoChange", false, 0); - storage_manager.addFileToTid(1234, 3, "oldName", 0); - storage_manager.addFileToTid(1234, 4, "oldNameNoChange", 0); + storage_manager->addFileToTid(1234, 3, "oldName", 0); + storage_manager->addFileToTid(1234, 4, "oldNameNoChange", 0); - storage_manager.add("oldNameNoChange", false, 0); - storage_manager.rename("oldName", "newName"); + storage_manager->add("oldNameNoChange", false, 0); + storage_manager->rename("oldName", "newName"); - EXPECT_THROW(storage_manager.get("oldName"), std::runtime_error); - EXPECT_NO_THROW(storage_manager.get("oldNameNoChange")); + EXPECT_THROW(storage_manager->get("oldName"), std::runtime_error); + EXPECT_NO_THROW(storage_manager->get("oldNameNoChange")); } -TEST_F(CapioServerUnitTestEnviron, testNumberOfOpensAfterClone) { - - ClientManager client_manager; - StorageManager storage_manager(&client_manager); +TEST_F(StorageManagerTestEnvironment, testNumberOfOpensAfterClone) { - storage_manager.add("myFile", false, 0); - storage_manager.addFileToTid(1234, 3, "myFile", 0); - storage_manager.clone(1234, 5678); + storage_manager->add("myFile", false, 0); + storage_manager->addFileToTid(1234, 3, "myFile", 0); + storage_manager->clone(1234, 5678); - EXPECT_FALSE(storage_manager.get("myFile").is_deletable()); + EXPECT_FALSE(storage_manager->get("myFile").is_deletable()); - storage_manager.removeFromTid(1234, 3); - EXPECT_FALSE(storage_manager.get("myFile").is_deletable()); + storage_manager->removeFromTid(1234, 3); + EXPECT_FALSE(storage_manager->get("myFile").is_deletable()); - storage_manager.removeFromTid(5678, 3); + storage_manager->removeFromTid(5678, 3); - EXPECT_TRUE(storage_manager.get("myFile").is_deletable()); + EXPECT_TRUE(storage_manager->get("myFile").is_deletable()); } #endif // CAPIO_STORAGE_MANAGER_TEST_HPP From 4fca5d06cf5673349402788c6231c7960a012e2f Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 19 Feb 2026 13:22:30 +0000 Subject: [PATCH 13/19] Extended test suite --- capio/tests/unit/server/src/main.cpp | 2 +- capio/tests/unit/server/src/storage_manager.hpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/capio/tests/unit/server/src/main.cpp b/capio/tests/unit/server/src/main.cpp index 8e923269f..7962d83d9 100644 --- a/capio/tests/unit/server/src/main.cpp +++ b/capio/tests/unit/server/src/main.cpp @@ -19,6 +19,7 @@ class CapioServerUnitTestEnviron : public testing::Test { capio_cl_engine = new capiocl::engine::Engine(true); node_name = new char[HOST_NAME_MAX]; gethostname(node_name, HOST_NAME_MAX); + open_files_location(); } void TearDown() override { delete capio_cl_engine; } @@ -42,7 +43,6 @@ class StorageManagerTestEnvironment : public ClientManagerTestEnvironment { protected: StorageManager *storage_manager = nullptr; void SetUp() override { - open_files_location(); ClientManagerTestEnvironment::SetUp(); storage_manager = new StorageManager(client_manager); } diff --git a/capio/tests/unit/server/src/storage_manager.hpp b/capio/tests/unit/server/src/storage_manager.hpp index bcea9a8c0..8faf0830f 100644 --- a/capio/tests/unit/server/src/storage_manager.hpp +++ b/capio/tests/unit/server/src/storage_manager.hpp @@ -74,6 +74,21 @@ TEST_F(StorageManagerTestEnvironment, testRemameFile) { EXPECT_NO_THROW(storage_manager->get("oldNameNoChange")); } +TEST_F(StorageManagerTestEnvironment, testNumberOfOpensAndCloses) { + + storage_manager->add("myFile", false, 0); + storage_manager->addFileToTid(1234, 3, "myFile", 0); + storage_manager->addFileToTid(1234, 4, "myFile", 0); + + EXPECT_FALSE(storage_manager->get("myFile").is_deletable()); + + storage_manager->get("myFile").close(); + EXPECT_FALSE(storage_manager->get("myFile").is_deletable()); + + storage_manager->get("myFile").close(); + EXPECT_TRUE(storage_manager->get("myFile").is_deletable()); +} + TEST_F(StorageManagerTestEnvironment, testNumberOfOpensAfterClone) { storage_manager->add("myFile", false, 0); @@ -86,6 +101,7 @@ TEST_F(StorageManagerTestEnvironment, testNumberOfOpensAfterClone) { EXPECT_FALSE(storage_manager->get("myFile").is_deletable()); storage_manager->removeFromTid(5678, 3); + storage_manager->get("myFile").close(); EXPECT_TRUE(storage_manager->get("myFile").is_deletable()); } From ee8cc2a10534ec6f7c8d9293af6412192db69f0f Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 19 Feb 2026 13:39:46 +0000 Subject: [PATCH 14/19] cleanup --- capio/tests/unit/server/src/main.cpp | 39 ++++++++++++---------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/capio/tests/unit/server/src/main.cpp b/capio/tests/unit/server/src/main.cpp index 7962d83d9..3ce91a1cf 100644 --- a/capio/tests/unit/server/src/main.cpp +++ b/capio/tests/unit/server/src/main.cpp @@ -13,30 +13,12 @@ char *node_name; capiocl::engine::Engine *capio_cl_engine; const capiocl::engine::Engine &CapioCLEngine::get() { return *capio_cl_engine; } -class CapioServerUnitTestEnviron : public testing::Test { - protected: - void SetUp() override { - capio_cl_engine = new capiocl::engine::Engine(true); - node_name = new char[HOST_NAME_MAX]; - gethostname(node_name, HOST_NAME_MAX); - open_files_location(); - } - - void TearDown() override { delete capio_cl_engine; } -}; - -class ClientManagerTestEnvironment : public CapioServerUnitTestEnviron { +class ClientManagerTestEnvironment : public testing::Test { protected: ClientManager *client_manager = nullptr; - void SetUp() override { - CapioServerUnitTestEnviron::SetUp(); - client_manager = new ClientManager(); - } + void SetUp() override { client_manager = new ClientManager(); } - void TearDown() override { - delete client_manager; - CapioServerUnitTestEnviron::TearDown(); - } + void TearDown() override { delete client_manager; } }; class StorageManagerTestEnvironment : public ClientManagerTestEnvironment { @@ -57,4 +39,17 @@ class StorageManagerTestEnvironment : public ClientManagerTestEnvironment { #include "capio_file.hpp" #include "client_manager.hpp" -#include "storage_manager.hpp" \ No newline at end of file +#include "storage_manager.hpp" + +int main(int argc, char **argv, char **envp) { + testing::InitGoogleTest(&argc, argv); + + capio_cl_engine = new capiocl::engine::Engine(true); + node_name = new char[HOST_NAME_MAX]; + gethostname(node_name, HOST_NAME_MAX); + open_files_location(); + + const int test_result = RUN_ALL_TESTS(); + delete capio_cl_engine; + return test_result; +} \ No newline at end of file From 385bc00ba9bdf81424a62c225c9fa7185f51c223 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 19 Feb 2026 13:49:56 +0000 Subject: [PATCH 15/19] cleanup --- .../tests/unit/server/src/client_manager.hpp | 8 ++--- capio/tests/unit/server/src/main.cpp | 36 +++++++++---------- .../tests/unit/server/src/storage_manager.hpp | 14 ++++---- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/capio/tests/unit/server/src/client_manager.hpp b/capio/tests/unit/server/src/client_manager.hpp index dc57607f0..5e62f2d23 100644 --- a/capio/tests/unit/server/src/client_manager.hpp +++ b/capio/tests/unit/server/src/client_manager.hpp @@ -1,12 +1,12 @@ #ifndef CAPIO_CLIENT_MANAGER_HPP #define CAPIO_CLIENT_MANAGER_HPP -TEST_F(ClientManagerTestEnvironment, testReplyToNonClient) { +TEST(ClientManagerTestEnvironment, testReplyToNonClient) { char buffer[1024]; EXPECT_THROW(client_manager->replyToClient(-1, 0, buffer, 0), std::runtime_error); } -TEST_F(ClientManagerTestEnvironment, testGetNumberOfConnectedClients) { +TEST(ClientManagerTestEnvironment, testGetNumberOfConnectedClients) { EXPECT_EQ(client_manager->getConnectedPosixClients(), 0); @@ -17,7 +17,7 @@ TEST_F(ClientManagerTestEnvironment, testGetNumberOfConnectedClients) { EXPECT_EQ(client_manager->getConnectedPosixClients(), 0); } -TEST_F(ClientManagerTestEnvironment, testFailedRequestCode) { +TEST(ClientManagerTestEnvironment, testFailedRequestCode) { // NOTE: there is no need to delete this object as it is only attaching to the shm allocated by // client_manager. Also calling delete on this raises std::terminate as an exception is thrown @@ -38,7 +38,7 @@ TEST_F(ClientManagerTestEnvironment, testFailedRequestCode) { EXPECT_EQ(client_manager->readNextRequest(new_req), -1); } -TEST_F(ClientManagerTestEnvironment, testAddAndRemoveProducedFiles) { +TEST(ClientManagerTestEnvironment, testAddAndRemoveProducedFiles) { client_manager->registerClient(1234, "test_app"); client_manager->registerProducedFile(1234, "test.txt"); diff --git a/capio/tests/unit/server/src/main.cpp b/capio/tests/unit/server/src/main.cpp index 3ce91a1cf..60ae02f56 100644 --- a/capio/tests/unit/server/src/main.cpp +++ b/capio/tests/unit/server/src/main.cpp @@ -11,27 +11,29 @@ char *node_name; #include "utils/location.hpp" capiocl::engine::Engine *capio_cl_engine; -const capiocl::engine::Engine &CapioCLEngine::get() { return *capio_cl_engine; } +StorageManager *storage_manager = nullptr; +ClientManager *client_manager = nullptr; -class ClientManagerTestEnvironment : public testing::Test { - protected: - ClientManager *client_manager = nullptr; - void SetUp() override { client_manager = new ClientManager(); } +const capiocl::engine::Engine &CapioCLEngine::get() { return *capio_cl_engine; } - void TearDown() override { delete client_manager; } -}; +class ServerUnitTestEnvironment : public testing::Environment { + public: + explicit ServerUnitTestEnvironment() = default; -class StorageManagerTestEnvironment : public ClientManagerTestEnvironment { - protected: - StorageManager *storage_manager = nullptr; void SetUp() override { - ClientManagerTestEnvironment::SetUp(); + capio_cl_engine = new capiocl::engine::Engine(true); + node_name = new char[HOST_NAME_MAX]; + gethostname(node_name, HOST_NAME_MAX); + open_files_location(); + + client_manager = new ClientManager(); storage_manager = new StorageManager(client_manager); } void TearDown() override { delete storage_manager; - ClientManagerTestEnvironment::TearDown(); + delete client_manager; + delete capio_cl_engine; } }; @@ -44,12 +46,6 @@ class StorageManagerTestEnvironment : public ClientManagerTestEnvironment { int main(int argc, char **argv, char **envp) { testing::InitGoogleTest(&argc, argv); - capio_cl_engine = new capiocl::engine::Engine(true); - node_name = new char[HOST_NAME_MAX]; - gethostname(node_name, HOST_NAME_MAX); - open_files_location(); - - const int test_result = RUN_ALL_TESTS(); - delete capio_cl_engine; - return test_result; + testing::AddGlobalTestEnvironment(new ServerUnitTestEnvironment()); + return RUN_ALL_TESTS(); } \ No newline at end of file diff --git a/capio/tests/unit/server/src/storage_manager.hpp b/capio/tests/unit/server/src/storage_manager.hpp index 8faf0830f..266d64b23 100644 --- a/capio/tests/unit/server/src/storage_manager.hpp +++ b/capio/tests/unit/server/src/storage_manager.hpp @@ -1,7 +1,7 @@ #ifndef CAPIO_STORAGE_MANAGER_TEST_HPP #define CAPIO_STORAGE_MANAGER_TEST_HPP -TEST_F(StorageManagerTestEnvironment, testGetPaths) { +TEST(StorageManagerTestEnvironment, testGetPaths) { std::vector test_file_paths = { "test1.txt", @@ -23,13 +23,13 @@ TEST_F(StorageManagerTestEnvironment, testGetPaths) { } } -TEST_F(StorageManagerTestEnvironment, testExceptions) { +TEST(StorageManagerTestEnvironment, testExceptions) { EXPECT_THROW(storage_manager->get("test.txt"), std::runtime_error); EXPECT_THROW(storage_manager->get(1234, 1234), std::runtime_error); } -TEST_F(StorageManagerTestEnvironment, testInitDirectory) { +TEST(StorageManagerTestEnvironment, testInitDirectory) { capio_cl_engine->setDirectory("myDirectory"); capio_cl_engine->setDirectoryFileCount("myDirectory", 10); @@ -46,7 +46,7 @@ TEST_F(StorageManagerTestEnvironment, testInitDirectory) { EXPECT_FALSE(dir1.first_write); } -TEST_F(StorageManagerTestEnvironment, testAddDirectoryFailure) { +TEST(StorageManagerTestEnvironment, testAddDirectoryFailure) { char *old_capio_dir = getenv("CAPIO_DIR"); setenv("CAPIO_DIR", "/", 1); open_files_location(); @@ -59,7 +59,7 @@ TEST_F(StorageManagerTestEnvironment, testAddDirectoryFailure) { } } -TEST_F(StorageManagerTestEnvironment, testRemameFile) { +TEST(StorageManagerTestEnvironment, testRemameFile) { storage_manager->add("oldName", false, 0); storage_manager->add("oldNameNoChange", false, 0); @@ -74,7 +74,7 @@ TEST_F(StorageManagerTestEnvironment, testRemameFile) { EXPECT_NO_THROW(storage_manager->get("oldNameNoChange")); } -TEST_F(StorageManagerTestEnvironment, testNumberOfOpensAndCloses) { +TEST(StorageManagerTestEnvironment, testNumberOfOpensAndCloses) { storage_manager->add("myFile", false, 0); storage_manager->addFileToTid(1234, 3, "myFile", 0); @@ -89,7 +89,7 @@ TEST_F(StorageManagerTestEnvironment, testNumberOfOpensAndCloses) { EXPECT_TRUE(storage_manager->get("myFile").is_deletable()); } -TEST_F(StorageManagerTestEnvironment, testNumberOfOpensAfterClone) { +TEST(StorageManagerTestEnvironment, testNumberOfOpensAfterClone) { storage_manager->add("myFile", false, 0); storage_manager->addFileToTid(1234, 3, "myFile", 0); From 7df1a476ad933c0eac5a8e06b3916797eb752715 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 19 Feb 2026 13:56:58 +0000 Subject: [PATCH 16/19] reverted changes from capio_server --- capio/server/capio_server.cpp | 2 +- capio/server/include/storage/manager.hpp | 9 +-------- capio/server/src/storage_manager.cpp | 4 ++-- capio/tests/unit/server/src/client_manager.hpp | 8 +++++--- capio/tests/unit/server/src/main.cpp | 4 ++-- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/capio/server/capio_server.cpp b/capio/server/capio_server.cpp index c60d2d522..c0c29afa8 100644 --- a/capio/server/capio_server.cpp +++ b/capio/server/capio_server.cpp @@ -296,8 +296,8 @@ int main(int argc, char **argv) { open_files_location(); shm_canary = new CapioShmCanary(capio_cl_engine->getWorkflowName()); + storage_manager = new StorageManager(); client_manager = new ClientManager(); - storage_manager = new StorageManager(client_manager); std::thread server_thread(capio_server, std::ref(internal_server_sem)); LOG("capio_server thread started"); diff --git a/capio/server/include/storage/manager.hpp b/capio/server/include/storage/manager.hpp index 04bb8b239..069c99132 100644 --- a/capio/server/include/storage/manager.hpp +++ b/capio/server/include/storage/manager.hpp @@ -7,8 +7,6 @@ #include "utils/capio_file.hpp" #include "utils/shared_mutex.hpp" -#include "client-manager/client_manager.hpp" - #include #include @@ -22,10 +20,6 @@ * and their respective offsets. */ class StorageManager { - - ///@brief reference to ClientManager to avoid using the global instanced variable - ClientManager *_client_manager; - /** * @brief Mutex to protect access to _storage internal data structure. */ @@ -115,9 +109,8 @@ class StorageManager { * @brief Constructs a new StorageService instance. * * Initializes the server and logs its completion. - * @param client_manager Reference to ClientManager instance */ - StorageManager(ClientManager *client_manager); + StorageManager(); /** * @brief Destroys the StorageService instance. diff --git a/capio/server/src/storage_manager.cpp b/capio/server/src/storage_manager.cpp index c02dca051..4981d4deb 100644 --- a/capio/server/src/storage_manager.cpp +++ b/capio/server/src/storage_manager.cpp @@ -60,12 +60,12 @@ void StorageManager::addDirectoryEntry(const pid_t tid, const std::filesystem::p c_file.insert_sector(base_offset, data_size); ++c_file.n_files; - _client_manager->registerProducedFile(tid, dir); + client_manager->registerProducedFile(tid, dir); if (c_file.n_files == c_file.n_files_expected) { c_file.set_complete(); } } -StorageManager::StorageManager(ClientManager *client_manager) : _client_manager(client_manager) { +StorageManager::StorageManager() { server_println(CAPIO_LOG_SERVER_CLI_LEVEL_INFO, "StorageManager initialization completed."); } diff --git a/capio/tests/unit/server/src/client_manager.hpp b/capio/tests/unit/server/src/client_manager.hpp index 5e62f2d23..1f5a2fa5c 100644 --- a/capio/tests/unit/server/src/client_manager.hpp +++ b/capio/tests/unit/server/src/client_manager.hpp @@ -27,10 +27,12 @@ TEST(ClientManagerTestEnvironment, testFailedRequestCode) { new CircularBuffer(SHM_COMM_CHAN_NAME, CAPIO_REQ_BUFF_CNT, CAPIO_REQ_MAX_SIZE); char req[CAPIO_REQ_MAX_SIZE], new_req[CAPIO_REQ_MAX_SIZE]; - sprintf(req, "123 aaaa bbbb cccc"); + constexpr int TEST_REQ_CODE = 123; + sprintf(req, "%04d aaaa bbbb cccc", TEST_REQ_CODE); request_queue->write(req, CAPIO_REQ_MAX_SIZE); - - EXPECT_EQ(client_manager->readNextRequest(new_req), 123); + const auto return_code = client_manager->readNextRequest(new_req); + std::cout << new_req << std::endl; + EXPECT_EQ(return_code, TEST_REQ_CODE); sprintf(req, "abc aaaa bbbb cccc"); request_queue->write(req, CAPIO_REQ_MAX_SIZE); diff --git a/capio/tests/unit/server/src/main.cpp b/capio/tests/unit/server/src/main.cpp index 60ae02f56..b9e73ec58 100644 --- a/capio/tests/unit/server/src/main.cpp +++ b/capio/tests/unit/server/src/main.cpp @@ -21,13 +21,13 @@ class ServerUnitTestEnvironment : public testing::Environment { explicit ServerUnitTestEnvironment() = default; void SetUp() override { - capio_cl_engine = new capiocl::engine::Engine(true); + capio_cl_engine = new capiocl::engine::Engine(false); node_name = new char[HOST_NAME_MAX]; gethostname(node_name, HOST_NAME_MAX); open_files_location(); client_manager = new ClientManager(); - storage_manager = new StorageManager(client_manager); + storage_manager = new StorageManager(); } void TearDown() override { From f152c804aef0e8d9b920aa1d56f135d071cf621d Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 21 Feb 2026 17:02:33 +0000 Subject: [PATCH 17/19] Fixed issue in running docker tests --- .github/workflows/ci-tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-tests.yaml b/.github/workflows/ci-tests.yaml index 6862c58a8..392cda88e 100644 --- a/.github/workflows/ci-tests.yaml +++ b/.github/workflows/ci-tests.yaml @@ -67,7 +67,7 @@ jobs: --env LD_PRELOAD=libcapio_posix.so \ --name capio-docker \ alphaunito/capio:latest \ - capio_server_unit_tests \ + capio_syscall_unit_tests \ --gtest_break_on_failure \ --gtest_print_time=1 From f042a90d3a857429f562f49fe0b104fa609e1ae2 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 21 Feb 2026 17:07:52 +0000 Subject: [PATCH 18/19] This commit disables the capio_syscall_unit_tests within the docker CI as there is the requirement to update the CI/CD for them --- .github/workflows/ci-tests.yaml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci-tests.yaml b/.github/workflows/ci-tests.yaml index 392cda88e..1c9008777 100644 --- a/.github/workflows/ci-tests.yaml +++ b/.github/workflows/ci-tests.yaml @@ -60,16 +60,16 @@ jobs: --gtest_break_on_failure \ --gtest_print_time=1 - echo "Run CAPIO syscall Unit tests" - docker run --rm \ - --env CAPIO_DIR=/tmp \ - --env CAPIO_LOG_LEVEL=-1 \ - --env LD_PRELOAD=libcapio_posix.so \ - --name capio-docker \ - alphaunito/capio:latest \ - capio_syscall_unit_tests \ - --gtest_break_on_failure \ - --gtest_print_time=1 + #echo "Run CAPIO syscall Unit tests" + #docker run --rm \ + # --env CAPIO_DIR=/tmp \ + # --env CAPIO_LOG_LEVEL=-1 \ + # --env LD_PRELOAD=libcapio_posix.so \ + # --name capio-docker \ + # alphaunito/capio:latest \ + # capio_syscall_unit_tests \ + # --gtest_break_on_failure \ + # --gtest_print_time=1 echo "Run CAPIO integration tests" docker run --rm \ From b08ec2eddc585eb7bf3fca122c79a7c21afbb2fe Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 21 Feb 2026 17:16:11 +0000 Subject: [PATCH 19/19] Fixed docker CI/CD tests --- .github/workflows/ci-tests.yaml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci-tests.yaml b/.github/workflows/ci-tests.yaml index 1c9008777..ee9e12991 100644 --- a/.github/workflows/ci-tests.yaml +++ b/.github/workflows/ci-tests.yaml @@ -60,16 +60,19 @@ jobs: --gtest_break_on_failure \ --gtest_print_time=1 - #echo "Run CAPIO syscall Unit tests" - #docker run --rm \ - # --env CAPIO_DIR=/tmp \ - # --env CAPIO_LOG_LEVEL=-1 \ - # --env LD_PRELOAD=libcapio_posix.so \ - # --name capio-docker \ - # alphaunito/capio:latest \ - # capio_syscall_unit_tests \ - # --gtest_break_on_failure \ - # --gtest_print_time=1 + echo "Run CAPIO syscall Unit tests" + docker run --rm \ + --env CAPIO_DIR=/tmp \ + --env CAPIO_LOG_LEVEL=-1 \ + --env LD_PRELOAD=libcapio_posix.so \ + --name capio-docker \ + alphaunito/capio:latest \ + jq -n --arg pwd $(pwd) \ + '{name: "CAPIO", IO_Graph: [], exclude: [$pwd + "/aNonExistingFile", $pwd, $pwd + "/"]}' \ + > test_config.json && \ + capio_syscall_unit_tests \ + --gtest_break_on_failure \ + --gtest_print_time=1 echo "Run CAPIO integration tests" docker run --rm \