From 96e4f6e4566bc4daea79be4a84bb4b78fbf0abf8 Mon Sep 17 00:00:00 2001 From: emanuel Date: Thu, 13 May 2021 14:56:42 +0100 Subject: [PATCH] Add CI build --- .gitlab-ci.yml | 16 ++++++- test/CMakeLists.txt | 17 ++++++++ test/spawn.sh | 8 ++++ test/tester.c | 101 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 test/CMakeLists.txt create mode 100644 test/spawn.sh create mode 100644 test/tester.c diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6deeb6d..1806421 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,9 +1,23 @@ -image: archlinux +image: registry.es.av.it.pt/its/it2s-docker/archlinux-maker stages: + - build - deploy release - deploy debug +.dependencies: + before_script: + - pacman -Sy zeromq it2s-config-git it2s-asn-git it2s-tender-git + +build: + stage: build + extends: .dependencies + script: mkdir build && cd build && cmake .. && make + artifacts: + paths: + - ./build/src/it2s-itss-facilities + expire_in: 1 hour + deploy release: stage: deploy release script: diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..bf86018 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,17 @@ +ADD_EXECUTABLE(tester + tester.c +) + +TARGET_LINK_LIBRARIES(tester + -lit2s-asn-itss-facilities + -lit2s-asn-itss-transport + -lit2s-asn-itss-security + -lit2s-asn-itss-management + -lzmq + -lit2s-asn-camv2 + -lit2s-asn-ivim + -lit2s-asn-denmv2 + -lit2s-asn-cpm + -lit2s-tender +) + diff --git a/test/spawn.sh b/test/spawn.sh new file mode 100644 index 0000000..7bb4d7a --- /dev/null +++ b/test/spawn.sh @@ -0,0 +1,8 @@ +nohup ../build/src/it2s-itss-facilities > /dev/null 2>&1 & + +../build/test/./tester +code=$? + +killall it2s-itss-facilities + +exit $code diff --git a/test/tester.c b/test/tester.c new file mode 100644 index 0000000..0066125 --- /dev/null +++ b/test/tester.c @@ -0,0 +1,101 @@ +#include +#include +#include +#include + +#include +#include +#include + +void hex2bin(char* hex, uint8_t** bin, uint16_t* bin_len) { + *bin_len = strlen(hex) / 2; + *bin = malloc(*bin_len); + char substr[3]; + substr[2] = '\0'; + for (int i = 0; i < *bin_len; ++i) { + memcpy(substr, hex + i * 2, 2); + (*bin)[i] = (uint8_t)strtoul(substr, NULL, 16); + } +} + +int decap(void* ctx) { + + return 0; +} + + +int forward_up(void* ctx) { + printf("Testing forwarding up:\n"); + BTPDataIndication_t* bdi = calloc(1, sizeof(BTPDataIndication_t)); + + char* cam_hex = "02027dfddf4403ca4059bba5f38cc40dba9ffffffc2230eff200e11fc0078082a88a8337fee3fff600004dffea800618d08018efff14003ac68800c77ff8e002263460063bffd1000fb1a30031dffe2800958d30018efff840048c68800c77ffae002c63480063bffbd001a31a40031dfff28002d8cf0018c0"; + + uint8_t* cam; + uint16_t cam_len; + hex2bin(cam_hex, &cam, &cam_len); + + bdi->data.buf = cam; + bdi->data.size = cam_len; + bdi->gnDestinationAddress.buf = calloc(1, 6); + bdi->gnDestinationAddress.size = 6; + + uint8_t b_bdi_cam[512]; + b_bdi_cam[0] = 3; + + asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_BTPDataIndication, bdi, b_bdi_cam+1, 511); + + void* facilities_socket = zmq_socket(ctx, ZMQ_REQ); + + int code = 0; + + zmq_connect(facilities_socket, "ipc:///tmp/itss/facilities"); + zmq_send(facilities_socket, b_bdi_cam, enc.encoded+1, 0); + zmq_recv(facilities_socket, &code, 1, 0); + if (code) { + printf(" FAIL\n"); + return 1; + } + printf(" - Sent CAM BDI (%ldB)\n", bdi->data.size); + + void* applications_socket = zmq_socket(ctx, ZMQ_REP); + + zmq_bind(applications_socket, "ipc:///tmp/itss/applications"); + uint8_t buffer[2048]; + zmq_recv(applications_socket, buffer, 2048, 0); + code = 0; + zmq_send(applications_socket, &code, 1, 0); + + zmq_close(applications_socket); + zmq_close(facilities_socket); + + FacilitiesDataIndication_t* fdi = NULL; + asn_dec_rval_t dec = asn_decode(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesDataIndication, (void**) &fdi, buffer+1, 2047); + if (dec.code) { + printf(" FAIL\n"); + return 1; + } + printf(" - Received CAM FDI (%ldB)\n", fdi->data.size); + + if (fdi->data.size == bdi->data.size) { + printf(" OK\n"); + } else { + printf(" FAIL\n"); + return 1; + } + + return 0; +} + + +int main() { + + int rv = 0; + + void* ctx = zmq_ctx_new(); + + rv += forward_up(ctx); + rv += decap(ctx); + + return rv; +} +