Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Migrate BPF_CGROUP_INET_SOCK_CREATE test cases to prog_tests

Move the "load w/o expected_attach_type" test case to
prog_tests/sock_create.c and drop the remaining test case, as it is made
redundant with the existing coverage inside prog_tests/sock_create.c.

Signed-off-by: Jordan Rife <jrife@google.com>
Link: https://lore.kernel.org/r/20241022152913.574836-4-jrife@google.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>

authored by

Jordan Rife and committed by
Martin KaFai Lau
af522f13 c17f9734

+24 -37
+24 -9
tools/testing/selftests/bpf/prog_tests/sock_create.c
··· 237 237 238 238 .error = DENY_CREATE, 239 239 }, 240 + { 241 + .descr = "load w/o expected_attach_type (compat mode)", 242 + .insns = { 243 + /* return 1 */ 244 + BPF_MOV64_IMM(BPF_REG_0, 1), 245 + BPF_EXIT_INSN(), 246 + }, 247 + .expected_attach_type = 0, 248 + .attach_type = BPF_CGROUP_INET_SOCK_CREATE, 249 + 250 + .domain = AF_INET, 251 + .type = SOCK_STREAM, 252 + }, 240 253 }; 241 254 242 255 static int load_prog(const struct bpf_insn *insns, ··· 304 291 goto detach_prog; 305 292 } 306 293 307 - err = getsockopt(sock_fd, SOL_SOCKET, test->optname, &optval, &optlen); 308 - if (err) { 309 - log_err("Failed to call getsockopt"); 310 - goto cleanup; 311 - } 294 + if (test->optname) { 295 + err = getsockopt(sock_fd, SOL_SOCKET, test->optname, &optval, &optlen); 296 + if (err) { 297 + log_err("Failed to call getsockopt"); 298 + goto cleanup; 299 + } 312 300 313 - if (optval != test->optval) { 314 - errno = 0; 315 - log_err("getsockopt returned unexpected optval"); 316 - goto cleanup; 301 + if (optval != test->optval) { 302 + errno = 0; 303 + log_err("getsockopt returned unexpected optval"); 304 + goto cleanup; 305 + } 317 306 } 318 307 319 308 ret = test->error != OK;
-28
tools/testing/selftests/bpf/test_sock.c
··· 47 47 }; 48 48 49 49 static struct sock_test tests[] = { 50 - { 51 - .descr = "sock_create load w/o expected_attach_type (compat mode)", 52 - .insns = { 53 - BPF_MOV64_IMM(BPF_REG_0, 1), 54 - BPF_EXIT_INSN(), 55 - }, 56 - .expected_attach_type = 0, 57 - .attach_type = BPF_CGROUP_INET_SOCK_CREATE, 58 - .domain = AF_INET, 59 - .type = SOCK_STREAM, 60 - .ip = "127.0.0.1", 61 - .port = 8097, 62 - .result = SUCCESS, 63 - }, 64 - { 65 - .descr = "sock_create load w/ expected_attach_type", 66 - .insns = { 67 - BPF_MOV64_IMM(BPF_REG_0, 1), 68 - BPF_EXIT_INSN(), 69 - }, 70 - .expected_attach_type = BPF_CGROUP_INET_SOCK_CREATE, 71 - .attach_type = BPF_CGROUP_INET_SOCK_CREATE, 72 - .domain = AF_INET, 73 - .type = SOCK_STREAM, 74 - .ip = "127.0.0.1", 75 - .port = 8097, 76 - .result = SUCCESS, 77 - }, 78 50 }; 79 51 80 52 static size_t probe_prog_length(const struct bpf_insn *fp)