canfdtest: return -1 if compare_frame fails
Do report errors from function compare_frame also on the exit-code. Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com>pull/354/head
parent
c70d0a8e61
commit
24de626f33
12
canfdtest.c
12
canfdtest.c
|
|
@ -117,9 +117,9 @@ static void print_compare(
|
||||||
print_frame(rec_id, rec_data, rec_dlc, 0);
|
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;
|
const canid_t expected_can_id = inc ? can_id_pong : can_id_ping;
|
||||||
|
|
||||||
if (rec->can_id != expected_can_id) {
|
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,
|
print_compare(expected_can_id, exp->data, exp->can_dlc,
|
||||||
rec->can_id, rec->data, rec->can_dlc, inc);
|
rec->can_id, rec->data, rec->can_dlc, inc);
|
||||||
running = 0;
|
running = 0;
|
||||||
|
err = -1;
|
||||||
} else if (rec->can_dlc != exp->can_dlc) {
|
} else if (rec->can_dlc != exp->can_dlc) {
|
||||||
printf("Message length mismatch!\n");
|
printf("Message length mismatch!\n");
|
||||||
print_compare(expected_can_id, exp->data, exp->can_dlc,
|
print_compare(expected_can_id, exp->data, exp->can_dlc,
|
||||||
rec->can_id, rec->data, rec->can_dlc, inc);
|
rec->can_id, rec->data, rec->can_dlc, inc);
|
||||||
running = 0;
|
running = 0;
|
||||||
|
err = -1;
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < rec->can_dlc; i++) {
|
for (i = 0; i < rec->can_dlc; i++) {
|
||||||
if (rec->data[i] != (uint8_t)(exp->data[i] + inc)) {
|
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,
|
print_compare(expected_can_id, exp->data, exp->can_dlc,
|
||||||
rec->can_id, rec->data, rec->can_dlc, inc);
|
rec->can_id, rec->data, rec->can_dlc, inc);
|
||||||
running = 0;
|
running = 0;
|
||||||
|
err = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void millisleep(int msecs)
|
static void millisleep(int msecs)
|
||||||
|
|
@ -346,7 +350,7 @@ static int can_echo_gen(void)
|
||||||
|
|
||||||
/* own frame */
|
/* own frame */
|
||||||
if (rx_frame.can_id == can_id_ping) {
|
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[recv_tx_pos] = 1;
|
||||||
recv_tx_pos++;
|
recv_tx_pos++;
|
||||||
if (recv_tx_pos == inflight_count)
|
if (recv_tx_pos == inflight_count)
|
||||||
|
|
@ -360,7 +364,7 @@ static int can_echo_gen(void)
|
||||||
running = 0;
|
running = 0;
|
||||||
}
|
}
|
||||||
/* compare with expected */
|
/* 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++;
|
recv_rx_pos++;
|
||||||
if (recv_rx_pos == inflight_count)
|
if (recv_rx_pos == inflight_count)
|
||||||
recv_rx_pos = 0;
|
recv_rx_pos = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue