diff --git a/.ci/build-kit/install_and_test.sh b/.ci/build-kit/install_and_test.sh index 2d0c47b48..a3b8c3e89 100755 --- a/.ci/build-kit/install_and_test.sh +++ b/.ci/build-kit/install_and_test.sh @@ -1,17 +1,15 @@ -#!/bin/sh +!/bin/sh set -e cmake \ -B build \ -S "$EXT_MOUNT/source" \ - -DBUILD_TESTING_LIBOCPP=ON \ + -G Ninja \ + -DBUILD_TESTING=ON \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_INSTALL_PREFIX="$WORKSPACE_PATH/dist" -make -j$(nproc) -C build install +ninja -j$(nproc) -C build install -cd ./build/tests/ - -./database_tests -./utils_tests +ninja -j$(nproc) -C build tests/test \ No newline at end of file diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index 75350c896..2a57d2d0a 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -1,5 +1,10 @@ +# Please reference work here https://github.com/EVerest/everest-core/tree/main/.github/workflows +# TODO: modify to reuse the above workflow to DRY up CI. + name: Build and test libocpp on: + push: + branch: "**" pull_request: {} workflow_dispatch: inputs: @@ -13,7 +18,7 @@ on: - 'large-ubuntu-22.04-xxl' jobs: lint: - name: Install and test + name: Lint strategy: matrix: os: [ubuntu-22.04] @@ -29,6 +34,17 @@ jobs: source-dir: source extensions: hpp,cpp exclude: cache + install_and_test: + name: Install and test + strategy: + matrix: + os: [ubuntu-22.04] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout libocpp + uses: actions/checkout@v3 + with: + path: source - name: Setup run scripts run: | mkdir scripts @@ -43,4 +59,10 @@ jobs: --volume "$(pwd):/ext" \ --name test-container \ build-kit run-script install_and_test + - name: Archive test results + if: always() + uses: actions/upload-artifact@v3 + with: + name: ctest-report + path: /workspace/build/tests/Testing/Temporary/LastTest.log diff --git a/.gitignore b/.gitignore index d2a1bc5ee..8e78b9cb2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,8 @@ -*build* -!.ci/** -!.github/** +/build !.gitignore *vscode -cache/ +.cache/ workspace.yaml CMakeLists.txt.user !doc/build-with-fetchcontent +/dist diff --git a/CMakeLists.txt b/CMakeLists.txt index 182250711..2eed8f2b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,9 @@ if(CMAKE_RUN_CLANG_TIDY) -export-fixes=clang-tidy-fixes.yaml) endif() -if(BUILD_TESTING_LIBOCPP) +if(BUILD_TESTING) + enable_testing() + include(CTest) add_subdirectory(tests) endif() diff --git a/README.md b/README.md index dcfe27f8f..ef7b0bbb7 100644 --- a/README.md +++ b/README.md @@ -498,19 +498,7 @@ The main reference for the integration of libocpp for OCPP1.6 is the ocpp::v16:: ## Unit testing -If you want to run the unit tests in the tests subdirectory: install the needed dependencies. -For Debian GNU/Linux 11 you can install it like this: - -```bash -sudo apt install libgtest-dev lcov -python3 -m pip install gcovr -``` - -Run the unit tests - -```bash - cmake .. -DBUILD_TESTING=ON -``` +GTest is required for building the test cases target. To build the target and run the tests you can reference the script `.ci/build-kit/install_and_test.sh`. The script allows the GitHub Actions runner to execute. Local testing is still in progress. ## Building with FetchContent instead of EDM In [doc/build-with-fetchcontent](doc/build-with-fetchcontent) you can find an example how to build libocpp with FetchContent instead of EDM. diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 74ef3e953..f142b847b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,3 +1,4 @@ +add_definitions(-D_SQL_INIT_FILE="${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/everest/modules/OCPP/init.sql") add_executable(database_tests database_tests.cpp) target_include_directories(database_tests PUBLIC ${GTEST_INCLUDE_DIRS}) diff --git a/tests/database_tests.cpp b/tests/database_tests.cpp index 2c487d89d..b6400f88a 100644 --- a/tests/database_tests.cpp +++ b/tests/database_tests.cpp @@ -10,6 +10,7 @@ namespace ocpp { namespace v16 { +#define SQL_INIT_FILE _SQL_INIT_FILE ChargingProfile get_sample_charging_profile() { ChargingSchedulePeriod period1; @@ -52,9 +53,9 @@ ChargingProfile get_sample_charging_profile() { class DatabaseTest : public ::testing::Test { protected: void SetUp() override { - this->db_handler = - std::make_unique(CP_ID, std::filesystem::path("/tmp"), - std::filesystem::path("../../dist/share/everest/modules/OCPP/init.sql")); + std::cout << SQL_INIT_FILE <db_handler = std::make_unique(CP_ID,std::filesystem::path("/tmp"), + std::filesystem::path(SQL_INIT_FILE)); this->db_handler->open_db_connection(2); }