Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding simple lint, build and test ci workflows #13

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .ci/build-kit/build_and_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

set -e
SebaLukas marked this conversation as resolved.
Show resolved Hide resolved

cmake \
-B build \
-S "$EXT_MOUNT/source" \
-G Ninja \
-DCB_V2G_BUILD_TESTS=ON \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON

ninja -C build

trap "cp build/Testing/Temporary/LastTest.log /ext/ctest-report" EXIT
SebaLukas marked this conversation as resolved.
Show resolved Hide resolved

ninja -C build test
32 changes: 32 additions & 0 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build and test libcbv2g
on:
pull_request: {}
jobs:
build_and_test:
name: Build and test
runs-on: 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 --quiet ghcr.io/everest/build-kit-alpine:v1.2.0
docker image tag ghcr.io/everest/build-kit-alpine:v1.2.0 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
203 changes: 103 additions & 100 deletions tests/DIN/session_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t, 8> {0x84, 0x87, 0x72, 0x60, 0xF3, 0x58, 0x00, 0x00};
const auto evccid = std::array<uint8_t, 8>{0x84, 0x87, 0x72, 0x60, 0xF3, 0x58, 0x00, 0x00};
std::copy(evccid.begin(), evccid.end(), body.SessionSetupReq.EVCCID.bytes);
body.SessionSetupReq.EVCCID.bytesLen = 6;

Expand Down Expand Up @@ -120,103 +120,106 @@ SCENARIO("Encode and decode DIN session setup message") {
// </ns7:Body>
// </ns7:V2G_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<uint8_t, 8>{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<uint8_t, 15>{'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<uint8_t>(stream, stream + exi_bitstream_get_length(&exi_stream_in) + 1);
//
// const auto expected_exi_stream = std::vector<uint8_t>(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<uint8_t*>(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<uint8_t>{0x52, 0xC8, 0xB2, 0x86, 0xBF, 0xFE, 0x36, 0x2D};
// const auto session_id =
// std::vector<uint8_t>(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<uint8_t>(std::begin(session_setup_res.EVSEID.bytes),
// std::end(session_setup_res.EVSEID.bytes));
// REQUIRE(evse_id ==
// std::vector<uint8_t>({'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<uint8_t, 8>{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<uint8_t, 15>{'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<uint8_t>(stream, stream + exi_bitstream_get_length(&exi_stream_in) + 1);
//
// const auto expected_exi_stream = std::vector<uint8_t>(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<uint8_t*>(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<uint8_t>{0x52, 0xC8, 0xB2, 0x86, 0xBF, 0xFE, 0x36, 0x2D};
// const auto session_id =
// std::vector<uint8_t>(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<uint8_t>(std::begin(session_setup_res.EVSEID.bytes),
// std::end(session_setup_res.EVSEID.bytes));
// REQUIRE(evse_id ==
// std::vector<uint8_t>({'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);
// }
// }
}
Loading