Skip to content

Commit

Permalink
selftests/bpf: Adjust BPF selftest for xdp_adjust_tail
Browse files Browse the repository at this point in the history
Current selftest for BPF-helper xdp_adjust_tail only shrink tail.
Make it more clear that this is a shrink test case.

Signed-off-by: Jesper Dangaard Brouer <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
Link: https://lore.kernel.org/bpf/158945350058.97035.17280775016196207372.stgit@firesoul
  • Loading branch information
netoptimizer authored and Alexei Starovoitov committed May 15, 2020
1 parent bc56c91 commit 68545fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 7 additions & 2 deletions tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#include <test_progs.h>
#include <network_helpers.h>

void test_xdp_adjust_tail(void)
void test_xdp_adjust_tail_shrink(void)
{
const char *file = "./test_adjust_tail.o";
const char *file = "./test_xdp_adjust_tail_shrink.o";
struct bpf_object *obj;
char buf[128];
__u32 duration, retval, size;
Expand All @@ -28,3 +28,8 @@ void test_xdp_adjust_tail(void)
err, errno, retval, size);
bpf_object__close(obj);
}

void test_xdp_adjust_tail(void)
{
test_xdp_adjust_tail_shrink();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-2.0
* Copyright (c) 2018 Facebook
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2018 Facebook
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
Expand All @@ -11,15 +11,15 @@

int _version SEC("version") = 1;

SEC("xdp_adjust_tail")
int _xdp_adjust_tail(struct xdp_md *xdp)
SEC("xdp_adjust_tail_shrink")
int _xdp_adjust_tail_shrink(struct xdp_md *xdp)
{
void *data_end = (void *)(long)xdp->data_end;
void *data = (void *)(long)xdp->data;
int offset = 0;

if (data_end - data == 54)
offset = 256;
if (data_end - data == 54) /* sizeof(pkt_v4) */
offset = 256; /* shrink too much */
else
offset = 20;
if (bpf_xdp_adjust_tail(xdp, 0 - offset))
Expand Down

0 comments on commit 68545fb

Please sign in to comment.