Lines Matching +full:read +full:- +full:out

1 // SPDX-License-Identifier: GPL-2.0
62 /* not check contents, but ensure read() ends without error */ in do_dummy_read_opts()
63 while ((len = read(iter_fd, buf, sizeof(buf))) > 0) in do_dummy_read_opts()
65 ASSERT_GE(len, 0, "read"); in do_dummy_read_opts()
114 /* Read after both map fd and link fd are closed */ in do_read_map_iter_fd()
115 while ((len = read(iter_fd, buf, sizeof(buf))) > 0) in do_read_map_iter_fd()
128 len = read(fd, buf, bufleft); in read_fd_into_buffer()
131 bufleft -= len; in read_fd_into_buffer()
135 return len < 0 ? len : size - bufleft; in read_fd_into_buffer()
146 do_dummy_read(skel->progs.dump_ipv6_route); in test_ipv6_route()
159 do_dummy_read(skel->progs.dump_netlink); in test_netlink()
172 do_dummy_read(skel->progs.dump_bpf_map); in test_bpf_map()
229 skel->bss->tid = getpid(); in test_task_common_nocheck()
231 do_dummy_read_opts(skel->progs.dump_task, opts); in test_task_common_nocheck()
233 *num_unknown = skel->bss->num_unknown_tid; in test_task_common_nocheck()
234 *num_known = skel->bss->num_known_tid; in test_task_common_nocheck()
314 do_dummy_read(skel->progs.dump_task_sleepable); in test_task_sleepable()
316 ASSERT_GT(skel->bss->num_expected_failure_copy_from_user_task, 0, in test_task_sleepable()
318 ASSERT_GT(skel->bss->num_success_copy_from_user_task, 0, in test_task_sleepable()
332 do_dummy_read(skel->progs.dump_task_stack); in test_task_stack()
333 do_dummy_read(skel->progs.get_task_user_stacks); in test_task_stack()
335 ASSERT_EQ(skel->bss->num_user_stacks, 1, "num_user_stacks"); in test_task_stack()
352 skel->bss->tgid = getpid(); in test_task_file()
364 do_dummy_read_opts(skel->progs.dump_task_file, &opts); in test_task_file()
366 ASSERT_EQ(skel->bss->count, 0, "check_count"); in test_task_file()
367 ASSERT_EQ(skel->bss->unique_tgid_count, 1, "check_unique_tgid_count"); in test_task_file()
369 skel->bss->last_tgid = 0; in test_task_file()
370 skel->bss->count = 0; in test_task_file()
371 skel->bss->unique_tgid_count = 0; in test_task_file()
373 do_dummy_read(skel->progs.dump_task_file); in test_task_file()
375 ASSERT_EQ(skel->bss->count, 0, "check_count"); in test_task_file()
376 ASSERT_GT(skel->bss->unique_tgid_count, 1, "check_unique_tgid_count"); in test_task_file()
378 check_bpf_link_info(skel->progs.dump_task_file); in test_task_file()
393 struct bpf_program *prog = skel->progs.dump_task_struct; in do_btf_read()
394 struct bpf_iter_task_btf__bss *bss = skel->bss; in do_btf_read()
395 int iter_fd = -1, err; in do_btf_read()
409 if (bss->skip) { in do_btf_read()
416 if (!ASSERT_GE(err, 0, "read")) in do_btf_read()
438 bss = skel->bss; in test_task_btf()
444 if (!ASSERT_NEQ(bss->tasks, 0, "no task iteration, did BPF program run?")) in test_task_btf()
447 ASSERT_EQ(bss->seq_err, 0, "check for unexpected err"); in test_task_btf()
461 do_dummy_read(skel->progs.dump_tcp4); in test_tcp4()
474 do_dummy_read(skel->progs.dump_tcp6); in test_tcp6()
487 do_dummy_read(skel->progs.dump_udp4); in test_udp4()
500 do_dummy_read(skel->progs.dump_udp6); in test_udp6()
513 do_dummy_read(skel->progs.dump_unix); in test_unix()
527 while ((len = read(iter_fd, buf + start, read_buf_len)) > 0) { in do_read_with_fd()
529 if (!ASSERT_LT(start, 16, "read")) in do_read_with_fd()
530 return -1; in do_read_with_fd()
531 read_buf_len = read_one_char ? 1 : 16 - start; in do_read_with_fd()
533 if (!ASSERT_GE(len, 0, "read")) in do_read_with_fd()
534 return -1; in do_read_with_fd()
536 if (!ASSERT_STREQ(buf, expected, "read")) in do_read_with_fd()
537 return -1; in do_read_with_fd()
554 goto out; in test_anon_iter()
557 link = skel->links.dump_task; in test_anon_iter()
560 goto out; in test_anon_iter()
565 out: in test_anon_iter()
575 return -1; in do_read()
594 link = bpf_program__attach_iter(skel1->progs.dump_task, NULL); in test_file_iter()
596 goto out; in test_file_iter()
617 err = bpf_link__update_program(link, skel2->progs.dump_task); in test_file_iter()
629 out: in test_file_iter()
654 goto out; in test_overflow()
667 skel->rodata->print_len = (iter_size + 8) / 8; in test_overflow()
670 skel->rodata->print_len = (iter_size - 8) / 8; in test_overflow()
671 expected_read_len = 2 * (iter_size - 8); in test_overflow()
673 skel->rodata->print_len = 1; in test_overflow()
676 skel->rodata->ret1 = ret1; in test_overflow()
687 skel->bss->map1_id = map_info.id; in test_overflow()
692 skel->bss->map2_id = map_info.id; in test_overflow()
694 link = bpf_program__attach_iter(skel->progs.dump_bpf_map, NULL); in test_overflow()
706 /* do read */ in test_overflow()
709 while ((len = read(iter_fd, buf, expected_read_len)) > 0) in test_overflow()
712 ASSERT_EQ(len, -1, "read"); in test_overflow()
713 ASSERT_EQ(errno, E2BIG, "read"); in test_overflow()
716 while ((len = read(iter_fd, buf, expected_read_len)) > 0) in test_overflow()
719 if (!ASSERT_GE(len, 0, "read")) in test_overflow()
723 len = read(iter_fd, buf, expected_read_len); in test_overflow()
726 } while (len > 0 || len == -EAGAIN); in test_overflow()
728 if (!ASSERT_GE(len, 0, "read")) in test_overflow()
732 if (!ASSERT_EQ(total_read_len, expected_read_len, "read")) in test_overflow()
735 if (!ASSERT_EQ(skel->bss->map1_accessed, 1, "map1_accessed")) in test_overflow()
738 if (!ASSERT_EQ(skel->bss->map2_accessed, 2, "map2_accessed")) in test_overflow()
741 ASSERT_EQ(skel->bss->map2_seqnum1, skel->bss->map2_seqnum2, "map2_seqnum"); in test_overflow()
753 out: in test_overflow()
777 skel->bss->in_test_mode = true; in test_bpf_hash_map()
781 goto out; in test_bpf_hash_map()
785 linfo.map.map_fd = bpf_map__fd(skel->maps.hashmap2); in test_bpf_hash_map()
788 link = bpf_program__attach_iter(skel->progs.dump_bpf_hash_map, &opts); in test_bpf_hash_map()
790 goto out; in test_bpf_hash_map()
792 linfo.map.map_fd = bpf_map__fd(skel->maps.hashmap3); in test_bpf_hash_map()
793 link = bpf_program__attach_iter(skel->progs.dump_bpf_hash_map, &opts); in test_bpf_hash_map()
795 goto out; in test_bpf_hash_map()
798 map_fd = bpf_map__fd(skel->maps.hashmap1); in test_bpf_hash_map()
799 for (i = 0; i < bpf_map__max_entries(skel->maps.hashmap1); i++) { in test_bpf_hash_map()
810 goto out; in test_bpf_hash_map()
815 link = bpf_program__attach_iter(skel->progs.sleepable_dummy_dump, &opts); in test_bpf_hash_map()
817 goto out; in test_bpf_hash_map()
820 link = bpf_program__attach_iter(skel->progs.dump_bpf_hash_map, &opts); in test_bpf_hash_map()
822 goto out; in test_bpf_hash_map()
829 while ((len = read(iter_fd, buf, sizeof(buf))) > 0) in test_bpf_hash_map()
831 if (!ASSERT_GE(len, 0, "read")) in test_bpf_hash_map()
835 if (!ASSERT_EQ(skel->bss->key_sum_a, expected_key_a, "key_sum_a")) in test_bpf_hash_map()
837 if (!ASSERT_EQ(skel->bss->key_sum_b, expected_key_b, "key_sum_b")) in test_bpf_hash_map()
839 if (!ASSERT_EQ(skel->bss->val_sum, expected_val, "val_sum")) in test_bpf_hash_map()
846 out: in test_bpf_hash_map()
871 skel->rodata->num_cpus = bpf_num_possible_cpus(); in test_bpf_percpu_hash_map()
874 goto out; in test_bpf_percpu_hash_map()
878 goto out; in test_bpf_percpu_hash_map()
881 map_fd = bpf_map__fd(skel->maps.hashmap1); in test_bpf_percpu_hash_map()
882 for (i = 0; i < bpf_map__max_entries(skel->maps.hashmap1); i++) { in test_bpf_percpu_hash_map()
896 goto out; in test_bpf_percpu_hash_map()
903 link = bpf_program__attach_iter(skel->progs.dump_bpf_percpu_hash_map, &opts); in test_bpf_percpu_hash_map()
905 goto out; in test_bpf_percpu_hash_map()
912 while ((len = read(iter_fd, buf, sizeof(buf))) > 0) in test_bpf_percpu_hash_map()
914 if (!ASSERT_GE(len, 0, "read")) in test_bpf_percpu_hash_map()
918 if (!ASSERT_EQ(skel->bss->key_sum_a, expected_key_a, "key_sum_a")) in test_bpf_percpu_hash_map()
920 if (!ASSERT_EQ(skel->bss->key_sum_b, expected_key_b, "key_sum_b")) in test_bpf_percpu_hash_map()
922 if (!ASSERT_EQ(skel->bss->val_sum, expected_val, "val_sum")) in test_bpf_percpu_hash_map()
929 out: in test_bpf_percpu_hash_map()
950 map_fd = bpf_map__fd(skel->maps.arraymap1); in test_bpf_array_map()
951 for (i = 0; i < bpf_map__max_entries(skel->maps.arraymap1); i++) { in test_bpf_array_map()
961 goto out; in test_bpf_array_map()
968 link = bpf_program__attach_iter(skel->progs.dump_bpf_array_map, &opts); in test_bpf_array_map()
970 goto out; in test_bpf_array_map()
978 while ((len = read(iter_fd, buf + start, sizeof(buf) - start)) > 0) in test_bpf_array_map()
980 if (!ASSERT_GE(len, 0, "read")) in test_bpf_array_map()
990 if (!ASSERT_EQ(skel->bss->key_sum, expected_key, "key_sum")) in test_bpf_array_map()
992 if (!ASSERT_EQ(skel->bss->val_sum, expected_val, "val_sum")) in test_bpf_array_map()
995 hash_fd = bpf_map__fd(skel->maps.hashmap1); in test_bpf_array_map()
996 for (i = 0; i < bpf_map__max_entries(skel->maps.arraymap1); i++) { in test_bpf_array_map()
1007 if (!ASSERT_EQ(key, val - 4, "invalid_val hashmap1")) in test_bpf_array_map()
1015 out: in test_bpf_array_map()
1027 do_read_map_iter_fd(&skel->skeleton, skel->progs.dump_bpf_array_map, in test_bpf_array_map_iter_fd()
1028 skel->maps.arraymap1); in test_bpf_array_map_iter_fd()
1049 skel->rodata->num_cpus = bpf_num_possible_cpus(); in test_bpf_percpu_array_map()
1052 goto out; in test_bpf_percpu_array_map()
1056 goto out; in test_bpf_percpu_array_map()
1059 map_fd = bpf_map__fd(skel->maps.arraymap1); in test_bpf_percpu_array_map()
1060 for (i = 0; i < bpf_map__max_entries(skel->maps.arraymap1); i++) { in test_bpf_percpu_array_map()
1070 goto out; in test_bpf_percpu_array_map()
1077 link = bpf_program__attach_iter(skel->progs.dump_bpf_percpu_array_map, &opts); in test_bpf_percpu_array_map()
1079 goto out; in test_bpf_percpu_array_map()
1086 while ((len = read(iter_fd, buf, sizeof(buf))) > 0) in test_bpf_percpu_array_map()
1088 if (!ASSERT_GE(len, 0, "read")) in test_bpf_percpu_array_map()
1092 if (!ASSERT_EQ(skel->bss->key_sum, expected_key, "key_sum")) in test_bpf_percpu_array_map()
1094 if (!ASSERT_EQ(skel->bss->val_sum, expected_val, "val_sum")) in test_bpf_percpu_array_map()
1101 out: in test_bpf_percpu_array_map()
1114 int sock_fd = -1; in test_bpf_sk_storage_delete()
1122 map_fd = bpf_map__fd(skel->maps.sk_stg_map); in test_bpf_sk_storage_delete()
1126 goto out; in test_bpf_sk_storage_delete()
1130 goto out; in test_bpf_sk_storage_delete()
1136 link = bpf_program__attach_iter(skel->progs.delete_bpf_sk_storage_map, in test_bpf_sk_storage_delete()
1139 goto out; in test_bpf_sk_storage_delete()
1146 while ((len = read(iter_fd, buf, sizeof(buf))) > 0) in test_bpf_sk_storage_delete()
1148 if (!ASSERT_GE(len, 0, "read")) in test_bpf_sk_storage_delete()
1166 out: in test_bpf_sk_storage_delete()
1176 * socket local storage, the test verifies that the resulting value is -pid.
1181 int err, map_fd, val = -1; in test_bpf_sk_storage_get()
1182 int sock_fd = -1; in test_bpf_sk_storage_get()
1190 goto out; in test_bpf_sk_storage_get()
1196 map_fd = bpf_map__fd(skel->maps.sk_stg_map); in test_bpf_sk_storage_get()
1202 do_dummy_read(skel->progs.fill_socket_owner); in test_bpf_sk_storage_get()
1209 do_dummy_read(skel->progs.negate_socket_local_storage); in test_bpf_sk_storage_get()
1213 ASSERT_EQ(val, -getpid(), "bpf_map_lookup_elem"); in test_bpf_sk_storage_get()
1217 out: in test_bpf_sk_storage_get()
1229 do_read_map_iter_fd(&skel->skeleton, skel->progs.rw_bpf_sk_storage_map, in test_bpf_sk_stoarge_map_iter_fd()
1230 skel->maps.sk_stg_map); in test_bpf_sk_stoarge_map_iter_fd()
1241 int sock_fd[3] = {-1, -1, -1}; in test_bpf_sk_storage_map()
1250 map_fd = bpf_map__fd(skel->maps.sk_stg_map); in test_bpf_sk_storage_map()
1255 goto out; in test_bpf_sk_storage_map()
1263 goto out; in test_bpf_sk_storage_map()
1270 link = bpf_program__attach_iter(skel->progs.oob_write_bpf_sk_storage_map, &opts); in test_bpf_sk_storage_map()
1272 if (!ASSERT_EQ(err, -EACCES, "attach_oob_write_iter")) { in test_bpf_sk_storage_map()
1275 goto out; in test_bpf_sk_storage_map()
1278 link = bpf_program__attach_iter(skel->progs.rw_bpf_sk_storage_map, &opts); in test_bpf_sk_storage_map()
1280 goto out; in test_bpf_sk_storage_map()
1286 skel->bss->to_add_val = time(NULL); in test_bpf_sk_storage_map()
1288 while ((len = read(iter_fd, buf, sizeof(buf))) > 0) in test_bpf_sk_storage_map()
1290 if (!ASSERT_GE(len, 0, "read")) in test_bpf_sk_storage_map()
1294 if (!ASSERT_EQ(skel->bss->ipv6_sk_count, num_sockets, "ipv6_sk_count")) in test_bpf_sk_storage_map()
1297 if (!ASSERT_EQ(skel->bss->val_sum, expected_val, "val_sum")) in test_bpf_sk_storage_map()
1303 !ASSERT_EQ(val, i + 1 + skel->bss->to_add_val, "check_map_value")) in test_bpf_sk_storage_map()
1311 out: in test_bpf_sk_storage_map()
1331 linfo.map.map_fd = bpf_map__fd(skel->maps.hashmap1); in test_rdonly_buf_out_of_bound()
1334 link = bpf_program__attach_iter(skel->progs.dump_bpf_hash_map, &opts); in test_rdonly_buf_out_of_bound()
1358 do_dummy_read(skel->progs.dump_bpf_link); in test_link_iter()
1371 do_dummy_read(skel->progs.dump_ksym); in test_ksym_iter()
1398 int err, iter_fd = -1, proc_maps_fd = -1; in test_task_vma_common()
1407 skel->bss->pid = getpid(); in test_task_vma_common()
1408 skel->bss->one_task = opts ? 1 : 0; in test_task_vma_common()
1412 goto out; in test_task_vma_common()
1414 skel->links.proc_maps = bpf_program__attach_iter( in test_task_vma_common()
1415 skel->progs.proc_maps, opts); in test_task_vma_common()
1417 if (!ASSERT_OK_PTR(skel->links.proc_maps, "bpf_program__attach_iter")) { in test_task_vma_common()
1418 skel->links.proc_maps = NULL; in test_task_vma_common()
1419 goto out; in test_task_vma_common()
1422 iter_fd = bpf_iter_create(bpf_link__fd(skel->links.proc_maps)); in test_task_vma_common()
1424 goto out; in test_task_vma_common()
1426 /* Read CMP_BUFFER_SIZE (1kB) from bpf_iter. Read in small chunks in test_task_vma_common()
1432 MIN(read_size, CMP_BUFFER_SIZE - len)); in test_task_vma_common()
1436 goto out; in test_task_vma_common()
1440 ASSERT_EQ(skel->bss->one_task_error, 0, "unexpected task"); in test_task_vma_common()
1442 /* read CMP_BUFFER_SIZE (1kB) from /proc/pid/maps */ in test_task_vma_common()
1443 snprintf(maps_path, 64, "/proc/%u/maps", skel->bss->pid); in test_task_vma_common()
1446 goto out; in test_task_vma_common()
1449 goto out; in test_task_vma_common()
1457 check_bpf_link_info(skel->progs.proc_maps); in test_task_vma_common()
1459 out: in test_task_vma_common()
1468 int wstatus, child_pid = -1; in test_task_vma_dead_task()
1470 int err, iter_fd = -1; in test_task_vma_dead_task()
1477 skel->bss->pid = getpid(); in test_task_vma_dead_task()
1481 goto out; in test_task_vma_dead_task()
1483 skel->links.proc_maps = bpf_program__attach_iter( in test_task_vma_dead_task()
1484 skel->progs.proc_maps, NULL); in test_task_vma_dead_task()
1486 if (!ASSERT_OK_PTR(skel->links.proc_maps, "bpf_program__attach_iter")) { in test_task_vma_dead_task()
1487 skel->links.proc_maps = NULL; in test_task_vma_dead_task()
1488 goto out; in test_task_vma_dead_task()
1496 /* Fork short-lived processes in the background. */ in test_task_vma_dead_task()
1505 goto out; in test_task_vma_dead_task()
1508 iter_fd = bpf_iter_create(bpf_link__fd(skel->links.proc_maps)); in test_task_vma_dead_task()
1510 goto out; in test_task_vma_dead_task()
1516 goto out; in test_task_vma_dead_task()
1525 iter_fd = -1; in test_task_vma_dead_task()
1528 check_bpf_link_info(skel->progs.proc_maps); in test_task_vma_dead_task()
1530 out: in test_task_vma_dead_task()
1544 do_read_map_iter_fd(&skel->skeleton, skel->progs.copy, skel->maps.sockmap); in test_bpf_sockmap_map_iter_fd()
1581 skel->bss->pid = getpid(); in test_task_vma_offset_common()
1582 skel->bss->address = (uintptr_t)trigger_func; in test_task_vma_offset_common()
1585 skel->bss->page_shift = shift; in test_task_vma_offset_common()
1587 skel->links.get_vma_offset = bpf_program__attach_iter(skel->progs.get_vma_offset, opts); in test_task_vma_offset_common()
1588 if (!ASSERT_OK_PTR(skel->links.get_vma_offset, "attach_iter")) in test_task_vma_offset_common()
1591 iter_fd = bpf_iter_create(bpf_link__fd(skel->links.get_vma_offset)); in test_task_vma_offset_common()
1595 while ((len = read(iter_fd, buf, sizeof(buf))) > 0) in test_task_vma_offset_common()
1600 ASSERT_EQ(skel->bss->offset, get_uprobe_offset(trigger_func), "offset"); in test_task_vma_offset_common()
1602 ASSERT_EQ(skel->bss->unique_tgid_cnt, 1, "unique_tgid_count"); in test_task_vma_offset_common()
1604 ASSERT_GT(skel->bss->unique_tgid_cnt, 1, "unique_tgid_count"); in test_task_vma_offset_common()
1673 if (test__start_subtest("anon-read-one-char")) in test_bpf_iter()
1679 if (test__start_subtest("overflow-e2big")) in test_bpf_iter()
1681 if (test__start_subtest("prog-ret-1")) in test_bpf_iter()
1701 if (test__start_subtest("rdonly-buf-out-of-bound")) in test_bpf_iter()
1703 if (test__start_subtest("buf-neg-offset")) in test_bpf_iter()
1705 if (test__start_subtest("link-iter")) in test_bpf_iter()