diff mbox series

[bpf-next] selftests/bpf: Add additional mprog query test coverage

Message ID 20231017081728.24769-1-daniel@iogearbox.net (mailing list archive)
State Accepted
Commit 24516309e330cd592c04d0467313d885584af4e8
Delegated to: BPF
Headers show
Series [bpf-next] selftests/bpf: Add additional mprog query test coverage | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/cc_maintainers warning 12 maintainers not CCed: song@kernel.org ast@kernel.org mykolal@fb.com andrii@kernel.org yonghong.song@linux.dev jolsa@kernel.org kpsingh@kernel.org john.fastabend@gmail.com shuah@kernel.org linux-kselftest@vger.kernel.org sdf@google.com haoluo@google.com
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 9 this patch: 9
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 143 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-0 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-1 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-5 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-6 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for veristat
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-12 fail Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_verifier on x86_64 with llvm-16

Commit Message

Daniel Borkmann Oct. 17, 2023, 8:17 a.m. UTC
Add several new test cases which assert corner cases on the mprog query
mechanism, for example, around passing in a too small or a larger array
than the current count.

  ./test_progs -t tc_opts
  #252     tc_opts_after:OK
  #253     tc_opts_append:OK
  #254     tc_opts_basic:OK
  #255     tc_opts_before:OK
  #256     tc_opts_chain_classic:OK
  #257     tc_opts_chain_mixed:OK
  #258     tc_opts_delete_empty:OK
  #259     tc_opts_demixed:OK
  #260     tc_opts_detach:OK
  #261     tc_opts_detach_after:OK
  #262     tc_opts_detach_before:OK
  #263     tc_opts_dev_cleanup:OK
  #264     tc_opts_invalid:OK
  #265     tc_opts_max:OK
  #266     tc_opts_mixed:OK
  #267     tc_opts_prepend:OK
  #268     tc_opts_query:OK
  #269     tc_opts_query_attach:OK
  #270     tc_opts_replace:OK
  #271     tc_opts_revision:OK
  Summary: 20/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
---
 .../selftests/bpf/prog_tests/tc_opts.c        | 131 +++++++++++++++++-
 1 file changed, 130 insertions(+), 1 deletion(-)

Comments

Alan Maguire Oct. 17, 2023, 9:09 a.m. UTC | #1
On 17/10/2023 09:17, Daniel Borkmann wrote:
> Add several new test cases which assert corner cases on the mprog query
> mechanism, for example, around passing in a too small or a larger array
> than the current count.
> 
>   ./test_progs -t tc_opts
>   #252     tc_opts_after:OK
>   #253     tc_opts_append:OK
>   #254     tc_opts_basic:OK
>   #255     tc_opts_before:OK
>   #256     tc_opts_chain_classic:OK
>   #257     tc_opts_chain_mixed:OK
>   #258     tc_opts_delete_empty:OK
>   #259     tc_opts_demixed:OK
>   #260     tc_opts_detach:OK
>   #261     tc_opts_detach_after:OK
>   #262     tc_opts_detach_before:OK
>   #263     tc_opts_dev_cleanup:OK
>   #264     tc_opts_invalid:OK
>   #265     tc_opts_max:OK
>   #266     tc_opts_mixed:OK
>   #267     tc_opts_prepend:OK
>   #268     tc_opts_query:OK
>   #269     tc_opts_query_attach:OK
>   #270     tc_opts_replace:OK
>   #271     tc_opts_revision:OK
>   Summary: 20/0 PASSED, 0 SKIPPED, 0 FAILED
> 
> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

Looks like it does a great job of exercising the codepaths in
bpf_mprog_query()!

Reviewed-by: Alan Maguire <alan.maguire@oracle.com>

