hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/tools/testing/selftests/bpf/test_sock.c
....@@ -13,7 +13,7 @@
1313 #include <bpf/bpf.h>
1414
1515 #include "cgroup_helpers.h"
16
-#include "bpf_endian.h"
16
+#include <bpf/bpf_endian.h>
1717 #include "bpf_rlimit.h"
1818 #include "bpf_util.h"
1919
....@@ -21,6 +21,7 @@
2121 #define MAX_INSNS 512
2222
2323 char bpf_log_buf[BPF_LOG_BUF_SIZE];
24
+static bool verbose = false;
2425
2526 struct sock_test {
2627 const char *descr;
....@@ -328,6 +329,7 @@
328329 enum bpf_attach_type attach_type)
329330 {
330331 struct bpf_load_program_attr attr;
332
+ int ret;
331333
332334 memset(&attr, 0, sizeof(struct bpf_load_program_attr));
333335 attr.prog_type = BPF_PROG_TYPE_CGROUP_SOCK;
....@@ -335,8 +337,13 @@
335337 attr.insns = prog;
336338 attr.insns_cnt = probe_prog_length(attr.insns);
337339 attr.license = "GPL";
340
+ attr.log_level = 2;
338341
339
- return bpf_load_program_xattr(&attr, bpf_log_buf, BPF_LOG_BUF_SIZE);
342
+ ret = bpf_load_program_xattr(&attr, bpf_log_buf, BPF_LOG_BUF_SIZE);
343
+ if (verbose && ret < 0)
344
+ fprintf(stderr, "%s\n", bpf_log_buf);
345
+
346
+ return ret;
340347 }
341348
342349 static int attach_sock_prog(int cgfd, int progfd,
....@@ -457,14 +464,8 @@
457464 int cgfd = -1;
458465 int err = 0;
459466
460
- if (setup_cgroup_environment())
461
- goto err;
462
-
463
- cgfd = create_and_get_cgroup(CG_PATH);
464
- if (!cgfd)
465
- goto err;
466
-
467
- if (join_cgroup(CG_PATH))
467
+ cgfd = cgroup_setup_and_join(CG_PATH);
468
+ if (cgfd < 0)
468469 goto err;
469470
470471 if (run_tests(cgfd))