Skip to content

Commit

Permalink
sys/linux/test: test case for bpf_tail_call helper
Browse files Browse the repository at this point in the history
This test case corresponds to the BPF program below (bcc syntax for the
map).

    BPF_PROG_ARRAY(prog_array, 10);
    int tail_call_prog(void *ctx) {
        char str[8] = {0};
        u64 data = 0x1234;
        bpf_snprintf(str, sizeof(str), "%d     ", &data, sizeof(data));
        return 0;
    }
    int do_tail_call(void *ctx) {
        prog_array.call(ctx, 0);
        return 0;
    }

It reuses the program defined to test bpf_snprintf, as the target of the
tail call.

Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
  • Loading branch information
pchaigno authored and a-nogikh committed Nov 6, 2023
1 parent b1547b1 commit 8321139
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sys/linux/test/bpf_helpers
Expand Up @@ -13,3 +13,10 @@ r3 = bpf$BPF_MAP_CONST_STR_FREEZE(AUTO, &AUTO={r1, r1}, 0x4)
r4 = bpf$PROG_LOAD(AUTO, &AUTO={0x3, AUTO, &AUTO=@framed={{AUTO, AUTO, AUTO, AUTO, 0x0, AUTO, AUTO, AUTO, 0x0}, [@snprintf={{AUTO, AUTO, AUTO, AUTO, AUTO, AUTO, AUTO}, {AUTO, AUTO, AUTO, AUTO, AUTO, AUTO, AUTO}, {AUTO, AUTO, AUTO, AUTO, AUTO, AUTO, 0x1234}, {AUTO, AUTO, AUTO, AUTO, AUTO, AUTO, AUTO}, {AUTO, AUTO, AUTO, AUTO, AUTO, AUTO, AUTO}, {AUTO, AUTO, AUTO, AUTO, AUTO, AUTO, AUTO}, {AUTO, AUTO, AUTO, AUTO, AUTO, AUTO, AUTO}, {AUTO, AUTO, AUTO, AUTO, AUTO, AUTO, AUTO}, {AUTO, AUTO, AUTO, AUTO, AUTO, AUTO, AUTO}, {AUTO, AUTO, AUTO, AUTO, r1, AUTO, AUTO, AUTO, AUTO}, {AUTO, AUTO, AUTO, AUTO, AUTO, AUTO, AUTO}, {AUTO, AUTO, AUTO, AUTO}}], {AUTO, AUTO, AUTO, AUTO}}, &AUTO='GPL\x00', 0x0, 0x0, 0x0, 0x0, 0x0, "00000000000000000000000000000000", 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 0xa0)

r5 = bpf$BPF_PROG_TEST_RUN(AUTO, &AUTO={r4, AUTO, 0x10, 0x10, &AUTO="0000000000000000", &AUTO="0000000000000000", 0x1, AUTO, 0x0, 0x0, 0x0, 0x0, 0x0, AUTO, 0x0}, 0x4c)

# Prepare, load, and execute a BPF program that performs a tail call to the bpf_snprintf program.

r10 = bpf$MAP_CREATE_TAIL_CALL(AUTO, &AUTO={AUTO, AUTO, AUTO, AUTO, AUTO, 0x0, 0x0, "00000000000000000000000000000000", 0x0, 0x0, 0x0, 0x0, 0x0, AUTO}, 0x48)
r11 = bpf$MAP_UPDATE_ELEM_TAIL_CALL(AUTO, &AUTO={{r10, r10}, &AUTO=0x0, &AUTO=r4, AUTO}, 0x1c)

r4 = bpf$PROG_LOAD(AUTO, &AUTO={0x3, AUTO, &AUTO=@framed={{AUTO, AUTO, AUTO, AUTO, 0x0, AUTO, AUTO, AUTO, 0x0}, [@tail_call={{AUTO, AUTO, AUTO, AUTO, r10, AUTO, AUTO, AUTO, AUTO}, {AUTO, AUTO, AUTO, AUTO, AUTO, AUTO, AUTO}, {AUTO, AUTO, AUTO, AUTO}, {AUTO, AUTO, AUTO, AUTO, AUTO, AUTO, AUTO}}], {AUTO, AUTO, AUTO, AUTO}}, &AUTO='GPL\x00', 0x0, 0x0, 0x0, 0x0, 0x0, "00000000000000000000000000000000", 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 0xa0)

0 comments on commit 8321139

Please sign in to comment.