Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some common libraries improvements #589

Merged
merged 3 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 2 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ if(ENABLE_LOGCOLLECTOR OR ENABLE_INVENTORY)
add_subdirectory(common)
else()
add_subdirectory(common/config)
add_subdirectory(common/data_provider)
add_subdirectory(common/file_helper)
add_subdirectory(common/logger)
add_subdirectory(common/pal)
add_subdirectory(common/utils)
add_subdirectory(common/data_provider)
add_subdirectory(common/networkHelper)
add_subdirectory(common/file_helper)
endif()

add_subdirectory(modules)
Expand Down
24 changes: 13 additions & 11 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
add_subdirectory(binaries_op)
add_subdirectory(byteArrayHelper)
add_subdirectory(cmdHelper)
add_subdirectory(config)
add_subdirectory(data_provider)
add_subdirectory(dbsync)
add_subdirectory(error_messages)
if(NOT MSVC)
add_subdirectory(file_op)
endif()
add_subdirectory(encodingHelper)
add_subdirectory(file_helper)
add_subdirectory(globHelper)
add_subdirectory(hashHelper)
add_subdirectory(jsonHelper)
add_subdirectory(linuxHelper)
add_subdirectory(logger)
add_subdirectory(mem_op)
add_subdirectory(mapWrapper)
add_subdirectory(networkHelper)
add_subdirectory(pal)
add_subdirectory(privsep_op)
add_subdirectory(pthreads_op)
add_subdirectory(randombytes)
add_subdirectory(regex_op)
add_subdirectory(pipelineHelper)
add_subdirectory(registryHelper)
add_subdirectory(sqliteWrapper)
add_subdirectory(time_op)
add_subdirectory(stringHelper)
add_subdirectory(threadDispatcher)
add_subdirectory(timeHelper)
add_subdirectory(utils)
add_subdirectory(windowsHelper)

if(BUILD_TESTS)
enable_testing()
Expand Down
15 changes: 0 additions & 15 deletions src/common/binaries_op/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +0,0 @@
add_library(binaries_op STATIC src/binaries_op.c)

get_filename_component(COMMON_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../ ABSOLUTE)
target_include_directories(binaries_op PUBLIC
include
${COMMON_FOLDER}/error_messages/include
${COMMON_FOLDER}/file_op/include
${COMMON_FOLDER}/pal/include
${COMMON_FOLDER}/utils/include)

target_link_libraries(binaries_op
utils
Logger
pal
time_op)
1 change: 0 additions & 1 deletion src/common/binaries_op/src/binaries_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <stdlib.h>
#include "os_err.h"
#include "os_macros.h"
#include "pal.h"

#ifndef WIN32
#include "file_op.h"
Expand Down
14 changes: 12 additions & 2 deletions src/common/byteArrayHelper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
cmake_minimum_required(VERSION 3.12.4)
cmake_minimum_required(VERSION 3.22)

if(UNIT_TEST)
project(byte_array_helper)

include(../../cmake/CommonSettings.cmake)
set_common_settings()

add_library(byte_array_helper INTERFACE)

target_include_directories(byte_array_helper INTERFACE include)

if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
85 changes: 11 additions & 74 deletions src/common/byteArrayHelper/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,84 +1,21 @@
cmake_minimum_required(VERSION 3.12.4)

project(utils_unit_test)

file(GLOB UTIL_CXX_UNITTEST_WINDOWS_SRC)
find_package(GTest CONFIG REQUIRED)

file(GLOB UTIL_CXX_UNITTEST_COMMON_SRC
"byteArrayHelper_test.cpp"
"main.cpp"
)

file(GLOB UTIL_CXX_UNITTEST_LINUX_SRC)

