Skip to content

Commit

Permalink
selftests/xsk: use ksft_print_msg uniformly
Browse files Browse the repository at this point in the history
Use ksft_print_msg() instead of printf() and fprintf() in all places
as the ksefltests framework is being used. There is only one exception
and that is for the list-of-tests print out option, since no tests are
run in that case.

Signed-off-by: Magnus Karlsson <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>
  • Loading branch information
magnus-karlsson authored and Alexei Starovoitov committed Sep 14, 2023
1 parent 146e305 commit 7c3fcf0
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions tools/testing/selftests/bpf/xskxceiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ static void pkt_print_data(u32 *data, u32 cnt)

seqnum = ntohl(*data) & 0xffff;
pkt_nb = ntohl(*data) >> 16;
fprintf(stdout, "%u:%u ", pkt_nb, seqnum);
ksft_print_msg("%u:%u ", pkt_nb, seqnum);
data++;
}
}
Expand All @@ -820,29 +820,29 @@ static void pkt_dump(void *pkt, u32 len, bool eth_header)

if (eth_header) {
/*extract L2 frame */
fprintf(stdout, "DEBUG>> L2: dst mac: ");
ksft_print_msg("DEBUG>> L2: dst mac: ");
for (i = 0; i < ETH_ALEN; i++)
fprintf(stdout, "%02X", ethhdr->h_dest[i]);
ksft_print_msg("%02X", ethhdr->h_dest[i]);

fprintf(stdout, "\nDEBUG>> L2: src mac: ");
ksft_print_msg("\nDEBUG>> L2: src mac: ");
for (i = 0; i < ETH_ALEN; i++)
fprintf(stdout, "%02X", ethhdr->h_source[i]);
ksft_print_msg("%02X", ethhdr->h_source[i]);

data = pkt + PKT_HDR_SIZE;
} else {
data = pkt;
}

/*extract L5 frame */
fprintf(stdout, "\nDEBUG>> L5: seqnum: ");
ksft_print_msg("\nDEBUG>> L5: seqnum: ");
pkt_print_data(data, PKT_DUMP_NB_TO_PRINT);
fprintf(stdout, "....");
ksft_print_msg("....");
if (len > PKT_DUMP_NB_TO_PRINT * sizeof(u32)) {
fprintf(stdout, "\n.... ");
ksft_print_msg("\n.... ");
pkt_print_data(data + len / sizeof(u32) - PKT_DUMP_NB_TO_PRINT,
PKT_DUMP_NB_TO_PRINT);
}
fprintf(stdout, "\n---------------------------------------\n");
ksft_print_msg("\n---------------------------------------\n");
}

static bool is_offset_correct(struct xsk_umem_info *umem, struct pkt *pkt, u64 addr)
Expand Down Expand Up @@ -1553,7 +1553,8 @@ static void *worker_testapp_validate_rx(void *arg)
xsk_clear_xskmap(ifobject->xskmap);
err = xsk_update_xskmap(ifobject->xskmap, ifobject->xsk->xsk);
if (err) {
printf("Error: Failed to update xskmap, error %s\n", strerror(-err));
ksft_print_msg("Error: Failed to update xskmap, error %s\n",
strerror(-err));
exit_with_error(-err);
}
}
Expand Down Expand Up @@ -1617,7 +1618,7 @@ static void xsk_reattach_xdp(struct ifobject *ifobj, struct bpf_program *xdp_pro
xsk_detach_xdp_program(ifobj->ifindex, mode_to_xdp_flags(ifobj->mode));
err = xsk_attach_xdp_program(xdp_prog, ifobj->ifindex, mode_to_xdp_flags(mode));
if (err) {
printf("Error attaching XDP program\n");
ksft_print_msg("Error attaching XDP program\n");
exit_with_error(-err);
}

Expand Down Expand Up @@ -2104,7 +2105,7 @@ static void init_iface(struct ifobject *ifobj, const char *dst_mac, const char *

err = xsk_load_xdp_programs(ifobj);
if (err) {
printf("Error loading XDP program\n");
ksft_print_msg("Error loading XDP program\n");
exit_with_error(err);
}

Expand Down

0 comments on commit 7c3fcf0

Please sign in to comment.