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 = sys_gettid(); 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()
367 err = read(finish_pipe[0], &c, 1); in test_task_sleepable()
369 exit(-1); in test_task_sleepable()
380 err = read(data_pipe[0], &data, sizeof(data)); in test_task_sleepable()
383 skel->bss->user_ptr = data[0]; in test_task_sleepable()
384 skel->bss->user_ptr_long = data[1]; in test_task_sleepable()
385 skel->bss->pid = pid; in test_task_sleepable()
387 do_dummy_read(skel->progs.dump_task_sleepable); in test_task_sleepable()
389 ASSERT_GT(skel->bss->num_expected_failure_copy_from_user_task, 0, in test_task_sleepable()
391 ASSERT_GT(skel->bss->num_success_copy_from_user_task, 0, in test_task_sleepable()
393 ASSERT_GT(skel->bss->num_expected_failure_copy_from_user_task_str, 0, in test_task_sleepable()
395 ASSERT_GT(skel->bss->num_success_copy_from_user_task_str, 0, in test_task_sleepable()
417 do_dummy_read(skel->progs.dump_task_stack); in test_task_stack()
418 do_dummy_read(skel->progs.get_task_user_stacks); in test_task_stack()
420 ASSERT_EQ(skel->bss->num_user_stacks, 1, "num_user_stacks"); in test_task_stack()
437 skel->bss->tgid = getpid(); in test_task_file()
449 do_dummy_read_opts(skel->progs.dump_task_file, &opts); in test_task_file()
451 ASSERT_EQ(skel->bss->count, 0, "check_count"); in test_task_file()
452 ASSERT_EQ(skel->bss->unique_tgid_count, 1, "check_unique_tgid_count"); in test_task_file()
454 skel->bss->last_tgid = 0; in test_task_file()
455 skel->bss->count = 0; in test_task_file()
456 skel->bss->unique_tgid_count = 0; in test_task_file()
458 do_dummy_read(skel->progs.dump_task_file); in test_task_file()
460 ASSERT_EQ(skel->bss->count, 0, "check_count"); in test_task_file()
461 ASSERT_GT(skel->bss->unique_tgid_count, 1, "check_unique_tgid_count"); in test_task_file()
463 check_bpf_link_info(skel->progs.dump_task_file); in test_task_file()
478 struct bpf_program *prog = skel->progs.dump_task_struct; in do_btf_read()
479 struct bpf_iter_task_btf__bss *bss = skel->bss; in do_btf_read()
480 int iter_fd = -1, err; in do_btf_read()
494 if (bss->skip) { in do_btf_read()
501 if (!ASSERT_GE(err, 0, "read")) in do_btf_read()
523 bss = skel->bss; in test_task_btf()
529 if (!ASSERT_NEQ(bss->tasks, 0, "no task iteration, did BPF program run?")) in test_task_btf()
532 ASSERT_EQ(bss->seq_err, 0, "check for unexpected err"); in test_task_btf()
546 do_dummy_read(skel->progs.dump_tcp4); in test_tcp4()
559 do_dummy_read(skel->progs.dump_tcp6); in test_tcp6()
572 do_dummy_read(skel->progs.dump_udp4); in test_udp4()
585 do_dummy_read(skel->progs.dump_udp6); in test_udp6()
598 do_dummy_read(skel->progs.dump_unix); in test_unix()
612 while ((len = read(iter_fd, buf + start, read_buf_len)) > 0) { in do_read_with_fd()
614 if (!ASSERT_LT(start, 16, "read")) in do_read_with_fd()
615 return -1; in do_read_with_fd()
616 read_buf_len = read_one_char ? 1 : 16 - start; in do_read_with_fd()
618 if (!ASSERT_GE(len, 0, "read")) in do_read_with_fd()
619 return -1; in do_read_with_fd()
621 if (!ASSERT_STREQ(buf, expected, "read")) in do_read_with_fd()
622 return -1; in do_read_with_fd()
639 goto out; in test_anon_iter()
642 link = skel->links.dump_task; in test_anon_iter()
645 goto out; in test_anon_iter()
650 out: in test_anon_iter()
660 return -1; in do_read()
679 link = bpf_program__attach_iter(skel1->progs.dump_task, NULL); in test_file_iter()
681 goto out; in test_file_iter()
702 err = bpf_link__update_program(link, skel2->progs.dump_task); in test_file_iter()
714 out: in test_file_iter()
739 goto out; in test_overflow()
752 skel->rodata->print_len = (iter_size + 8) / 8; in test_overflow()
755 skel->rodata->print_len = (iter_size - 8) / 8; in test_overflow()
756 expected_read_len = 2 * (iter_size - 8); in test_overflow()
758 skel->rodata->print_len = 1; in test_overflow()
761 skel->rodata->ret1 = ret1; in test_overflow()
772 skel->bss->map1_id = map_info.id; in test_overflow()
777 skel->bss->map2_id = map_info.id; in test_overflow()
779 link = bpf_program__attach_iter(skel->progs.dump_bpf_map, NULL); in test_overflow()
791 /* do read */ in test_overflow()
794 while ((len = read(iter_fd, buf, expected_read_len)) > 0) in test_overflow()
797 ASSERT_EQ(len, -1, "read"); in test_overflow()
798 ASSERT_EQ(errno, E2BIG, "read"); in test_overflow()
801 while ((len = read(iter_fd, buf, expected_read_len)) > 0) in test_overflow()
804 if (!ASSERT_GE(len, 0, "read")) in test_overflow()
808 len = read(iter_fd, buf, expected_read_len); in test_overflow()
811 } while (len > 0 || len == -EAGAIN); in test_overflow()
813 if (!ASSERT_GE(len, 0, "read")) in test_overflow()
817 if (!ASSERT_EQ(total_read_len, expected_read_len, "read")) in test_overflow()
820 if (!ASSERT_EQ(skel->bss->map1_accessed, 1, "map1_accessed")) in test_overflow()
823 if (!ASSERT_EQ(skel->bss->map2_accessed, 2, "map2_accessed")) in test_overflow()
826 ASSERT_EQ(skel->bss->map2_seqnum1, skel->bss->map2_seqnum2, "map2_seqnum"); in test_overflow()
838 out: in test_overflow()
862 skel->bss->in_test_mode = true; in test_bpf_hash_map()
866 goto out; in test_bpf_hash_map()
870 linfo.map.map_fd = bpf_map__fd(skel->maps.hashmap2); in test_bpf_hash_map()
873 link = bpf_program__attach_iter(skel->progs.dump_bpf_hash_map, &opts); in test_bpf_hash_map()
875 goto out; in test_bpf_hash_map()
877 linfo.map.map_fd = bpf_map__fd(skel->maps.hashmap3); in test_bpf_hash_map()
878 link = bpf_program__attach_iter(skel->progs.dump_bpf_hash_map, &opts); in test_bpf_hash_map()
880 goto out; in test_bpf_hash_map()
883 map_fd = bpf_map__fd(skel->maps.hashmap1); in test_bpf_hash_map()
884 for (i = 0; i < bpf_map__max_entries(skel->maps.hashmap1); i++) { in test_bpf_hash_map()
895 goto out; in test_bpf_hash_map()
900 link = bpf_program__attach_iter(skel->progs.sleepable_dummy_dump, &opts); in test_bpf_hash_map()
902 goto out; in test_bpf_hash_map()
905 link = bpf_program__attach_iter(skel->progs.dump_bpf_hash_map, &opts); in test_bpf_hash_map()
907 goto out; in test_bpf_hash_map()
914 while ((len = read(iter_fd, buf, sizeof(buf))) > 0) in test_bpf_hash_map()
916 if (!ASSERT_GE(len, 0, "read")) in test_bpf_hash_map()
920 if (!ASSERT_EQ(skel->bss->key_sum_a, expected_key_a, "key_sum_a")) in test_bpf_hash_map()
922 if (!ASSERT_EQ(skel->bss->key_sum_b, expected_key_b, "key_sum_b")) in test_bpf_hash_map()
924 if (!ASSERT_EQ(skel->bss->val_sum, expected_val, "val_sum")) in test_bpf_hash_map()
931 out: in test_bpf_hash_map()
956 skel->rodata->num_cpus = bpf_num_possible_cpus(); in test_bpf_percpu_hash_map()
959 goto out; in test_bpf_percpu_hash_map()
963 goto out; in test_bpf_percpu_hash_map()
966 map_fd = bpf_map__fd(skel->maps.hashmap1); in test_bpf_percpu_hash_map()
967 for (i = 0; i < bpf_map__max_entries(skel->maps.hashmap1); i++) { in test_bpf_percpu_hash_map()
981 goto out; in test_bpf_percpu_hash_map()
988 link = bpf_program__attach_iter(skel->progs.dump_bpf_percpu_hash_map, &opts); in test_bpf_percpu_hash_map()
990 goto out; in test_bpf_percpu_hash_map()
997 while ((len = read(iter_fd, buf, sizeof(buf))) > 0) in test_bpf_percpu_hash_map()
999 if (!ASSERT_GE(len, 0, "read")) in test_bpf_percpu_hash_map()
1003 if (!ASSERT_EQ(skel->bss->key_sum_a, expected_key_a, "key_sum_a")) in test_bpf_percpu_hash_map()
1005 if (!ASSERT_EQ(skel->bss->key_sum_b, expected_key_b, "key_sum_b")) in test_bpf_percpu_hash_map()
1007 if (!ASSERT_EQ(skel->bss->val_sum, expected_val, "val_sum")) in test_bpf_percpu_hash_map()
1014 out: in test_bpf_percpu_hash_map()
1035 map_fd = bpf_map__fd(skel->maps.arraymap1); in test_bpf_array_map()
1036 for (i = 0; i < bpf_map__max_entries(skel->maps.arraymap1); i++) { in test_bpf_array_map()
1046 goto out; in test_bpf_array_map()
1053 link = bpf_program__attach_iter(skel->progs.dump_bpf_array_map, &opts); in test_bpf_array_map()
1055 goto out; in test_bpf_array_map()
1063 while ((len = read(iter_fd, buf + start, sizeof(buf) - start)) > 0) in test_bpf_array_map()
1065 if (!ASSERT_GE(len, 0, "read")) in test_bpf_array_map()
1075 if (!ASSERT_EQ(skel->bss->key_sum, expected_key, "key_sum")) in test_bpf_array_map()
1077 if (!ASSERT_EQ(skel->bss->val_sum, expected_val, "val_sum")) in test_bpf_array_map()
1080 hash_fd = bpf_map__fd(skel->maps.hashmap1); in test_bpf_array_map()
1081 for (i = 0; i < bpf_map__max_entries(skel->maps.arraymap1); i++) { in test_bpf_array_map()
1092 if (!ASSERT_EQ(key, val - 4, "invalid_val hashmap1")) in test_bpf_array_map()
1100 out: in test_bpf_array_map()
1112 do_read_map_iter_fd(&skel->skeleton, skel->progs.dump_bpf_array_map, in test_bpf_array_map_iter_fd()
1113 skel->maps.arraymap1); in test_bpf_array_map_iter_fd()
1134 skel->rodata->num_cpus = bpf_num_possible_cpus(); in test_bpf_percpu_array_map()
1137 goto out; in test_bpf_percpu_array_map()
1141 goto out; in test_bpf_percpu_array_map()
1144 map_fd = bpf_map__fd(skel->maps.arraymap1); in test_bpf_percpu_array_map()
1145 for (i = 0; i < bpf_map__max_entries(skel->maps.arraymap1); i++) { in test_bpf_percpu_array_map()
1155 goto out; in test_bpf_percpu_array_map()
1162 link = bpf_program__attach_iter(skel->progs.dump_bpf_percpu_array_map, &opts); in test_bpf_percpu_array_map()
1164 goto out; in test_bpf_percpu_array_map()
1171 while ((len = read(iter_fd, buf, sizeof(buf))) > 0) in test_bpf_percpu_array_map()
1173 if (!ASSERT_GE(len, 0, "read")) in test_bpf_percpu_array_map()
1177 if (!ASSERT_EQ(skel->bss->key_sum, expected_key, "key_sum")) in test_bpf_percpu_array_map()
1179 if (!ASSERT_EQ(skel->bss->val_sum, expected_val, "val_sum")) in test_bpf_percpu_array_map()
1186 out: in test_bpf_percpu_array_map()
1199 int sock_fd = -1; in test_bpf_sk_storage_delete()
1207 map_fd = bpf_map__fd(skel->maps.sk_stg_map); in test_bpf_sk_storage_delete()
1211 goto out; in test_bpf_sk_storage_delete()
1215 goto out; in test_bpf_sk_storage_delete()
1221 link = bpf_program__attach_iter(skel->progs.delete_bpf_sk_storage_map, in test_bpf_sk_storage_delete()
1224 goto out; in test_bpf_sk_storage_delete()
1231 while ((len = read(iter_fd, buf, sizeof(buf))) > 0) in test_bpf_sk_storage_delete()
1233 if (!ASSERT_GE(len, 0, "read")) in test_bpf_sk_storage_delete()
1251 out: in test_bpf_sk_storage_delete()
1261 * socket local storage, the test verifies that the resulting value is -pid.
1266 int err, map_fd, val = -1; in test_bpf_sk_storage_get()
1267 int sock_fd = -1; in test_bpf_sk_storage_get()
1275 goto out; in test_bpf_sk_storage_get()
1281 map_fd = bpf_map__fd(skel->maps.sk_stg_map); in test_bpf_sk_storage_get()
1287 do_dummy_read(skel->progs.fill_socket_owner); in test_bpf_sk_storage_get()
1294 do_dummy_read(skel->progs.negate_socket_local_storage); in test_bpf_sk_storage_get()
1298 ASSERT_EQ(val, -getpid(), "bpf_map_lookup_elem"); in test_bpf_sk_storage_get()
1302 out: in test_bpf_sk_storage_get()
1314 do_read_map_iter_fd(&skel->skeleton, skel->progs.rw_bpf_sk_storage_map, in test_bpf_sk_storage_map_iter_fd()
1315 skel->maps.sk_stg_map); in test_bpf_sk_storage_map_iter_fd()
1326 int sock_fd[3] = {-1, -1, -1}; in test_bpf_sk_storage_map()
1335 map_fd = bpf_map__fd(skel->maps.sk_stg_map); in test_bpf_sk_storage_map()
1340 goto out; in test_bpf_sk_storage_map()
1348 goto out; in test_bpf_sk_storage_map()
1355 link = bpf_program__attach_iter(skel->progs.oob_write_bpf_sk_storage_map, &opts); in test_bpf_sk_storage_map()
1357 if (!ASSERT_EQ(err, -EACCES, "attach_oob_write_iter")) { in test_bpf_sk_storage_map()
1360 goto out; in test_bpf_sk_storage_map()
1363 link = bpf_program__attach_iter(skel->progs.rw_bpf_sk_storage_map, &opts); in test_bpf_sk_storage_map()
1365 goto out; in test_bpf_sk_storage_map()
1371 skel->bss->to_add_val = time(NULL); in test_bpf_sk_storage_map()
1373 while ((len = read(iter_fd, buf, sizeof(buf))) > 0) in test_bpf_sk_storage_map()
1375 if (!ASSERT_GE(len, 0, "read")) in test_bpf_sk_storage_map()
1379 if (!ASSERT_EQ(skel->bss->ipv6_sk_count, num_sockets, "ipv6_sk_count")) in test_bpf_sk_storage_map()
1382 if (!ASSERT_EQ(skel->bss->val_sum, expected_val, "val_sum")) in test_bpf_sk_storage_map()
1388 !ASSERT_EQ(val, i + 1 + skel->bss->to_add_val, "check_map_value")) in test_bpf_sk_storage_map()
1396 out: in test_bpf_sk_storage_map()
1416 linfo.map.map_fd = bpf_map__fd(skel->maps.hashmap1); in test_rdonly_buf_out_of_bound()
1419 link = bpf_program__attach_iter(skel->progs.dump_bpf_hash_map, &opts); in test_rdonly_buf_out_of_bound()
1443 do_dummy_read(skel->progs.dump_bpf_link); in test_link_iter()
1456 do_dummy_read(skel->progs.dump_ksym); in test_ksym_iter()
1483 int err, iter_fd = -1, proc_maps_fd = -1; in test_task_vma_common()
1492 skel->bss->pid = getpid(); in test_task_vma_common()
1493 skel->bss->one_task = opts ? 1 : 0; in test_task_vma_common()
1497 goto out; in test_task_vma_common()
1499 skel->links.proc_maps = bpf_program__attach_iter( in test_task_vma_common()
1500 skel->progs.proc_maps, opts); in test_task_vma_common()
1502 if (!ASSERT_OK_PTR(skel->links.proc_maps, "bpf_program__attach_iter")) { in test_task_vma_common()
1503 skel->links.proc_maps = NULL; in test_task_vma_common()
1504 goto out; in test_task_vma_common()
1507 iter_fd = bpf_iter_create(bpf_link__fd(skel->links.proc_maps)); in test_task_vma_common()
1509 goto out; in test_task_vma_common()
1511 /* Read CMP_BUFFER_SIZE (1kB) from bpf_iter. Read in small chunks in test_task_vma_common()
1517 MIN(read_size, CMP_BUFFER_SIZE - len)); in test_task_vma_common()
1521 goto out; in test_task_vma_common()
1525 ASSERT_EQ(skel->bss->one_task_error, 0, "unexpected task"); in test_task_vma_common()
1527 /* read CMP_BUFFER_SIZE (1kB) from /proc/pid/maps */ in test_task_vma_common()
1528 snprintf(maps_path, 64, "/proc/%u/maps", skel->bss->pid); in test_task_vma_common()
1531 goto out; in test_task_vma_common()
1534 goto out; in test_task_vma_common()
1542 check_bpf_link_info(skel->progs.proc_maps); in test_task_vma_common()
1544 out: in test_task_vma_common()
1553 int wstatus, child_pid = -1; in test_task_vma_dead_task()
1555 int err, iter_fd = -1; in test_task_vma_dead_task()
1562 skel->bss->pid = getpid(); in test_task_vma_dead_task()
1566 goto out; in test_task_vma_dead_task()
1568 skel->links.proc_maps = bpf_program__attach_iter( in test_task_vma_dead_task()
1569 skel->progs.proc_maps, NULL); in test_task_vma_dead_task()
1571 if (!ASSERT_OK_PTR(skel->links.proc_maps, "bpf_program__attach_iter")) { in test_task_vma_dead_task()
1572 skel->links.proc_maps = NULL; in test_task_vma_dead_task()
1573 goto out; in test_task_vma_dead_task()
1581 /* Fork short-lived processes in the background. */ in test_task_vma_dead_task()
1590 goto out; in test_task_vma_dead_task()
1593 iter_fd = bpf_iter_create(bpf_link__fd(skel->links.proc_maps)); in test_task_vma_dead_task()
1595 goto out; in test_task_vma_dead_task()
1601 goto out; in test_task_vma_dead_task()
1610 iter_fd = -1; in test_task_vma_dead_task()
1613 check_bpf_link_info(skel->progs.proc_maps); in test_task_vma_dead_task()
1615 out: in test_task_vma_dead_task()
1629 do_read_map_iter_fd(&skel->skeleton, skel->progs.copy, skel->maps.sockmap); in test_bpf_sockmap_map_iter_fd()
1666 skel->bss->pid = getpid(); in test_task_vma_offset_common()
1667 skel->bss->address = (uintptr_t)trigger_func; in test_task_vma_offset_common()
1670 skel->bss->page_shift = shift; in test_task_vma_offset_common()
1672 skel->links.get_vma_offset = bpf_program__attach_iter(skel->progs.get_vma_offset, opts); in test_task_vma_offset_common()
1673 if (!ASSERT_OK_PTR(skel->links.get_vma_offset, "attach_iter")) in test_task_vma_offset_common()
1676 iter_fd = bpf_iter_create(bpf_link__fd(skel->links.get_vma_offset)); in test_task_vma_offset_common()
1680 while ((len = read(iter_fd, buf, sizeof(buf))) > 0) in test_task_vma_offset_common()
1685 ASSERT_EQ(skel->bss->offset, get_uprobe_offset(trigger_func), "offset"); in test_task_vma_offset_common()
1687 ASSERT_EQ(skel->bss->unique_tgid_cnt, 1, "unique_tgid_count"); in test_task_vma_offset_common()
1689 ASSERT_GT(skel->bss->unique_tgid_cnt, 1, "unique_tgid_count"); in test_task_vma_offset_common()
1758 if (test__start_subtest("anon-read-one-char")) in test_bpf_iter()
1764 if (test__start_subtest("overflow-e2big")) in test_bpf_iter()
1766 if (test__start_subtest("prog-ret-1")) in test_bpf_iter()
1786 if (test__start_subtest("rdonly-buf-out-of-bound")) in test_bpf_iter()
1788 if (test__start_subtest("buf-neg-offset")) in test_bpf_iter()
1790 if (test__start_subtest("link-iter")) in test_bpf_iter()