> ---
>  .../selftests/bpf/prog_tests/tc_opts.c        | 131 +++++++++++++++++-
>  1 file changed, 130 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/tc_opts.c b/tools/testing/selftests/bpf/prog_tests/tc_opts.c
> index ca506d2fcf58..51883ccb8020 100644
> --- a/tools/testing/selftests/bpf/prog_tests/tc_opts.c
> +++ b/tools/testing/selftests/bpf/prog_tests/tc_opts.c
> @@ -2471,7 +2471,7 @@ static void test_tc_opts_query_target(int target)
>  	__u32 fd1, fd2, fd3, fd4, id1, id2, id3, id4;
>  	struct test_tc_link *skel;
>  	union bpf_attr attr;
> -	__u32 prog_ids[5];
> +	__u32 prog_ids[10];
>  	int err;
>  
>  	skel = test_tc_link__open_and_load();
> @@ -2599,6 +2599,135 @@ static void test_tc_opts_query_target(int target)
>  	ASSERT_EQ(attr.query.link_ids, 0, "link_ids");
>  	ASSERT_EQ(attr.query.link_attach_flags, 0, "link_attach_flags");
>  
> +	/* Test 3: Query with smaller prog_ids array */
> +	memset(&attr, 0, attr_size);
> +	attr.query.target_ifindex = loopback;
> +	attr.query.attach_type = target;
> +
> +	memset(prog_ids, 0, sizeof(prog_ids));
> +	attr.query.prog_ids = ptr_to_u64(prog_ids);
> +	attr.query.count = 2;
> +
> +	err = syscall(__NR_bpf, BPF_PROG_QUERY, &attr, attr_size);
> +	ASSERT_EQ(err, -1, "prog_query_should_fail");
> +	ASSERT_EQ(errno, ENOSPC, "prog_query_should_fail");
> +
> +	ASSERT_EQ(attr.query.count, 4, "count");
> +	ASSERT_EQ(attr.query.revision, 5, "revision");
> +	ASSERT_EQ(attr.query.query_flags, 0, "query_flags");
> +	ASSERT_EQ(attr.query.attach_flags, 0, "attach_flags");
> +	ASSERT_EQ(attr.query.target_ifindex, loopback, "target_ifindex");
> +	ASSERT_EQ(attr.query.attach_type, target, "attach_type");
> +	ASSERT_EQ(attr.query.prog_ids, ptr_to_u64(prog_ids), "prog_ids");
> +	ASSERT_EQ(prog_ids[0], id1, "prog_ids[0]");
> +	ASSERT_EQ(prog_ids[1], id2, "prog_ids[1]");
> +	ASSERT_EQ(prog_ids[2], 0, "prog_ids[2]");
> +	ASSERT_EQ(prog_ids[3], 0, "prog_ids[3]");
> +	ASSERT_EQ(prog_ids[4], 0, "prog_ids[4]");
> +	ASSERT_EQ(attr.query.prog_attach_flags, 0, "prog_attach_flags");
> +	ASSERT_EQ(attr.query.link_ids, 0, "link_ids");
> +	ASSERT_EQ(attr.query.link_attach_flags, 0, "link_attach_flags");
> +
> +	/* Test 4: Query with larger prog_ids array */
> +	memset(&attr, 0, attr_size);
> +	attr.query.target_ifindex = loopback;
> +	attr.query.attach_type = target;
> +
> +	memset(prog_ids, 0, sizeof(prog_ids));
> +	attr.query.prog_ids = ptr_to_u64(prog_ids);
> +	attr.query.count = 10;
> +
> +	err = syscall(__NR_bpf, BPF_PROG_QUERY, &attr, attr_size);
> +	if (!ASSERT_OK(err, "prog_query"))
> +		goto cleanup4;
> +
> +	ASSERT_EQ(attr.query.count, 4, "count");
> +	ASSERT_EQ(attr.query.revision, 5, "revision");
> +	ASSERT_EQ(attr.query.query_flags, 0, "query_flags");
> +	ASSERT_EQ(attr.query.attach_flags, 0, "attach_flags");
> +	ASSERT_EQ(attr.query.target_ifindex, loopback, "target_ifindex");
> +	ASSERT_EQ(attr.query.attach_type, target, "attach_type");
> +	ASSERT_EQ(attr.query.prog_ids, ptr_to_u64(prog_ids), "prog_ids");
> +	ASSERT_EQ(prog_ids[0], id1, "prog_ids[0]");
> +	ASSERT_EQ(prog_ids[1], id2, "prog_ids[1]");
> +	ASSERT_EQ(prog_ids[2], id3, "prog_ids[2]");
> +	ASSERT_EQ(prog_ids[3], id4, "prog_ids[3]");
> +	ASSERT_EQ(prog_ids[4], 0, "prog_ids[4]");
> +	ASSERT_EQ(attr.query.prog_attach_flags, 0, "prog_attach_flags");
> +	ASSERT_EQ(attr.query.link_ids, 0, "link_ids");
> +	ASSERT_EQ(attr.query.link_attach_flags, 0, "link_attach_flags");
> +
> +	/* Test 5: Query with NULL prog_ids array but with count > 0 */
> +	memset(&attr, 0, attr_size);
> +	attr.query.target_ifindex = loopback;
> +	attr.query.attach_type = target;
> +
> +	memset(prog_ids, 0, sizeof(prog_ids));
> +	attr.query.count = sizeof(prog_ids);
> +
> +	err = syscall(__NR_bpf, BPF_PROG_QUERY, &attr, attr_size);
> +	if (!ASSERT_OK(err, "prog_query"))
> +		goto cleanup4;
> +
> +	ASSERT_EQ(attr.query.count, 4, "count");
> +	ASSERT_EQ(attr.query.revision, 5, "revision");
> +	ASSERT_EQ(attr.query.query_flags, 0, "query_flags");
> +	ASSERT_EQ(attr.query.attach_flags, 0, "attach_flags");
> +	ASSERT_EQ(attr.query.target_ifindex, loopback, "target_ifindex");
> +	ASSERT_EQ(attr.query.attach_type, target, "attach_type");
> +	ASSERT_EQ(prog_ids[0], 0, "prog_ids[0]");
> +	ASSERT_EQ(prog_ids[1], 0, "prog_ids[1]");
> +	ASSERT_EQ(prog_ids[2], 0, "prog_ids[2]");
> +	ASSERT_EQ(prog_ids[3], 0, "prog_ids[3]");
> +	ASSERT_EQ(prog_ids[4], 0, "prog_ids[4]");
> +	ASSERT_EQ(attr.query.prog_ids, 0, "prog_ids");
> +	ASSERT_EQ(attr.query.prog_attach_flags, 0, "prog_attach_flags");
> +	ASSERT_EQ(attr.query.link_ids, 0, "link_ids");
> +	ASSERT_EQ(attr.query.link_attach_flags, 0, "link_attach_flags");
> +
> +	/* Test 6: Query with non-NULL prog_ids array but with count == 0 */
> +	memset(&attr, 0, attr_size);
> +	attr.query.target_ifindex = loopback;
> +	attr.query.attach_type = target;
> +
> +	memset(prog_ids, 0, sizeof(prog_ids));
> +	attr.query.prog_ids = ptr_to_u64(prog_ids);
> +
> +	err = syscall(__NR_bpf, BPF_PROG_QUERY, &attr, attr_size);
> +	if (!ASSERT_OK(err, "prog_query"))
> +		goto cleanup4;
> +
> +	ASSERT_EQ(attr.query.count, 4, "count");
> +	ASSERT_EQ(attr.query.revision, 5, "revision");
> +	ASSERT_EQ(attr.query.query_flags, 0, "query_flags");
> +	ASSERT_EQ(attr.query.attach_flags, 0, "attach_flags");
> +	ASSERT_EQ(attr.query.target_ifindex, loopback, "target_ifindex");
> +	ASSERT_EQ(attr.query.attach_type, target, "attach_type");
> +	ASSERT_EQ(prog_ids[0], 0, "prog_ids[0]");
> +	ASSERT_EQ(prog_ids[1], 0, "prog_ids[1]");
> +	ASSERT_EQ(prog_ids[2], 0, "prog_ids[2]");
> +	ASSERT_EQ(prog_ids[3], 0, "prog_ids[3]");
> +	ASSERT_EQ(prog_ids[4], 0, "prog_ids[4]");
> +	ASSERT_EQ(attr.query.prog_ids, ptr_to_u64(prog_ids), "prog_ids");
> +	ASSERT_EQ(attr.query.prog_attach_flags, 0, "prog_attach_flags");
> +	ASSERT_EQ(attr.query.link_ids, 0, "link_ids");
> +	ASSERT_EQ(attr.query.link_attach_flags, 0, "link_attach_flags");
> +
> +	/* Test 7: Query with invalid flags */
> +	attr.query.attach_flags = 0;
> +	attr.query.query_flags = 1;
> +
> +	err = syscall(__NR_bpf, BPF_PROG_QUERY, &attr, attr_size);
> +	ASSERT_EQ(err, -1, "prog_query_should_fail");
> +	ASSERT_EQ(errno, EINVAL, "prog_query_should_fail");
> +
> +	attr.query.attach_flags = 1;
> +	attr.query.query_flags = 0;
> +
> +	err = syscall(__NR_bpf, BPF_PROG_QUERY, &attr, attr_size);
> +	ASSERT_EQ(err, -1, "prog_query_should_fail");
> +	ASSERT_EQ(errno, EINVAL, "prog_query_should_fail");
> +
>  cleanup4:
>  	err = bpf_prog_detach_opts(fd4, loopback, target, &optd);
>  	ASSERT_OK(err, "prog_detach");
patchwork-bot+netdevbpf@kernel.org Oct. 17, 2023, 8 p.m. UTC | #2
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Tue, 17 Oct 2023 10:17:28 +0200 you wrote:
> Add several new test cases which assert corner cases on the mprog query
> mechanism, for example, around passing in a too small or a larger array
> than the current count.
> 
>   ./test_progs -t tc_opts
>   #252     tc_opts_after:OK
>   #253     tc_opts_append:OK
>   #254     tc_opts_basic:OK
>   #255     tc_opts_before:OK
>   #256     tc_opts_chain_classic:OK
>   #257     tc_opts_chain_mixed:OK
>   #258     tc_opts_delete_empty:OK
>   #259     tc_opts_demixed:OK
>   #260     tc_opts_detach:OK
>   #261     tc_opts_detach_after:OK
>   #262     tc_opts_detach_before:OK
>   #263     tc_opts_dev_cleanup:OK
>   #264     tc_opts_invalid:OK
>   #265     tc_opts_max:OK
>   #266     tc_opts_mixed:OK
>   #267     tc_opts_prepend:OK
>   #268     tc_opts_query:OK
>   #269     tc_opts_query_attach:OK
>   #270     tc_opts_replace:OK
>   #271     tc_opts_revision:OK
>   Summary: 20/0 PASSED, 0 SKIPPED, 0 FAILED
> 
> [...]