file(COPY input_files DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

link_directories(${SRC_FOLDER}/external/googletest/lib)
link_directories(${SRC_FOLDER}/external/libarchive/.libs/)

if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
add_definitions(-DPROMISE_TYPE=PromiseType::SLEEP)
else()
add_definitions(-DPROMISE_TYPE=PromiseType::NORMAL)
endif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_executable(utils_unit_test
${UTIL_CXX_UNITTEST_COMMON_SRC}
${UTIL_CXX_UNITTEST_WINDOWS_SRC}
${UTIL_CXX_UNITTEST_CPP17_SRC}
)
add_definitions(-DWIN32=1
-D_WIN32_WINNT=0x600)
target_link_libraries(utils_unit_test
debug gtestd
debug gmockd
optimized gtest
optimized gmock
pthread
crypto
ssl
-static-libgcc
ws2_32
crypt32
)
else()
add_executable(byte_array_helper_tests
${UTIL_CXX_UNITTEST_COMMON_SRC}
)

if (APPLE)
add_executable(utils_unit_test
${UTIL_CXX_UNITTEST_COMMON_SRC}
${UTIL_CXX_UNITTEST_CPP17_SRC}
)
else()
add_executable(utils_unit_test
${UTIL_CXX_UNITTEST_COMMON_SRC}
${UTIL_CXX_UNITTEST_LINUX_SRC}
${UTIL_CXX_UNITTEST_CPP17_SRC}
)
endif(APPLE)
include(../../../cmake/ConfigureTarget.cmake)
configure_target(byte_array_helper_tests)

target_link_libraries(utils_unit_test
debug gtestd
debug gmockd
optimized gtest
optimized gmock
rocksdb
crypto
dl
pthread
rt
lzma
z
minizip
archive
)
endif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_include_directories(byte_array_helper_tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../include
)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_link_libraries(utils_unit_test -fprofile-arcs)
else()
target_link_libraries(utils_unit_test gcov)
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_link_libraries(byte_array_helper_tests PRIVATE byte_array_helper GTest::gtest)

add_test(NAME utils_unit_test
COMMAND utils_unit_test)
add_test(NAME byteArrayHelperTests COMMAND byte_array_helper_tests)
10 changes: 5 additions & 5 deletions src/common/byteArrayHelper/tests/byteArrayHelper_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ void ByteArrayHelperTest::SetUp() {};

void ByteArrayHelperTest::TearDown() {};

constexpr uint8_t bufferBE[] = {0x12, 0x34, 0x56, 0x78};
constexpr uint8_t bufferLE[] = {0x78, 0x56, 0x34, 0x12};
constexpr int32_t result {305419896};
constexpr uint8_t BUFFER_BE[] = {0x12, 0x34, 0x56, 0x78};
constexpr uint8_t BUFFER_LE[] = {0x78, 0x56, 0x34, 0x12};
constexpr int32_t RESULT {305419896};

TEST_F(ByteArrayHelperTest, toInt32BE)
{
EXPECT_EQ(result, Utils::toInt32BE(bufferBE));
EXPECT_EQ(RESULT, Utils::toInt32BE(BUFFER_BE));
}

TEST_F(ByteArrayHelperTest, toInt32LE)
{
EXPECT_EQ(result, Utils::toInt32LE(bufferLE));
EXPECT_EQ(RESULT, Utils::toInt32LE(BUFFER_LE));
}
16 changes: 14 additions & 2 deletions src/common/cmdHelper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
cmake_minimum_required(VERSION 3.12.4)
cmake_minimum_required(VERSION 3.22)

if(UNIT_TEST)
project(cmd_helper)

include(../../cmake/CommonSettings.cmake)
set_common_settings()

add_library(cmd_helper INTERFACE)

target_include_directories(cmd_helper INTERFACE include)

target_link_libraries(cmd_helper INTERFACE pal)

if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
2 changes: 1 addition & 1 deletion src/common/cmdHelper/include/cmdHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <cstdio>
#include <memory>
#include <vector>
#include "pal.h"
#include <pal.h>

#ifdef __GNUC__
#pragma GCC diagnostic push
Expand Down
85 changes: 11 additions & 74 deletions src/common/cmdHelper/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,84 +1,21 @@
cmake_minimum_required(VERSION 3.12.4)

project(utils_unit_test)

file(GLOB UTIL_CXX_UNITTEST_WINDOWS_SRC)
find_package(GTest CONFIG REQUIRED)

file(GLOB UTIL_CXX_UNITTEST_COMMON_SRC
"cmdHelper_test.cpp"
"main.cpp"
)

file(GLOB UTIL_CXX_UNITTEST_LINUX_SRC)

file(COPY input_files DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

link_directories(${SRC_FOLDER}/external/googletest/lib)
link_directories(${SRC_FOLDER}/external/libarchive/.libs/)

if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
add_definitions(-DPROMISE_TYPE=PromiseType::SLEEP)
else()
add_definitions(-DPROMISE_TYPE=PromiseType::NORMAL)
endif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_executable(utils_unit_test
${UTIL_CXX_UNITTEST_COMMON_SRC}
${UTIL_CXX_UNITTEST_WINDOWS_SRC}
${UTIL_CXX_UNITTEST_CPP17_SRC}
)
add_definitions(-DWIN32=1
-D_WIN32_WINNT=0x600)
target_link_libraries(utils_unit_test
debug gtestd
debug gmockd
optimized gtest
optimized gmock
pthread
crypto
ssl
-static-libgcc
ws2_32
crypt32
)
else()
add_executable(cmd_helper_tests
${UTIL_CXX_UNITTEST_COMMON_SRC}
)

if (APPLE)
add_executable(utils_unit_test
${UTIL_CXX_UNITTEST_COMMON_SRC}
${UTIL_CXX_UNITTEST_CPP17_SRC}
)
else()
add_executable(utils_unit_test
${UTIL_CXX_UNITTEST_COMMON_SRC}
${UTIL_CXX_UNITTEST_LINUX_SRC}
${UTIL_CXX_UNITTEST_CPP17_SRC}
)
endif(APPLE)
include(../../../cmake/ConfigureTarget.cmake)
configure_target(cmd_helper_tests)

target_link_libraries(utils_unit_test
debug gtestd
debug gmockd
optimized gtest
optimized gmock
rocksdb
crypto
dl
pthread
rt
lzma
z
minizip
archive
)
endif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_include_directories(cmd_helper_tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../include
)

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_link_libraries(utils_unit_test -fprofile-arcs)
else()
target_link_libraries(utils_unit_test gcov)
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_link_libraries(cmd_helper_tests PRIVATE cmd_helper GTest::gtest)

add_test(NAME utils_unit_test
COMMAND utils_unit_test)
add_test(NAME cmdHelperTests COMMAND cmd_helper_tests)
3 changes: 3 additions & 0 deletions src/common/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.22)

project(Config)

include(../../cmake/CommonSettings.cmake)
set_common_settings()

add_library(Config INTERFACE)

include(../../cmake/config.cmake)
Expand Down
Loading