diff --git a/CMakeLists.txt b/CMakeLists.txt index 4eda4b5..83698a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,4 +6,3 @@ SET(BUILD_SHARED_LIBS ON) SET(CMAKE_INSTALL_PREFIX "/usr") ADD_SUBDIRECTORY(src) -ADD_SUBDIRECTORY(test) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index bf86018..0000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 3b6ac6b..0000000 --- a/test/spawn.sh +++ /dev/null @@ -1,12 +0,0 @@ -mkdir -p /tmp/itss - -echo Spawning [facilities] -nohup ../build/src/it2s-itss-facilities > /dev/null 2>&1 & - -echo Running tester... -../build/test/./tester -code=$? - -killall it2s-itss-facilities - -exit $code diff --git a/test/tester.c b/test/tester.c deleted file mode 100644 index fcc44c1..0000000 --- a/test/tester.c +++ /dev/null @@ -1,243 +0,0 @@ -#include -#include -#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 init(void* ctx) { - printf("Simulating [management] ... \n"); fflush(stdout); - - void* management_socket = zmq_socket(ctx, ZMQ_REP); - - zmq_bind(management_socket, "ipc:///tmp/itss/management"); - uint8_t buffer[2048]; - - // Request get - zmq_recv(management_socket, buffer, 2048, 0); - int rv = 0; - - ManagementRequest_t* mreq = NULL; - asn_dec_rval_t dec = asn_decode(NULL, ATS_CANONICAL_OER, &asn_DEF_ManagementRequest, (void**) &mreq, buffer, 2048); - if (dec.code) { - rv = 1; - printf(" FAIL: MREQ decode error\n"); fflush(stdout); - goto cleanup; - } - printf(" - Received MREQ.get\n"); fflush(stdout); - - ManagementReply_t* mrep = calloc(1, sizeof(ManagementReply_t)); - switch (mreq->present) { - case ManagementRequest_PR_attributes: - switch (mreq->choice.attributes.present) { - case ManagementRequestAttributes_PR_get: - mrep->returnCode = ManagementReplyReturnCode_accepted; - mrep->data = calloc(1, sizeof(ManagementReplyData_t)); - mrep->data->present = ManagementReplyData_PR_attributes; - - if (mreq->choice.attributes.choice.get.stationID) { - mrep->data->choice.attributes.stationID = malloc(sizeof(long)); - *mrep->data->choice.attributes.stationID = 78; - } - - if (mreq->choice.attributes.choice.get.gpsType) { - mrep->data->choice.attributes.gpsType = malloc(sizeof(long)); - *mrep->data->choice.attributes.gpsType = 0; - } - - if (mreq->choice.attributes.choice.get.clockType) { - mrep->data->choice.attributes.clockType = malloc(sizeof(long)); - *mrep->data->choice.attributes.clockType = 0; - } - - if (mreq->choice.attributes.choice.get.clock) { - mrep->data->choice.attributes.clock = calloc(1, sizeof(TimestampIts_t)); - asn_ulong2INTEGER(mrep->data->choice.attributes.clock, 666); - } - - if (mreq->choice.attributes.choice.get.clockOffset) { - mrep->data->choice.attributes.clockOffset = calloc(1, sizeof(TimestampIts_t)); - asn_ulong2INTEGER(mrep->data->choice.attributes.clockOffset, 0); - } - - if (mreq->choice.attributes.choice.get.coordinates) { - mrep->data->choice.attributes.coordinates = calloc(1, sizeof(WGS84Coordinates_t)); - mrep->data->choice.attributes.coordinates->latitude = 0; - mrep->data->choice.attributes.coordinates->longitude = 0; - } - - if (mreq->choice.attributes.choice.get.altitude) { - mrep->data->choice.attributes.altitude = calloc(1, sizeof(Altitude_t)); - mrep->data->choice.attributes.altitude->altitudeValue = 0; - mrep->data->choice.attributes.altitude->altitudeConfidence = 1; - } - - if (mreq->choice.attributes.choice.get.speed) { - mrep->data->choice.attributes.speed = calloc(1, sizeof(Speed_t)); - mrep->data->choice.attributes.speed->speedValue = 0; - mrep->data->choice.attributes.speed->speedConfidence = 1; - } - - if (mreq->choice.attributes.choice.get.heading) { - mrep->data->choice.attributes.heading = calloc(1, sizeof(Heading_t)); - mrep->data->choice.attributes.heading->headingValue = 0; - mrep->data->choice.attributes.heading->headingConfidence = 1; - } - break; - - default: - rv = 1; - printf(" FAIL: MREQ.ATTRIBUTES. not GET (%d)\n", mreq->present); fflush(stdout); - goto cleanup; - } - break; - - case ManagementRequest_PR_sa: - default: - rv = 1; - printf(" FAIL: MREQ. not ATTRIBUTES (%d)\n", mreq->present); fflush(stdout); - goto cleanup; - } - - asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_ManagementReply, NULL, mrep, buffer, 256); - zmq_send(management_socket, buffer, enc.encoded, 0); - - printf(" OK\n"); fflush(stdout); - -cleanup: - ASN_STRUCT_FREE(asn_DEF_ManagementRequest, mreq); - ASN_STRUCT_FREE(asn_DEF_ManagementReply, mrep); - - return rv; -} - -int cam_gen(void* ctx) { - printf("Testing CAM generation:\n"); fflush(stdout); - - void* transport_socket = zmq_socket(ctx, ZMQ_REP); - - int rv = zmq_bind(transport_socket, "ipc:///tmp/itss/transport"); - uint8_t buffer[2048]; - zmq_recv(transport_socket, buffer, 2048, 0); - int code = 0; - zmq_send(transport_socket, &code, 1, 0); - - zmq_close(transport_socket); - - TransportRequest_t* tr = NULL; - asn_dec_rval_t dec = asn_decode(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportRequest, (void**) &tr, buffer+1, 2047); - if (dec.code) { - printf(" FAIL\n"); fflush(stdout); - return 1; - } - printf(" - Received CAM TR (%ldB)\n", tr->choice.packet.choice.btp.data.size); fflush(stdout); - - if (tr->choice.packet.choice.btp.destinationPort == Port_cam) { - printf(" OK\n"); fflush(stdout); - } else { - printf(" FAIL\n"); fflush(stdout); - return 1; - } - - return 0; -} - - -int forward_up(void* ctx) { - printf("Testing forwarding up:\n"); fflush(stdout); - - TransportIndication_t* ti = calloc(1, sizeof(TransportIndication_t)); - ti->present = TransportIndication_PR_packet; - ti->choice.packet.present = TransportPacketIndication_PR_btp; - BTPPacketIndication_t* bpi = &ti->choice.packet.choice.btp; - - char* cam_hex = "02027dfddf4403ca4059bba5f38cc40dba9ffffffc2230eff200e11fc0078082a88a8337fee3fff600004dffea800618d08018efff14003ac68800c77ff8e002263460063bffd1000fb1a30031dffe2800958d30018efff840048c68800c77ffae002c63480063bffbd001a31a40031dfff28002d8cf0018c0"; - - uint8_t* cam; - uint16_t cam_len; - hex2bin(cam_hex, &cam, &cam_len); - - bpi->data.buf = cam; - bpi->data.size = cam_len; - bpi->gn.destinationAddress.buf = calloc(1, 6); - bpi->gn.destinationAddress.size = 6; - bpi->destinationPort = Port_cam; - - uint8_t b_ti_cam[512]; - b_ti_cam[0] = 3; - - asn_enc_rval_t enc = asn_encode_to_buffer(NULL, ATS_CANONICAL_OER, &asn_DEF_TransportIndication, ti, b_ti_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_ti_cam, enc.encoded+1, 0); - zmq_recv(facilities_socket, &code, 1, 0); - if (code) { - printf(" FAIL\n"); fflush(stdout); - return 1; - } - printf(" - Sent CAM TI (%ldB)\n", bpi->data.size); fflush(stdout); - - 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); - - FacilitiesIndication_t* fi = NULL; - asn_dec_rval_t dec = asn_decode(NULL, ATS_CANONICAL_OER, &asn_DEF_FacilitiesIndication, (void**) &fi, buffer+1, 2047); - if (dec.code) { - printf(" FAIL\n"); fflush(stdout); - return 1; - } - printf(" - Received CAM FI (%ldB)\n", fi->choice.message.data.size); fflush(stdout); - - if (fi->choice.message.data.size == bpi->data.size) { - printf(" OK\n"); fflush(stdout); - } else { - printf(" FAIL\n"); fflush(stdout); - return 1; - } - - return 0; -} - - -int main() { - - int rv = 0; - - void* ctx = zmq_ctx_new(); - - rv += init(ctx); - if (rv) return 1; - - rv += forward_up(ctx); - //rv += cam_gen(ctx); - - return rv; -} -