Skip to content

Commit

Permalink
canfdtest: add support for loopback testing
Browse files Browse the repository at this point in the history
  • Loading branch information
marckleinebudde committed Jan 17, 2024
1 parent 78aeedf commit fc2aad8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions canfdtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static int sockfd;
static int test_loops;
static int exit_sig;
static int inflight_count = CAN_MSG_COUNT;
static int filter;
static canid_t can_id_ping = CAN_MSG_ID_PING;
static canid_t can_id_pong = CAN_MSG_ID_PONG;
static bool has_pong_id;
Expand Down Expand Up @@ -80,6 +81,7 @@ static void print_usage(char *prg)
" -v (low verbosity)\n"
" -vv (high verbosity)\n"
" -x (ignore other frames on bus)\n"
" -xx (ignore locally generated and other frames on bus -- use for loopback testing)\n"
"\n"
"With the option '-g' CAN messages are generated and checked\n"
"on <can-interface>, otherwise all messages received on the\n"
Expand Down Expand Up @@ -304,8 +306,14 @@ static int can_echo_dut(void)
int err = 0;

while (running) {
if (recv_frame(&frame, NULL))
int flags;

if (recv_frame(&frame, &flags))
return -1;

if (filter > 1 && flags & MSG_DONTROUTE)
continue;

frame_count++;
if (verbose == 1) {
echo_progress(frame.data[0]);
Expand Down Expand Up @@ -387,6 +395,11 @@ static int can_echo_gen(void)
goto out_free;
}

if (filter > 1 &&
((rx_frame.can_id == can_id_ping && !(flags & MSG_CONFIRM)) ||
(rx_frame.can_id == can_id_pong && (flags & MSG_DONTROUTE))))
continue;

if (verbose > 1)
print_frame(rx_frame.can_id, rx_frame.data, rx_frame.len, 0);

Expand Down Expand Up @@ -435,7 +448,6 @@ int main(int argc, char *argv[])
int echo_gen = 0;
int opt, err;
int enable_socket_option = 1;
bool filter = false;

signal(SIGTERM, signal_handler);
signal(SIGHUP, signal_handler);
Expand Down Expand Up @@ -485,7 +497,7 @@ int main(int argc, char *argv[])
break;

case 'x':
filter = true;
filter++;
break;

case '?':
Expand Down

0 comments on commit fc2aad8

Please sign in to comment.