|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
| 2 | +/* Copyright (c) 2019 Facebook */ |
| 3 | +#include <test_progs.h> |
| 4 | +#include "bpf/libbpf_internal.h" |
| 5 | +#include "test_raw_tp_test_run.skel.h" |
| 6 | + |
| 7 | +static int duration; |
| 8 | + |
| 9 | +void test_raw_tp_test_run(void) |
| 10 | +{ |
| 11 | + struct bpf_prog_test_run_attr test_attr = {}; |
| 12 | + __u64 args[2] = {0x1234ULL, 0x5678ULL}; |
| 13 | + int comm_fd = -1, err, nr_online, i; |
| 14 | + int expected_retval = 0x1234 + 0x5678; |
| 15 | + struct test_raw_tp_test_run *skel; |
| 16 | + char buf[] = "new_name"; |
| 17 | + bool *online = NULL; |
| 18 | + |
| 19 | + err = parse_cpu_mask_file("/sys/devices/system/cpu/online", &online, |
| 20 | + &nr_online); |
| 21 | + if (CHECK(err, "parse_cpu_mask_file", "err %d\n", err)) |
| 22 | + return; |
| 23 | + |
| 24 | + skel = test_raw_tp_test_run__open_and_load(); |
| 25 | + if (CHECK(!skel, "skel_open", "failed to open skeleton\n")) |
| 26 | + return; |
| 27 | + err = test_raw_tp_test_run__attach(skel); |
| 28 | + if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err)) |
| 29 | + goto cleanup; |
| 30 | + |
| 31 | + comm_fd = open("/proc/self/comm", O_WRONLY|O_TRUNC); |
| 32 | + if (CHECK(comm_fd < 0, "open /proc/self/comm", "err %d\n", errno)) |
| 33 | + goto cleanup; |
| 34 | + |
| 35 | + err = write(comm_fd, buf, sizeof(buf)); |
| 36 | + CHECK(err < 0, "task rename", "err %d", errno); |
| 37 | + |
| 38 | + CHECK(skel->bss->count == 0, "check_count", "didn't increase\n"); |
| 39 | + CHECK(skel->data->on_cpu != 0xffffffff, "check_on_cpu", "got wrong value\n"); |
| 40 | + |
| 41 | + test_attr.prog_fd = bpf_program__fd(skel->progs.rename); |
| 42 | + test_attr.ctx_in = args; |
| 43 | + test_attr.ctx_size_in = sizeof(__u64); |
| 44 | + |
| 45 | + err = bpf_prog_test_run_xattr(&test_attr); |
| 46 | + CHECK(err == 0, "test_run", "should fail for too small ctx\n"); |
| 47 | + |
| 48 | + test_attr.ctx_size_in = sizeof(args); |
| 49 | + err = bpf_prog_test_run_xattr(&test_attr); |
| 50 | + CHECK(err < 0, "test_run", "err %d\n", errno); |
| 51 | + CHECK(test_attr.retval != expected_retval, "check_retval", |
| 52 | + "expect 0x%x, got 0x%x\n", expected_retval, test_attr.retval); |
| 53 | + |
| 54 | + for (i = 0; i < nr_online; i++) |
| 55 | + if (online[i]) { |
| 56 | + DECLARE_LIBBPF_OPTS(bpf_prog_test_run_opts, opts, |
| 57 | + .cpu_plus = i + 1, |
| 58 | + ); |
| 59 | + |
| 60 | + test_attr.retval = 0; |
| 61 | + err = bpf_prog_test_run_xattr_opts(&test_attr, &opts); |
| 62 | + CHECK(err < 0, "test_run_with_opts", "err %d\n", errno); |
| 63 | + CHECK(skel->data->on_cpu != i, "check_on_cpu", |
| 64 | + "got wrong value\n"); |
| 65 | + CHECK(test_attr.retval != expected_retval, |
| 66 | + "check_retval", "expect 0x%x, got 0x%x\n", |
| 67 | + expected_retval, test_attr.retval); |
| 68 | + } |
| 69 | +cleanup: |
| 70 | + close(comm_fd); |
| 71 | + test_raw_tp_test_run__destroy(skel); |
| 72 | + free(online); |
| 73 | +} |
0 commit comments