Skip to content

Commit

Permalink
Addressed PR Comments
Browse files Browse the repository at this point in the history
Signed-off-by: Coury Richards <[email protected]>
  • Loading branch information
couryrr-afs committed Dec 18, 2023
1 parent 4f87fd8 commit 844e351
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 29 deletions.
12 changes: 5 additions & 7 deletions .ci/build-kit/install_and_test.sh
Original file line number Diff line number Diff line change
@@ -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
24 changes: 23 additions & 1 deletion .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -13,7 +18,7 @@ on:
- 'large-ubuntu-22.04-xxl'
jobs:
lint:
name: Install and test
name: Lint
strategy:
matrix:
os: [ubuntu-22.04]
Expand All @@ -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
Expand All @@ -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

7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
*build*
!.ci/**
!.github/**
/build
!.gitignore
*vscode
cache/
.cache/
workspace.yaml
CMakeLists.txt.user
!doc/build-with-fetchcontent
/dist
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
14 changes: 1 addition & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
Expand Down
7 changes: 4 additions & 3 deletions tests/database_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace ocpp {
namespace v16 {
#define SQL_INIT_FILE _SQL_INIT_FILE

ChargingProfile get_sample_charging_profile() {
ChargingSchedulePeriod period1;
Expand Down Expand Up @@ -52,9 +53,9 @@ ChargingProfile get_sample_charging_profile() {
class DatabaseTest : public ::testing::Test {
protected:
void SetUp() override {
this->db_handler =
std::make_unique<DatabaseHandler>(CP_ID, std::filesystem::path("/tmp"),
std::filesystem::path("../../dist/share/everest/modules/OCPP/init.sql"));
std::cout << SQL_INIT_FILE <<std::endl;
this->db_handler = std::make_unique<DatabaseHandler>(CP_ID,std::filesystem::path("/tmp"),
std::filesystem::path(SQL_INIT_FILE));
this->db_handler->open_db_connection(2);
}

Expand Down

0 comments on commit 844e351

Please sign in to comment.