Skip to content

Commit 7b8eb76

Browse files
CI: Add building, testing and linting (#297)
Signed-off-by: Coury Richards <146002925+couryrr-afs@users.noreply.github.com> Co-authored-by: Dominik-K <dominik@pionix.de>
1 parent 0255e3b commit 7b8eb76

File tree

8 files changed

+98
-37
lines changed

8 files changed

+98
-37
lines changed

.ci/build-kit/install_and_test.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
cmake \
6+
-B build \
7+
-S "$EXT_MOUNT/source" \
8+
-G Ninja \
9+
-DBUILD_TESTING=ON \
10+
-DCMAKE_BUILD_TYPE=Debug \
11+
-DCMAKE_INSTALL_PREFIX="$WORKSPACE_PATH/dist"
12+
13+
ninja -j$(nproc) -C build install
14+
15+
trap "cp build/Testing/Temporary/LastTest.log /ext/ctest-report" EXIT
16+
17+
ninja -j$(nproc) -C build test

.github/workflows/build_and_test.yaml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Please reference work here https://github.com/EVerest/everest-core/tree/main/.github/workflows
2+
# TODO: modify to reuse the above workflow to DRY up CI.
3+
4+
name: Build and test libocpp
5+
on:
6+
pull_request: {}
7+
workflow_dispatch:
8+
inputs:
9+
runner:
10+
description: Which runner to use
11+
type: choice
12+
default: 'ubuntu-22.04'
13+
required: true
14+
options:
15+
- 'ubuntu-22.04'
16+
- 'large-ubuntu-22.04-xxl'
17+
jobs:
18+
lint:
19+
name: Lint
20+
strategy:
21+
matrix:
22+
os: [ubuntu-22.04]
23+
runs-on: ${{ matrix.os }}
24+
steps:
25+
- name: Checkout libocpp
26+
uses: actions/checkout@v3
27+
with:
28+
path: source
29+
- name: Run clang-format
30+
uses: everest/everest-ci/github-actions/run-clang-format@v1.0.0
31+
with:
32+
source-dir: source
33+
extensions: hpp,cpp
34+
exclude: cache
35+
install_and_test:
36+
name: Install and test
37+
strategy:
38+
matrix:
39+
os: [ubuntu-22.04]
40+
runs-on: ${{ matrix.os }}
41+
steps:
42+
- name: Checkout libocpp
43+
uses: actions/checkout@v3
44+
with:
45+
path: source
46+
- name: Setup run scripts
47+
run: |
48+
mkdir scripts
49+
rsync -a source/.ci/build-kit/ scripts
50+
- name: Pull docker container
51+
run: |
52+
docker pull --platform=linux/x86_64 --quiet ghcr.io/everest/build-kit-alpine:latest
53+
docker image tag ghcr.io/everest/build-kit-alpine:latest build-kit
54+
- name: Run install with tests
55+
run: |
56+
docker run \
57+
--volume "$(pwd):/ext" \
58+
--name test-container \
59+
build-kit run-script install_and_test
60+
- name: Archive test results
61+
if: always()
62+
uses: actions/upload-artifact@v3
63+
with:
64+
name: ctest-report
65+
path: ${{ github.workspace }}/ctest-report
66+

.github/workflows/lint.yaml

-21
This file was deleted.

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
*build*
1+
/build
2+
!.gitignore
23
*vscode
34
.cache/
45
workspace.yaml
56
CMakeLists.txt.user
67
!doc/build-with-fetchcontent
8+
/dist

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ if(CMAKE_RUN_CLANG_TIDY)
103103
-export-fixes=clang-tidy-fixes.yaml)
104104
endif()
105105

106-
if(BUILD_TESTING_LIBOCPP)
106+
if(BUILD_TESTING)
107+
include(CTest)
107108
add_subdirectory(tests)
108109
endif()
109110

README.md

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# C++ implementation of OCPP
2+
![Github Actions](https://github.com/EVerest/libocpp/actions/workflows/build_and_test.yaml/badge.svg)
23

34
This is a C++ library implementation of OCPP for version 1.6 (https://www.openchargealliance.org/protocols/ocpp-16/) and 2.0.1 (https://www.openchargealliance.org/protocols/ocpp-201/). It enables charging stations to communicate with cloud backends for remote control, monitoring and billing of charging processes.
45

@@ -522,19 +523,10 @@ The main reference for the integration of libocpp for OCPP1.6 is the ocpp::v16::
522523

523524
## Unit testing
524525

525-
If you want to run the unit tests in the tests subdirectory: install the needed dependencies.
526-
For Debian GNU/Linux 11 you can install it like this:
527-
528-
```bash
529-
sudo apt install libgtest-dev lcov
530-
python3 -m pip install gcovr
531-
```
532-
533-
Run the unit tests
534-
535-
```bash
536-
cmake .. -DBUILD_TESTING=ON
537-
```
526+
GTest is required for building the test cases target.
527+
To build the target and run the tests you can reference the script `.ci/build-kit/install_and_test.sh`.
528+
The script allows the GitHub Actions runner to execute.
529+
Local testing is still in progress.
538530

539531
## Building with FetchContent instead of EDM
540532
In [doc/build-with-fetchcontent](doc/build-with-fetchcontent) you can find an example how to build libocpp with FetchContent instead of EDM.

tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
add_definitions(-D_SQL_INIT_FILE="${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/everest/modules/OCPP/init.sql")
12
add_executable(database_tests database_tests.cpp)
23

34
target_include_directories(database_tests PUBLIC ${GTEST_INCLUDE_DIRS})

tests/database_tests.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace ocpp {
1212
namespace v16 {
13+
#define SQL_INIT_FILE _SQL_INIT_FILE
1314

1415
ChargingProfile get_sample_charging_profile() {
1516
ChargingSchedulePeriod period1;
@@ -53,7 +54,7 @@ class DatabaseTest : public ::testing::Test {
5354
protected:
5455
void SetUp() override {
5556
this->db_handler = std::make_unique<DatabaseHandler>(CP_ID, std::filesystem::path("/tmp"),
56-
std::filesystem::path("../../config/v16/init.sql"));
57+
std::filesystem::path(SQL_INIT_FILE));
5758
this->db_handler->open_db_connection(2);
5859
}
5960

@@ -307,6 +308,8 @@ TEST_F(DatabaseTest, test_insert_and_get_transaction_without_id_tag) {
307308
}
308309

309310
TEST_F(DatabaseTest, test_insert_and_get_profiles) {
311+
// TODO enable again on fixing https://github.com/EVerest/libocpp/issues/384
312+
GTEST_SKIP() << "validFrom/validTo checks are failing. See https://github.com/EVerest/libocpp/issues/384";
310313

311314
const auto profile = get_sample_charging_profile();
312315

0 commit comments

Comments
 (0)