Here is the summary with links:
  - [bpf-next] selftests/bpf: Add additional mprog query test coverage
    https://git.kernel.org/bpf/bpf-next/c/24516309e330

You are awesome, thank you!
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/tc_opts.c b/tools/testing/selftests/bpf/prog_tests/tc_opts.c
index ca506d2fcf58..51883ccb8020 100644
--- a/tools/testing/selftests/bpf/prog_tests/tc_opts.c
+++ b/tools/testing/selftests/bpf/prog_tests/tc_opts.c
@@ -2471,7 +2471,7 @@  static void test_tc_opts_query_target(int target)
 	__u32 fd1, fd2, fd3, fd4, id1, id2, id3, id4;
 	struct test_tc_link *skel;
 	union bpf_attr attr;
-	__u32 prog_ids[5];
+	__u32 prog_ids[10];
 	int err;
 
 	skel = test_tc_link__open_and_load();
@@ -2599,6 +2599,135 @@  static void test_tc_opts_query_target(int target)
 	ASSERT_EQ(attr.query.link_ids, 0, "link_ids");
 	ASSERT_EQ(attr.query.link_attach_flags, 0, "link_attach_flags");
 
+	/* Test 3: Query with smaller prog_ids array */
+	memset(&attr, 0, attr_size);
+	attr.query.target_ifindex = loopback;
+	attr.query.attach_type = target;
+
+	memset(prog_ids, 0, sizeof(prog_ids));
+	attr.query.prog_ids = ptr_to_u64(prog_ids);
+	attr.query.count = 2;
+
+	err = syscall(__NR_bpf, BPF_PROG_QUERY, &attr, attr_size);
+	ASSERT_EQ(err, -1, "prog_query_should_fail");
+	ASSERT_EQ(errno, ENOSPC, "prog_query_should_fail");
+
+	ASSERT_EQ(attr.query.count, 4, "count");
+	ASSERT_EQ(attr.query.revision, 5, "revision");
+	ASSERT_EQ(attr.query.query_flags, 0, "query_flags");
+	ASSERT_EQ(attr.query.attach_flags, 0, "attach_flags");
+	ASSERT_EQ(attr.query.target_ifindex, loopback, "target_ifindex");
+	ASSERT_EQ(attr.query.attach_type, target, "attach_type");
+	ASSERT_EQ(attr.query.prog_ids, ptr_to_u64(prog_ids), "prog_ids");
+	ASSERT_EQ(prog_ids[0], id1, "prog_ids[0]");
+	ASSERT_EQ(prog_ids[1], id2, "prog_ids[1]");
+	ASSERT_EQ(prog_ids[2], 0, "prog_ids[2]");
+	ASSERT_EQ(prog_ids[3], 0, "prog_ids[3]");
+	ASSERT_EQ(prog_ids[4], 0, "prog_ids[4]");
+	ASSERT_EQ(attr.query.prog_attach_flags, 0, "prog_attach_flags");
+	ASSERT_EQ(attr.query.link_ids, 0, "link_ids");
+	ASSERT_EQ(attr.query.link_attach_flags, 0, "link_attach_flags");
+
+	/* Test 4: Query with larger prog_ids array */
+	memset(&attr, 0, attr_size);
+	attr.query.target_ifindex = loopback;
+	attr.query.attach_type = target;
+
+	memset(prog_ids, 0, sizeof(prog_ids));
+	attr.query.prog_ids = ptr_to_u64(prog_ids);
+	attr.query.count = 10;
+
+	err = syscall(__NR_bpf, BPF_PROG_QUERY, &attr, attr_size);
+	if (!ASSERT_OK(err, "prog_query"))
+		goto cleanup4;
+
+	ASSERT_EQ(attr.query.count, 4, "count");
+	ASSERT_EQ(attr.query.revision, 5, "revision");
+	ASSERT_EQ(attr.query.query_flags, 0, "query_flags");
+	ASSERT_EQ(attr.query.attach_flags, 0, "attach_flags");
+	ASSERT_EQ(attr.query.target_ifindex, loopback, "target_ifindex");
+	ASSERT_EQ(attr.query.attach_type, target, "attach_type");
+	ASSERT_EQ(attr.query.prog_ids, ptr_to_u64(prog_ids), "prog_ids");
+	ASSERT_EQ(prog_ids[0], id1, "prog_ids[0]");
+	ASSERT_EQ(prog_ids[1], id2, "prog_ids[1]");
+	ASSERT_EQ(prog_ids[2], id3, "prog_ids[2]");
+	ASSERT_EQ(prog_ids[3], id4, "prog_ids[3]");
+	ASSERT_EQ(prog_ids[4], 0, "prog_ids[4]");
+	ASSERT_EQ(attr.query.prog_attach_flags, 0, "prog_attach_flags");
+	ASSERT_EQ(attr.query.link_ids, 0, "link_ids");
+	ASSERT_EQ(attr.query.link_attach_flags, 0, "link_attach_flags");
+
+	/* Test 5: Query with NULL prog_ids array but with count > 0 */
+	memset(&attr, 0, attr_size);
+	attr.query.target_ifindex = loopback;
+	attr.query.attach_type = target;
+
+	memset(prog_ids, 0, sizeof(prog_ids));
+	attr.query.count = sizeof(prog_ids);
+
+	err = syscall(__NR_bpf, BPF_PROG_QUERY, &attr, attr_size);
+	if (!ASSERT_OK(err, "prog_query"))
+		goto cleanup4;
+
+	ASSERT_EQ(attr.query.count, 4, "count");
+	ASSERT_EQ(attr.query.revision, 5, "revision");
+	ASSERT_EQ(attr.query.query_flags, 0, "query_flags");
+	ASSERT_EQ(attr.query.attach_flags, 0, "attach_flags");
+	ASSERT_EQ(attr.query.target_ifindex, loopback, "target_ifindex");
+	ASSERT_EQ(attr.query.attach_type, target, "attach_type");
+	ASSERT_EQ(prog_ids[0], 0, "prog_ids[0]");
+	ASSERT_EQ(prog_ids[1], 0, "prog_ids[1]");
+	ASSERT_EQ(prog_ids[2], 0, "prog_ids[2]");
+	ASSERT_EQ(prog_ids[3], 0, "prog_ids[3]");
+	ASSERT_EQ(prog_ids[4], 0, "prog_ids[4]");
+	ASSERT_EQ(attr.query.prog_ids, 0, "prog_ids");
+	ASSERT_EQ(attr.query.prog_attach_flags, 0, "prog_attach_flags");
+	ASSERT_EQ(attr.query.link_ids, 0, "link_ids");
+	ASSERT_EQ(attr.query.link_attach_flags, 0, "link_attach_flags");
+
+	/* Test 6: Query with non-NULL prog_ids array but with count == 0 */
+	memset(&attr, 0, attr_size);
+	attr.query.target_ifindex = loopback;
+	attr.query.attach_type = target;
+
+	memset(prog_ids, 0, sizeof(prog_ids));
+	attr.query.prog_ids = ptr_to_u64(prog_ids);
+
+	err = syscall(__NR_bpf, BPF_PROG_QUERY, &attr, attr_size);
+	if (!ASSERT_OK(err, "prog_query"))
+		goto cleanup4;
+
+	ASSERT_EQ(attr.query.count, 4, "count");
+	ASSERT_EQ(attr.query.revision, 5, "revision");
+	ASSERT_EQ(attr.query.query_flags, 0, "query_flags");
+	ASSERT_EQ(attr.query.attach_flags, 0, "attach_flags");
+	ASSERT_EQ(attr.query.target_ifindex, loopback, "target_ifindex");
+	ASSERT_EQ(attr.query.attach_type, target, "attach_type");
+	ASSERT_EQ(prog_ids[0], 0, "prog_ids[0]");
+	ASSERT_EQ(prog_ids[1], 0, "prog_ids[1]");
+	ASSERT_EQ(prog_ids[2], 0, "prog_ids[2]");
+	ASSERT_EQ(prog_ids[3], 0, "prog_ids[3]");
+	ASSERT_EQ(prog_ids[4], 0, "prog_ids[4]");
+	ASSERT_EQ(attr.query.prog_ids, ptr_to_u64(prog_ids), "prog_ids");
+	ASSERT_EQ(attr.query.prog_attach_flags, 0, "prog_attach_flags");
+	ASSERT_EQ(attr.query.link_ids, 0, "link_ids");
+	ASSERT_EQ(attr.query.link_attach_flags, 0, "link_attach_flags");
+
+	/* Test 7: Query with invalid flags */
+	attr.query.attach_flags = 0;
+	attr.query.query_flags = 1;
+
+	err = syscall(__NR_bpf, BPF_PROG_QUERY, &attr, attr_size);
+	ASSERT_EQ(err, -1, "prog_query_should_fail");
+	ASSERT_EQ(errno, EINVAL, "prog_query_should_fail");
+
+	attr.query.attach_flags = 1;
+	attr.query.query_flags = 0;
+
+	err = syscall(__NR_bpf, BPF_PROG_QUERY, &attr, attr_size);
+	ASSERT_EQ(err, -1, "prog_query_should_fail");
+	ASSERT_EQ(errno, EINVAL, "prog_query_should_fail");
+
 cleanup4:
 	err = bpf_prog_detach_opts(fd4, loopback, target, &optd);
 	ASSERT_OK(err, "prog_detach");