From 3c9529137e675edc1e4ee7d5c81e9e8092efeaf8 Mon Sep 17 00:00:00 2001 From: Sebastian Lukas Date: Thu, 13 Jun 2024 11:20:29 +0200 Subject: [PATCH] Adding simple lint, build and test ci workflows Signed-off-by: Sebastian Lukas --- .ci/build-kit/build_and_test.sh | 16 ++ .github/workflows/build_and_test.yaml | 56 +++++++ tests/DIN/session_setup.cpp | 203 +++++++++++++------------- 3 files changed, 175 insertions(+), 100 deletions(-) create mode 100755 .ci/build-kit/build_and_test.sh create mode 100644 .github/workflows/build_and_test.yaml diff --git a/.ci/build-kit/build_and_test.sh b/.ci/build-kit/build_and_test.sh new file mode 100755 index 0000000..eabb58d --- /dev/null +++ b/.ci/build-kit/build_and_test.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +cmake \ + -B build \ + -S "$EXT_MOUNT/source" \ + -G Ninja \ + -DCB_V2G_BUILD_TESTS=ON \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + +ninja -j$(nproc) -C build + +trap "cp build/Testing/Temporary/LastTest.log /ext/ctest-report" EXIT + +ninja -j$(nproc) -C build test diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml new file mode 100644 index 0000000..4306111 --- /dev/null +++ b/.github/workflows/build_and_test.yaml @@ -0,0 +1,56 @@ +name: Build and test libcbv2g +on: + pull_request: {} + workflow_dispatch: + inputs: + runner: + description: Which runner to use + type: choice + default: 'ubuntu-22.04' + required: true + options: + - 'ubuntu-22.04' + - 'large-ubuntu-22.04-xxl' +jobs: + lint: + name: Lint + runs-on: ${{ inputs.runner || 'ubuntu-22.04' }} + steps: + - name: Checkout libcbv2g + uses: actions/checkout@v3 + with: + path: source + - name: Run clang-format + uses: everest/everest-ci/github-actions/run-clang-format@v1.1.0 + with: + source-dir: source + extensions: hpp,cpp + exclude: cache + build_and_test: + name: Build and test + runs-on: ${{ inputs.runner || 'ubuntu-22.04' }} + steps: + - name: Checkout libcbv2g + uses: actions/checkout@v3 + with: + path: source + - name: Setup run scripts + run: | + mkdir scripts + rsync -a source/.ci/build-kit/ scripts + - name: Pull docker container + run: | + docker pull --platform=linux/x86_64 --quiet ghcr.io/everest/build-kit-alpine:latest + docker image tag ghcr.io/everest/build-kit-alpine:latest build-kit + - name: Build and test + run: | + docker run \ + --volume "$(pwd):/ext" \ + --name test-container \ + build-kit run-script build_and_test + - name: Archive test results + if: always() + uses: actions/upload-artifact@v3 + with: + name: ctest-report + path: ${{ github.workspace }}/ctest-report diff --git a/tests/DIN/session_setup.cpp b/tests/DIN/session_setup.cpp index fc94ce3..80720ac 100644 --- a/tests/DIN/session_setup.cpp +++ b/tests/DIN/session_setup.cpp @@ -44,7 +44,7 @@ SCENARIO("Encode and decode DIN session setup message") { auto& body = request.V2G_Message.Body; init_din_SessionSetupReqType(&body.SessionSetupReq); body.SessionSetupReq_isUsed = true; - const auto evccid = std::array {0x84, 0x87, 0x72, 0x60, 0xF3, 0x58, 0x00, 0x00}; + const auto evccid = std::array{0x84, 0x87, 0x72, 0x60, 0xF3, 0x58, 0x00, 0x00}; std::copy(evccid.begin(), evccid.end(), body.SessionSetupReq.EVCCID.bytes); body.SessionSetupReq.EVCCID.bytesLen = 6; @@ -120,103 +120,106 @@ SCENARIO("Encode and decode DIN session setup message") { // // -// TODO: These tests should work but at the moment the exi stream is broken. -// -// GIVEN("Good case - Encode an SessionSetupRes document") { -// uint8_t doc_raw[] = "\x80\x98\x02\x14\xb2\x2c\xa1\xaf\xff\x8d\x8b\x51\xe0\x20\x45\x11\x14\xa9\x41\x39\x60\xa9" -// "\x14\xc4\xc8\xcc\xd0\xd4\xa8\xc4\x12\xd7\x1b\xd3\xc0\xc0"; -// -// din_exiDocument request; -// init_din_exiDocument(&request); -// -// init_din_MessageHeaderType(&request.V2G_Message.Header); -// -// auto& header = request.V2G_Message.Header; -// header.SessionID.bytesLen = din_sessionIDType_BYTES_SIZE; -// const auto session_id = std::array{0x52, 0xC8, 0xB2, 0x86, 0xBF, 0xFE, 0x36, 0x2D}; -// std::copy(session_id.begin(), session_id.end(), header.SessionID.bytes); -// -// init_din_BodyType(&request.V2G_Message.Body); -// auto& body = request.V2G_Message.Body; -// init_din_SessionSetupResType(&body.SessionSetupRes); -// body.SessionSetupRes_isUsed = true; -// -// // set the response code -// body.SessionSetupRes.ResponseCode = din_responseCodeType_OK_NewSessionEstablished; -// -// // set the EVSE ID -// const auto evse_id = -// std::array{'D', 'E', '*', 'P', 'N', 'X', '*', 'E', '1', '2', '3', '4', '5', '*', '1'}; -// std::copy(evse_id.begin(), evse_id.end(), body.SessionSetupRes.EVSEID.bytes); -// body.SessionSetupRes.EVSEID.bytesLen = evse_id.size(); -// -// // set the EVSE timestamp -// body.SessionSetupRes.DateTimeNow_isUsed = true; -// body.SessionSetupRes.DateTimeNow = 1675074582; -// -// uint8_t stream[256] = {}; -// exi_bitstream_t exi_stream_in; -// size_t pos1 = 0; -// int errn = 0; -// -// exi_bitstream_init(&exi_stream_in, stream, sizeof(stream), pos1, nullptr); -// -// THEN("It should be encoded succussfully") { -// -// REQUIRE(encode_din_exiDocument(&exi_stream_in, &request) == 0); -// -// const auto encoded_stream = -// std::vector(stream, stream + exi_bitstream_get_length(&exi_stream_in) + 1); -// -// const auto expected_exi_stream = std::vector(std::begin(doc_raw), std::end(doc_raw)); -// -// // REQUIRE(encoded_stream == expected_exi_stream); -// } -// } -// -// GIVEN("Good case - Decode an SessionSetupRes document") { -// -// uint8_t doc_raw[] = "\x80\x98\x02\x14\xb2\x2c\xa1\xaf\xff\x8d\x8b\x51\xe0\x20\x45\x11\x14\xa9\x41\x39\x60\xa9" -// "\x14\xc4\xc8\xcc\xd0\xd4\xa8\xc4\x12\xd7\x1b\xd3\xc0\xc0"; -// -// exi_bitstream_t exi_stream_in; -// size_t pos1 = 0; -// int errn = 0; -// -// exi_bitstream_init(&exi_stream_in, reinterpret_cast(doc_raw), sizeof(doc_raw), pos1, nullptr); -// -// THEN("It should be decoded succussfully") { -// din_exiDocument request; -// -// REQUIRE(decode_din_exiDocument(&exi_stream_in, &request) == 0); -// -// // Check Header -// auto& header = request.V2G_Message.Header; -// const auto expected_session_id = std::vector{0x52, 0xC8, 0xB2, 0x86, 0xBF, 0xFE, 0x36, 0x2D}; -// const auto session_id = -// std::vector(std::begin(header.SessionID.bytes), std::end(header.SessionID.bytes)); -// REQUIRE(session_id == expected_session_id); -// REQUIRE(header.Notification_isUsed == false); -// REQUIRE(header.Signature_isUsed == false); -// -// // Check Body -// REQUIRE(request.V2G_Message.Body.SessionSetupRes_isUsed == true); -// -// auto& session_setup_res = request.V2G_Message.Body.SessionSetupRes; -// -// // check the response code -// REQUIRE(session_setup_res.ResponseCode == din_responseCodeType_OK_NewSessionEstablished); -// -// // check the EVSE ID -// const auto evse_id = std::vector(std::begin(session_setup_res.EVSEID.bytes), -// std::end(session_setup_res.EVSEID.bytes)); -// REQUIRE(evse_id == -// std::vector({'D', 'E', '*', 'P', 'N', 'X', '*', 'E', '1', '2', '3', '4', '5', '*', '1'})); -// REQUIRE(session_setup_res.EVSEID.bytesLen == 15); -// -// // check the EVSE timestamp -// REQUIRE(session_setup_res.DateTimeNow_isUsed == true); -// REQUIRE(session_setup_res.DateTimeNow == 1675074582); -// } -// } + // TODO: These tests should work but at the moment the exi stream is broken. + // + // GIVEN("Good case - Encode an SessionSetupRes document") { + // uint8_t doc_raw[] = + // "\x80\x98\x02\x14\xb2\x2c\xa1\xaf\xff\x8d\x8b\x51\xe0\x20\x45\x11\x14\xa9\x41\x39\x60\xa9" + // "\x14\xc4\xc8\xcc\xd0\xd4\xa8\xc4\x12\xd7\x1b\xd3\xc0\xc0"; + // + // din_exiDocument request; + // init_din_exiDocument(&request); + // + // init_din_MessageHeaderType(&request.V2G_Message.Header); + // + // auto& header = request.V2G_Message.Header; + // header.SessionID.bytesLen = din_sessionIDType_BYTES_SIZE; + // const auto session_id = std::array{0x52, 0xC8, 0xB2, 0x86, 0xBF, 0xFE, 0x36, 0x2D}; + // std::copy(session_id.begin(), session_id.end(), header.SessionID.bytes); + // + // init_din_BodyType(&request.V2G_Message.Body); + // auto& body = request.V2G_Message.Body; + // init_din_SessionSetupResType(&body.SessionSetupRes); + // body.SessionSetupRes_isUsed = true; + // + // // set the response code + // body.SessionSetupRes.ResponseCode = din_responseCodeType_OK_NewSessionEstablished; + // + // // set the EVSE ID + // const auto evse_id = + // std::array{'D', 'E', '*', 'P', 'N', 'X', '*', 'E', '1', '2', '3', '4', '5', '*', '1'}; + // std::copy(evse_id.begin(), evse_id.end(), body.SessionSetupRes.EVSEID.bytes); + // body.SessionSetupRes.EVSEID.bytesLen = evse_id.size(); + // + // // set the EVSE timestamp + // body.SessionSetupRes.DateTimeNow_isUsed = true; + // body.SessionSetupRes.DateTimeNow = 1675074582; + // + // uint8_t stream[256] = {}; + // exi_bitstream_t exi_stream_in; + // size_t pos1 = 0; + // int errn = 0; + // + // exi_bitstream_init(&exi_stream_in, stream, sizeof(stream), pos1, nullptr); + // + // THEN("It should be encoded succussfully") { + // + // REQUIRE(encode_din_exiDocument(&exi_stream_in, &request) == 0); + // + // const auto encoded_stream = + // std::vector(stream, stream + exi_bitstream_get_length(&exi_stream_in) + 1); + // + // const auto expected_exi_stream = std::vector(std::begin(doc_raw), std::end(doc_raw)); + // + // // REQUIRE(encoded_stream == expected_exi_stream); + // } + // } + // + // GIVEN("Good case - Decode an SessionSetupRes document") { + // + // uint8_t doc_raw[] = + // "\x80\x98\x02\x14\xb2\x2c\xa1\xaf\xff\x8d\x8b\x51\xe0\x20\x45\x11\x14\xa9\x41\x39\x60\xa9" + // "\x14\xc4\xc8\xcc\xd0\xd4\xa8\xc4\x12\xd7\x1b\xd3\xc0\xc0"; + // + // exi_bitstream_t exi_stream_in; + // size_t pos1 = 0; + // int errn = 0; + // + // exi_bitstream_init(&exi_stream_in, reinterpret_cast(doc_raw), sizeof(doc_raw), pos1, nullptr); + // + // THEN("It should be decoded succussfully") { + // din_exiDocument request; + // + // REQUIRE(decode_din_exiDocument(&exi_stream_in, &request) == 0); + // + // // Check Header + // auto& header = request.V2G_Message.Header; + // const auto expected_session_id = std::vector{0x52, 0xC8, 0xB2, 0x86, 0xBF, 0xFE, 0x36, 0x2D}; + // const auto session_id = + // std::vector(std::begin(header.SessionID.bytes), std::end(header.SessionID.bytes)); + // REQUIRE(session_id == expected_session_id); + // REQUIRE(header.Notification_isUsed == false); + // REQUIRE(header.Signature_isUsed == false); + // + // // Check Body + // REQUIRE(request.V2G_Message.Body.SessionSetupRes_isUsed == true); + // + // auto& session_setup_res = request.V2G_Message.Body.SessionSetupRes; + // + // // check the response code + // REQUIRE(session_setup_res.ResponseCode == din_responseCodeType_OK_NewSessionEstablished); + // + // // check the EVSE ID + // const auto evse_id = std::vector(std::begin(session_setup_res.EVSEID.bytes), + // std::end(session_setup_res.EVSEID.bytes)); + // REQUIRE(evse_id == + // std::vector({'D', 'E', '*', 'P', 'N', 'X', '*', 'E', '1', '2', '3', '4', '5', '*', + // '1'})); + // REQUIRE(session_setup_res.EVSEID.bytesLen == 15); + // + // // check the EVSE timestamp + // REQUIRE(session_setup_res.DateTimeNow_isUsed == true); + // REQUIRE(session_setup_res.DateTimeNow == 1675074582); + // } + // } }