From 24de626f33ca6ff4227343c0a0438442c031645f Mon Sep 17 00:00:00 2001 From: Philippe Schenker Date: Tue, 12 Apr 2022 14:54:36 +0200 Subject: [PATCH] canfdtest: return -1 if compare_frame fails Do report errors from function compare_frame also on the exit-code. Signed-off-by: Philippe Schenker --- canfdtest.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/canfdtest.c b/canfdtest.c index da2178f..c8d407e 100644 --- a/canfdtest.c +++ b/canfdtest.c @@ -117,9 +117,9 @@ static void print_compare( print_frame(rec_id, rec_data, rec_dlc, 0); } -static void compare_frame(const struct can_frame *exp, const struct can_frame *rec, int inc) +static int compare_frame(const struct can_frame *exp, const struct can_frame *rec, int inc) { - int i; + int i, err = 0; const canid_t expected_can_id = inc ? can_id_pong : can_id_ping; if (rec->can_id != expected_can_id) { @@ -127,11 +127,13 @@ static void compare_frame(const struct can_frame *exp, const struct can_frame *r print_compare(expected_can_id, exp->data, exp->can_dlc, rec->can_id, rec->data, rec->can_dlc, inc); running = 0; + err = -1; } else if (rec->can_dlc != exp->can_dlc) { printf("Message length mismatch!\n"); print_compare(expected_can_id, exp->data, exp->can_dlc, rec->can_id, rec->data, rec->can_dlc, inc); running = 0; + err = -1; } else { for (i = 0; i < rec->can_dlc; i++) { if (rec->data[i] != (uint8_t)(exp->data[i] + inc)) { @@ -139,9 +141,11 @@ static void compare_frame(const struct can_frame *exp, const struct can_frame *r print_compare(expected_can_id, exp->data, exp->can_dlc, rec->can_id, rec->data, rec->can_dlc, inc); running = 0; + err = -1; } } } + return err; } static void millisleep(int msecs) @@ -346,7 +350,7 @@ static int can_echo_gen(void) /* own frame */ if (rx_frame.can_id == can_id_ping) { - compare_frame(&tx_frames[recv_tx_pos], &rx_frame, 0); + err = compare_frame(&tx_frames[recv_tx_pos], &rx_frame, 0); recv_tx[recv_tx_pos] = 1; recv_tx_pos++; if (recv_tx_pos == inflight_count) @@ -360,7 +364,7 @@ static int can_echo_gen(void) running = 0; } /* compare with expected */ - compare_frame(&tx_frames[recv_rx_pos], &rx_frame, 1); + err = compare_frame(&tx_frames[recv_rx_pos], &rx_frame, 1); recv_rx_pos++; if (recv_rx_pos == inflight_count) recv_rx_pos = 0;