From c64c99fbb4c3935dd18cae04b569fcb61f2e9cfe Mon Sep 17 00:00:00 2001 From: Katja Vornberger Date: Mon, 12 Feb 2024 21:12:02 +0100 Subject: [PATCH 01/11] Do not register request starting with "japi_": Use wrapper function instead of init variable --- include/japi.h | 1 - src/japi.c | 36 ++++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/include/japi.h b/include/japi.h index f30bf8f..4016106 100644 --- a/include/japi.h +++ b/include/japi.h @@ -60,7 +60,6 @@ typedef struct __japi_context { struct __japi_client *clients; /*!< Pointer to the JAPI client context */ bool include_args_in_response; /*!< Flag to include request args in response */ bool shutdown; /*!< Flag to shutdown the JAPI server */ - bool init; /*!< Flag to mark finished initialization */ } japi_context; /*! diff --git a/src/japi.c b/src/japi.c index 57af2e4..d4437c2 100644 --- a/src/japi.c +++ b/src/japi.c @@ -236,8 +236,9 @@ int japi_destroy(japi_context *ctx) return 0; } -int japi_register_request(japi_context *ctx, const char *req_name, - japi_req_handler req_handler) +static int japi_register_request_internal(japi_context *ctx, const char *req_name, + japi_req_handler req_handler, + bool allow_internal_req_name) { japi_request *req; char *bad_req_name = "japi_"; @@ -265,9 +266,11 @@ int japi_register_request(japi_context *ctx, const char *req_name, return -4; } - if (ctx->init && strncmp(req_name, bad_req_name, strlen(bad_req_name)) == 0) { - fprintf(stderr, "ERROR: Request name is not allowed.\n"); - return -6; + if (!allow_internal_req_name) { + if (strncmp(req_name, bad_req_name, strlen(bad_req_name)) == 0) { + fprintf(stderr, "ERROR: Request name is not allowed.\n"); + return -6; + } } req = (japi_request *)malloc(sizeof(japi_request)); @@ -285,6 +288,12 @@ int japi_register_request(japi_context *ctx, const char *req_name, return 0; } +int japi_register_request(japi_context *ctx, const char *req_name, + japi_req_handler req_handler) +{ + return japi_register_request_internal(ctx, req_name, req_handler, false); +} + japi_context *japi_init(void *userptr) { japi_context *ctx; @@ -295,7 +304,6 @@ japi_context *japi_init(void *userptr) return NULL; } - ctx->init = false; ctx->userptr = userptr; ctx->requests = NULL; ctx->push_services = NULL; @@ -315,16 +323,16 @@ japi_context *japi_init(void *userptr) signal(SIGPIPE, SIG_IGN); /* Register the default fallback handler */ - japi_register_request(ctx, "japi_request_not_found_handler", - &japi_request_not_found_handler); + japi_register_request_internal(ctx, "japi_request_not_found_handler", + &japi_request_not_found_handler, true); /* Register subscribe/unsubscribe service function */ - japi_register_request(ctx, "japi_pushsrv_subscribe", &japi_pushsrv_subscribe); - japi_register_request(ctx, "japi_pushsrv_unsubscribe", &japi_pushsrv_unsubscribe); + japi_register_request_internal(ctx, "japi_pushsrv_subscribe", + &japi_pushsrv_subscribe, true); + japi_register_request_internal(ctx, "japi_pushsrv_unsubscribe", + &japi_pushsrv_unsubscribe, true); /* Register list_push_service function */ - japi_register_request(ctx, "japi_pushsrv_list", &japi_pushsrv_list); - japi_register_request(ctx, "japi_cmd_list", &japi_cmd_list); - - ctx->init = true; + japi_register_request_internal(ctx, "japi_pushsrv_list", &japi_pushsrv_list, true); + japi_register_request_internal(ctx, "japi_cmd_list", &japi_cmd_list, true); return ctx; } From 17381b372735d7be779f7a8233d28605b0d7cda3 Mon Sep 17 00:00:00 2001 From: vornkat-iis <137415805+vornkat-iis@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:36:29 +0000 Subject: [PATCH 02/11] Temporary fix: continur using Node16 for Centos7 container --- .github/workflows/package.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 79b5a5a..d9819a5 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -7,6 +7,9 @@ on: jobs: package: runs-on: ubuntu-latest + env: + ACTIONS_RUNNER_FORCE_ACTIONS_NODE_VERSION: node16 + ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true container: image: ghcr.io/fraunhofer-iis/libjapi_ci credentials: From 90f3f5dfbf7d34df605d8174202cac989d8ef820 Mon Sep 17 00:00:00 2001 From: vornkat-iis <137415805+vornkat-iis@users.noreply.github.com> Date: Mon, 15 Jul 2024 18:15:18 +0200 Subject: [PATCH 03/11] 45 google testframework not optional (#128) Remove googletest as a submodule but download it if required from github --- .gitmodules | 3 --- CMakeLists.txt | 27 +++++++++++++++++++++------ README.md | 4 ++++ googletest | 1 - 4 files changed, 25 insertions(+), 10 deletions(-) delete mode 100644 .gitmodules delete mode 160000 googletest diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 8cf8b5e..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "googletest"] - path = googletest - url = https://github.com/google/googletest.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 8809b35..e3d8ab5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ -cmake_minimum_required(VERSION 3.6) +cmake_minimum_required(VERSION 3.14) -project(libjapi VERSION 0.3) +project(libjapi VERSION 0.4) set(SOVERSION 1) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -64,10 +64,24 @@ endif(DOXYGEN_FOUND) ################################ # Create unit test excecutable # - -add_subdirectory(googletest/googletest - EXCLUDE_FROM_ALL) - +find_package(GTest QUIET) +if(${GTest_FOUND}) + # Gtest on System Installed + message("GTest: Installed using GTest") + include(GoogleTest) +else() + # Include GoogleTest in the project + include(FetchContent) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG release-1.8.1 + ) + FetchContent_MakeAvailable(googletest) + include(GoogleTest) +endif() + +# Define test executable add_executable(testsuite EXCLUDE_FROM_ALL test/japi_test.cc @@ -80,6 +94,7 @@ target_link_libraries(testsuite japi ) +# Include directories target_include_directories(testsuite PUBLIC include/ diff --git a/README.md b/README.md index 58d3c50..5555ee5 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,10 @@ A Makefile is generated. Run 'make' to build the libjapi libraries. A shared and a static library is built. +To run the internal tests run + + $ make run_test + ## Demo You can clone the [demo project](https://git01.iis.fhg.de/ks-ip-lib/software/libjapi-demo), with examples for all features from the repository listed below: diff --git a/googletest b/googletest deleted file mode 160000 index 3f5b5b8..0000000 --- a/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3f5b5b8f8493a03fa25f1e4a7eae7678514a431d From 6d535b1c3532a65cadf19c3002b0230ce8b05fc2 Mon Sep 17 00:00:00 2001 From: Michael Nieland Date: Wed, 24 Jul 2024 07:52:39 +0000 Subject: [PATCH 04/11] enable tests by default and always include googletest --- CMakeLists.txt | 81 ++++++++++++++++++++------------------------------ README.md | 4 +-- 2 files changed, 34 insertions(+), 51 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3d8ab5..d07cf10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_C_STANDARD_REQUIRED ON) # 'cmake -DCMAKE_BUILD_TYPE=Debug ../' from build folder for debug output # if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Release") + set(CMAKE_BUILD_TYPE "Release") endif() file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*) @@ -29,12 +29,11 @@ target_include_directories(japi_objs PUBLIC include/ ${JSONC_INCLUDE_DIRS}) set_property(TARGET japi_objs PROPERTY POSITION_INDEPENDENT_CODE ON) # set up actual libraries -add_library(japi SHARED $) +add_library(japi SHARED $) add_library(japi-static STATIC $) -set_target_properties(japi PROPERTIES - PUBLIC_HEADER "${PUBLIC_HEADERS}" - SOVERSION ${SOVERSION}) +set_target_properties(japi PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}" + SOVERSION ${SOVERSION}) target_link_libraries(japi PkgConfig::JSONC) target_link_libraries(japi-static PkgConfig::JSONC) @@ -54,8 +53,10 @@ install(TARGETS japi find_package(Doxygen) if(DOXYGEN_FOUND) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxydir/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) - add_custom_target(doc + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxydir/Doxyfile.in + ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) + add_custom_target( + doc ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Generating API documentation with Doxygen" VERBATIM @@ -64,59 +65,41 @@ endif(DOXYGEN_FOUND) ################################ # Create unit test excecutable # -find_package(GTest QUIET) -if(${GTest_FOUND}) - # Gtest on System Installed - message("GTest: Installed using GTest") - include(GoogleTest) -else() +option(LIBJAPI_ENABLE_TESTING "Enable testing with googletest" ON) +if(LIBJAPI_ENABLE_TESTING) + enable_testing() + # Include GoogleTest in the project include(FetchContent) FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG release-1.8.1 - ) + GIT_TAG release-1.8.1) FetchContent_MakeAvailable(googletest) include(GoogleTest) -endif() - -# Define test executable -add_executable(testsuite - EXCLUDE_FROM_ALL - test/japi_test.cc -) -target_compile_options(testsuite PUBLIC "-pthread") + # Define test executable + add_executable(testsuite test/japi_test.cc) -target_link_libraries(testsuite - gtest_main - japi -) + target_compile_options(testsuite PUBLIC "-pthread") -# Include directories -target_include_directories(testsuite - PUBLIC - include/ - src/ - ${JSONC_INCLUDE_DIRS} -) + target_link_libraries(testsuite gtest_main japi) -add_custom_target(run_test COMMAND testsuite DEPENDS testsuite) + # Include directories + target_include_directories(testsuite PUBLIC include/ src/ + ${JSONC_INCLUDE_DIRS}) + # add_custom_target(run_test COMMAND testsuite DEPENDS testsuite) + gtest_discover_tests(testsuite) ################################ -# Test code coverage # - -if(CMAKE_BUILD_TYPE MATCHES "Debug") - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") - include(${CMAKE_SOURCE_DIR}/cmake/CodeCoverage.cmake) - set(COVERAGE_EXCLUDES - "doxydir" - "/usr/include/*" - "googletest/*" - "test/*" - ) - append_coverage_compiler_flags() + # Test code coverage # - setup_target_for_coverage_lcov(NAME coverage EXECUTABLE testsuite) -endif() + if(CMAKE_BUILD_TYPE MATCHES "Debug") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + include(${CMAKE_SOURCE_DIR}/cmake/CodeCoverage.cmake) + set(COVERAGE_EXCLUDES "doxydir" "/usr/include/*" "googletest/*" "test/*") + append_coverage_compiler_flags() + + setup_target_for_coverage_lcov(NAME coverage EXECUTABLE testsuite) + endif() +endif(LIBJAPI_ENABLE_TESTING) diff --git a/README.md b/README.md index 5555ee5..0151964 100644 --- a/README.md +++ b/README.md @@ -38,11 +38,11 @@ A Makefile is generated. Run 'make' to build the libjapi libraries. $ make -A shared and a static library is built. +A shared and a static library is built. Tests are built by default. They can be disabled using the `LIBJAPI_ENABLE_TESTING` variable. To run the internal tests run - $ make run_test + $ ctest ## Demo You can clone the [demo project](https://git01.iis.fhg.de/ks-ip-lib/software/libjapi-demo), with examples for all features from the repository listed below: From 965d2d896b81e9553c5e5c9ac9b39ddeec942dee Mon Sep 17 00:00:00 2001 From: Michael Nieland Date: Tue, 30 Jul 2024 09:02:11 +0000 Subject: [PATCH 05/11] clearer instructions for testing in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0151964..34a5c4c 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ A Makefile is generated. Run 'make' to build the libjapi libraries. $ make -A shared and a static library is built. Tests are built by default. They can be disabled using the `LIBJAPI_ENABLE_TESTING` variable. +A shared and a static library is built. Tests are built by default. They can be disabled using the command `cmake -DLIBJAPI_ENABLE_TESTING=FALSE ../` variable. To run the internal tests run From 7383259fc67fc22d9758b45011678cc81b67917c Mon Sep 17 00:00:00 2001 From: Michael Nieland Date: Tue, 30 Jul 2024 09:02:43 +0000 Subject: [PATCH 06/11] remove unused line. Change googletest version due to internal error, --- CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d07cf10..4ef52d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,7 +74,7 @@ if(LIBJAPI_ENABLE_TESTING) FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG release-1.8.1) + GIT_TAG release-1.8.0) FetchContent_MakeAvailable(googletest) include(GoogleTest) @@ -89,7 +89,6 @@ if(LIBJAPI_ENABLE_TESTING) target_include_directories(testsuite PUBLIC include/ src/ ${JSONC_INCLUDE_DIRS}) - # add_custom_target(run_test COMMAND testsuite DEPENDS testsuite) gtest_discover_tests(testsuite) ################################ # Test code coverage # @@ -97,7 +96,7 @@ if(LIBJAPI_ENABLE_TESTING) if(CMAKE_BUILD_TYPE MATCHES "Debug") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(${CMAKE_SOURCE_DIR}/cmake/CodeCoverage.cmake) - set(COVERAGE_EXCLUDES "doxydir" "/usr/include/*" "googletest/*" "test/*") + set(COVERAGE_EXCLUDES "doxydir" "/usr/include/*" "test/*") append_coverage_compiler_flags() setup_target_for_coverage_lcov(NAME coverage EXECUTABLE testsuite) From 8ae4881a214540af238b9591d9a54121ea984686 Mon Sep 17 00:00:00 2001 From: Michael Nieland Date: Thu, 1 Aug 2024 06:27:47 +0000 Subject: [PATCH 07/11] Coverage target is created when tests are enabled. --- CMakeLists.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ef52d4..ec7b010 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,15 +90,19 @@ if(LIBJAPI_ENABLE_TESTING) ${JSONC_INCLUDE_DIRS}) gtest_discover_tests(testsuite) -################################ - # Test code coverage # +################################ +# Test code coverage # if(CMAKE_BUILD_TYPE MATCHES "Debug") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(${CMAKE_SOURCE_DIR}/cmake/CodeCoverage.cmake) - set(COVERAGE_EXCLUDES "doxydir" "/usr/include/*" "test/*") + set(COVERAGE_EXCLUDES + "doxydir" + "/usr/include" + "_deps/googletest" + "test/*" + ) append_coverage_compiler_flags() - setup_target_for_coverage_lcov(NAME coverage EXECUTABLE testsuite) endif() endif(LIBJAPI_ENABLE_TESTING) From 387ba34f4de46d8fcebe55b956cf056855822a7f Mon Sep 17 00:00:00 2001 From: vornkat-iis Date: Thu, 1 Aug 2024 16:57:27 +0000 Subject: [PATCH 08/11] CI: changed target for testing --- .github/workflows/CMake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CMake.yml b/.github/workflows/CMake.yml index 54f8cdc..adf3459 100644 --- a/.github/workflows/CMake.yml +++ b/.github/workflows/CMake.yml @@ -37,4 +37,4 @@ jobs: working-directory: ${{ env.GITHUB_WORKSPACE }}/build # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: make run_test + run: ctest From 8d3a158d1818ed87e413fd41a6c36c0b70991fed Mon Sep 17 00:00:00 2001 From: Katja Vornberger Date: Thu, 1 Aug 2024 21:16:35 +0200 Subject: [PATCH 09/11] CI: Fix ctest command for CentOS7 and add devcontainer config to provide correct platform --- .devcontainer/devcontainer.json | 18 ++++++++++++++++++ .github/workflows/CMake.yml | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..9577d6c --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,18 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu +{ + "name": "libjapi_ci_build", + "image": "ghcr.io/fraunhofer-iis/libjapi_ci" + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.github/workflows/CMake.yml b/.github/workflows/CMake.yml index adf3459..883c8f4 100644 --- a/.github/workflows/CMake.yml +++ b/.github/workflows/CMake.yml @@ -37,4 +37,6 @@ jobs: working-directory: ${{ env.GITHUB_WORKSPACE }}/build # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest + run: | + make && + ctest3 From 3e0c627cd8e047cfe054af1d4c25baaf1d63f9a6 Mon Sep 17 00:00:00 2001 From: baronml Date: Wed, 7 Aug 2024 17:15:25 +0200 Subject: [PATCH 10/11] Split CMakeLists for libjapi compiling and test-framework with each differnt cmake version number --- CMakeLists.txt | 5 +++-- README.md | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec7b010..f5822f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.6) project(libjapi VERSION 0.4) set(SOVERSION 1) @@ -67,6 +67,7 @@ endif(DOXYGEN_FOUND) # Create unit test excecutable # option(LIBJAPI_ENABLE_TESTING "Enable testing with googletest" ON) if(LIBJAPI_ENABLE_TESTING) + cmake_minimum_required(VERSION 3.14) enable_testing() # Include GoogleTest in the project @@ -105,4 +106,4 @@ if(LIBJAPI_ENABLE_TESTING) append_coverage_compiler_flags() setup_target_for_coverage_lcov(NAME coverage EXECUTABLE testsuite) endif() -endif(LIBJAPI_ENABLE_TESTING) +endif(LIBJAPI_ENABLE_TESTING) \ No newline at end of file diff --git a/README.md b/README.md index 34a5c4c..5b6fffe 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ Prebuild packages for CentOS 7 can be downloaded from the [latest package Action ### Prerequisites * [json-c](https://github.com/json-c/json-c) -* [cmake version 3.6](https://cmake.org/) +* [cmake version 3.6](https://cmake.org/) for libjapi build +* [cmake version 3.14](https://cmake.org/) for libjapi test-framework build ### Installation Clone the git repository and it's submodules: @@ -38,7 +39,7 @@ A Makefile is generated. Run 'make' to build the libjapi libraries. $ make -A shared and a static library is built. Tests are built by default. They can be disabled using the command `cmake -DLIBJAPI_ENABLE_TESTING=FALSE ../` variable. +A shared and a static library is built. Tests are built by default. They can be disabled using the command `cmake -DLIBJAPI_ENABLE_TESTING=OFF ../` variable. To run the internal tests run From cfe0f19cee2435006fa890f92917d3bc73c4f2fc Mon Sep 17 00:00:00 2001 From: vornkat-iis Date: Fri, 9 Aug 2024 17:31:16 +0200 Subject: [PATCH 11/11] Make CREADLINE_MAX_LINE_SIZE configurable from CMakeList --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5822f6..ddb8a31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,12 @@ pkg_search_module(JSONC REQUIRED IMPORTED_TARGET json-c) # create an object lib to avoid double compilation add_library(japi_objs OBJECT ${SOURCES} ${HEADERS}) +if(DEFINED CREADLINE_MAX_LINE_SIZE) + if(CREADLINE_MAX_LINE_SIZE LESS 1024) + message(FATAL_ERROR "Minimal linesize is CREADLINE_BLOCK_SIZE=1024 bytes") + endif() + target_compile_definitions(japi_objs PRIVATE CREADLINE_MAX_LINE_SIZE=${CREADLINE_MAX_LINE_SIZE}) +endif() target_compile_options(japi_objs PUBLIC "-pthread" "-D_POSIX_C_SOURCE=200809L") target_include_directories(japi_objs PUBLIC include/ ${JSONC_INCLUDE_DIRS}) set_property(TARGET japi_objs PROPERTY POSITION_INDEPENDENT_CODE ON)