From cbf11a0931793dcd6cd288a0bda71de950bd776e Mon Sep 17 00:00:00 2001 From: muehlke Date: Wed, 13 Nov 2024 12:47:25 +0100 Subject: [PATCH 1/2] test: add new helper function to run a certain amount of millis on an specific registered tp --- test/env.c | 18 +++++++++++++++++- test/env.h | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/test/env.c b/test/env.c index f70c8d3..6852481 100644 --- a/test/env.c +++ b/test/env.c @@ -100,6 +100,22 @@ void ENV_RunMillis(uint32_t millis) { } } +void ENV_RunMillisForTpRegisteredAt(uint32_t millis, unsigned at) { + uint32_t end = UDSMillis() + millis; + while (UDSMillis() < end) { + assert(at >= 0 && at < MAX_NUM_TP); + + UDSTpPoll(registeredTps[at]); + TimeNowMillis++; + + // uses vcan, needs delay + if (IsNetworkedTransport(opts.tp_type)) { + // usleep(10); + msleep(1); + } + } +} + UDSTpHandle_t *ENV_TpNew(const char *name) { ENV_ParseOpts(); UDSTpHandle_t *tp = NULL; @@ -183,4 +199,4 @@ void ENV_TpFree(UDSTpHandle_t *tp) { } } -const ENV_Opts_t *ENV_GetOpts() { return &opts; } \ No newline at end of file +const ENV_Opts_t *ENV_GetOpts() { return &opts; } diff --git a/test/env.h b/test/env.h index 993609e..146b3c7 100644 --- a/test/env.h +++ b/test/env.h @@ -42,6 +42,7 @@ void ENV_TpFree(UDSTpHandle_t *tp); void ENV_RegisterServer(UDSServer_t *server); void ENV_RegisterClient(UDSClient_t *client); void ENV_RunMillis(uint32_t millis); +void ENV_RunMillisForTpRegisteredAt(uint32_t millis, unsigned at); const ENV_Opts_t *ENV_GetOpts(); #endif From fca519f85aef6a20f5b02a28358f2a63af20dfed Mon Sep 17 00:00:00 2001 From: muehlke Date: Wed, 13 Nov 2024 12:48:09 +0100 Subject: [PATCH 2/2] test: adapt tp compliance test to check FC timeout error on both tp implementations (isotp_sock and isotp_c) --- test/test_tp_compliance.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/test/test_tp_compliance.c b/test/test_tp_compliance.c index fddee30..0762437 100644 --- a/test/test_tp_compliance.c +++ b/test/test_tp_compliance.c @@ -100,16 +100,36 @@ void TestISOTPFlowControlFrameTimeout(void **state) { skip(); } - // killing server so that no response is sent to client - ENV_TpFree(srv); + int tp_type = ENV_GetOpts()->tp_type; + if (tp_type == ENV_TP_TYPE_ISOTP_SOCK){ + // killing server if using ISOTP sockets so that no response is sent to client + ENV_TpFree(srv); + } // sending multiframe to wait for Flow Control frame // which will not arrive since no server is running const uint8_t MSG[] = {1, 2, 3, 4, 5, 6, 7, 8}; ssize_t ret = UDSTpSend(client, MSG, sizeof(MSG), NULL); - // failure is expected as the elapsed 1s timeout raises an error on the ISOTP socket - assert_true(ret < 0); + tp_type = ENV_GetOpts()->tp_type; + if (tp_type == ENV_TP_TYPE_ISOTPC) { + // running poll just for the client to simulate the server not responding + ENV_RunMillisForTpRegisteredAt(1500, 1); + assert(((UDSTpISOTpC_t *)client)->phys_link.send_protocol_result == ISOTP_PROTOCOL_RESULT_TIMEOUT_BS); + assert(((UDSTpISOTpC_t *)client)->phys_link.send_status == ISOTP_SEND_STATUS_ERROR); + } else if (tp_type == ENV_TP_TYPE_ISOTP_SOCK) { + // failure is expected as the elapsed 1s timeout raises an error on the ISOTP socket + assert_true(ret < 0); + } else { + // do no test anything + } + + tp_type = ENV_GetOpts()->tp_type; + if (tp_type == ENV_TP_TYPE_ISOTP_SOCK){ + // reinitialize the server so the teardown function does not fail because + // of calling free() twice on the server sockets + srv = ENV_TpNew("server"); + } } int main() {