Skip to content

Commit

Permalink
libxdp: Use opts-style API to create umem in libxdp tests
Browse files Browse the repository at this point in the history
Signed-off-by: Muyang Tian <tianmuyang@huawei.com>
  • Loading branch information
tacslon authored and tohojo committed Jan 9, 2025
1 parent 794e49d commit e4df54b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
30 changes: 19 additions & 11 deletions lib/libxdp/tests/test_xsk_non_privileged.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ static void run_non_privileged_preconfig(const char *ifname,

static struct xsk_umem *create_umem_non_privileged(int sock_fd)
{
struct xsk_umem_config config = {
.fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
.comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
.frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE,
};
struct xsk_umem *umem = NULL;
struct xsk_ring_cons cq;
struct xsk_ring_prod fq;
Expand All @@ -107,16 +102,29 @@ static struct xsk_umem *create_umem_non_privileged(int sock_fd)
}

/* This variant requires CAP_NET_RAW, so should fail. */
if (!xsk_umem__create(&umem, b, UMEM_SIZE,
&fq, &cq, &config) || umem) {
perror("xsk_umem__create succeeded");
DECLARE_LIBXDP_OPTS(xsk_umem_opts, opts_cap,
.size = UMEM_SIZE,
.fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
.comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
.frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE,
);
umem = xsk_umem__create_opts(b, &fq, &cq, &opts_cap);
if (umem) {
perror("xsk_umem__create_opts succeeded");
exit(EXIT_FAILURE);
}

/* This variant shouldn't need any capabilities, so should pass. */
if (xsk_umem__create_with_fd(&umem, sock_fd, b, UMEM_SIZE,
&fq, &cq, &config) || !umem) {
perror("xsk_umem__create_with_fd failed");
DECLARE_LIBXDP_OPTS(xsk_umem_opts, opts,
.fd = sock_fd,
.size = UMEM_SIZE,
.fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
.comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
.frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE,
);
umem = xsk_umem__create_opts(b, &fq, &cq, &opts);
if (!umem) {
perror("xsk_umem__create_opts failed");
exit(EXIT_FAILURE);
}

Expand Down
11 changes: 6 additions & 5 deletions lib/libxdp/tests/test_xsk_refcnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,17 @@ static struct xsk_socket_info *xsks[MAX_NUM_QUEUES];
static struct xsk_umem_info *xsk_configure_umem(void *buffer, u64 size)
{
struct xsk_umem_info *umem;
int ret;

umem = calloc(1, sizeof(*umem));
if (!umem)
exit(EXIT_FAILURE);

ret = xsk_umem__create(&umem->umem, buffer, size, &umem->fq, &umem->cq,
NULL);
if (ret)
exit(ret);
DECLARE_LIBXDP_OPTS(xsk_umem_opts, opts,
.size = size,
);
umem->umem = xsk_umem__create_opts(buffer, &umem->fq, &umem->cq, &opts);
if (!umem->umem)
exit(errno);

umem->buffer = buffer;
return umem;
Expand Down

0 comments on commit e4df54b

Please sign in to comment.