Lines Matching refs:test

92 	/* If specified, test engine looks for this sequence of
94 * test rewrites applied by verifier. Use values
96 * fields if content does not matter. The test case fails if
104 /* If specified, test engine applies same pattern matching
106 * matched test case is marked as failed.
192 /* test: {skb->data[0], vlan_push} x 51 + {skb->data[0], vlan_pop} x 51 */
286 /* test the sequence of 8k jumps */
293 /* test to check that the long sequence of jumps is acceptable */
312 /* test the sequence of 8k jumps in inner most function (function depth 8)*/
324 /* test to check that the long sequence of jumps is acceptable */
429 /* This test was added to catch a specific use after free
789 static int load_btf_for_test(struct bpf_test *test)
794 test->btf_types[types_num] != BTF_END_RAW)
797 int types_len = types_num * sizeof(test->btf_types[0]);
799 return load_btf_spec(test->btf_types, types_len,
800 test->btf_strings, sizeof(test->btf_strings));
1011 static void do_test_fixup(struct bpf_test *test, enum bpf_prog_type prog_type,
1014 int *fixup_map_hash_8b = test->fixup_map_hash_8b;
1015 int *fixup_map_hash_48b = test->fixup_map_hash_48b;
1016 int *fixup_map_hash_16b = test->fixup_map_hash_16b;
1017 int *fixup_map_array_48b = test->fixup_map_array_48b;
1018 int *fixup_map_sockmap = test->fixup_map_sockmap;
1019 int *fixup_map_sockhash = test->fixup_map_sockhash;
1020 int *fixup_map_xskmap = test->fixup_map_xskmap;
1021 int *fixup_map_stacktrace = test->fixup_map_stacktrace;
1022 int *fixup_prog1 = test->fixup_prog1;
1023 int *fixup_prog2 = test->fixup_prog2;
1024 int *fixup_map_in_map = test->fixup_map_in_map;
1025 int *fixup_cgroup_storage = test->fixup_cgroup_storage;
1026 int *fixup_percpu_cgroup_storage = test->fixup_percpu_cgroup_storage;
1027 int *fixup_map_spin_lock = test->fixup_map_spin_lock;
1028 int *fixup_map_array_ro = test->fixup_map_array_ro;
1029 int *fixup_map_array_wo = test->fixup_map_array_wo;
1030 int *fixup_map_array_small = test->fixup_map_array_small;
1031 int *fixup_sk_storage_map = test->fixup_sk_storage_map;
1032 int *fixup_map_event_output = test->fixup_map_event_output;
1033 int *fixup_map_reuseport_array = test->fixup_map_reuseport_array;
1034 int *fixup_map_ringbuf = test->fixup_map_ringbuf;
1035 int *fixup_map_timer = test->fixup_map_timer;
1036 int *fixup_map_kptr = test->fixup_map_kptr;
1038 if (test->fill_helper) {
1039 test->fill_insns = calloc(MAX_TEST_INSNS, sizeof(struct bpf_insn));
1040 test->fill_helper(test);
1043 /* Allocating HTs with 1 elem is fine here, since we only test
1237 fixup_prog_kfuncs(prog, fd_array, test->fixup_kfunc_btf_id);
1465 static bool check_xlated_program(struct bpf_test *test, int fd_prog)
1470 bool check_expected = !is_null_insn(test->expected_insns);
1471 bool check_unexpected = !is_null_insn(test->unexpected_insns);
1483 !find_all_insn_subseqs(buf, test->expected_insns,
1491 print_insn(test->expected_insns, MAX_EXPECTED_INSNS);
1496 find_all_insn_subseqs(buf, test->unexpected_insns,
1504 print_insn(test->unexpected_insns, MAX_UNEXPECTED_INSNS);
1513 static void do_test_single(struct bpf_test *test, bool unpriv,
1517 int prog_len, prog_type = test->prog_type;
1518 struct bpf_insn *prog = test->insns;
1529 if ((test->flags & F_NEEDS_JIT_ENABLED) && jit_disabled) {
1544 do_test_fixup(test, prog_type, prog, map_fds, &fd_array[1]);
1545 if (test->fill_insns) {
1546 prog = test->fill_insns;
1547 prog_len = test->prog_len;
1552 * features, skip this test.
1558 if (test->flags & F_LOAD_WITH_STRICT_ALIGNMENT)
1560 if (test->flags & F_NEEDS_EFFICIENT_UNALIGNED_ACCESS)
1562 if (test->flags & ~3)
1563 pflags |= test->flags;
1565 expected_ret = unpriv && test->result_unpriv != UNDEF ?
1566 test->result_unpriv : test->result;
1567 expected_err = unpriv && test->errstr_unpriv ?
1568 test->errstr_unpriv : test->errstr;
1570 opts.expected_attach_type = test->expected_attach_type;
1582 prog_type == BPF_PROG_TYPE_LSM) && test->kfunc) {
1585 attach_btf_id = libbpf_find_vmlinux_btf_id(test->kfunc,
1589 test->kfunc);
1597 if (test->btf_types[0] != 0) {
1598 btf_fd = load_btf_for_test(test);
1604 if (test->func_info_cnt != 0) {
1605 opts.func_info = test->func_info;
1606 opts.func_info_cnt = test->func_info_cnt;
1607 opts.func_info_rec_size = sizeof(test->func_info[0]);
1641 (test->flags & F_NEEDS_EFFICIENT_UNALIGNED_ACCESS))
1659 if (!unpriv && test->insn_processed) {
1665 if (test->insn_processed != insn_processed) {
1667 insn_processed, test->insn_processed);
1675 if (!check_xlated_program(test, fd_prog))
1680 if (!alignment_prevented_execution && fd_prog >= 0 && test->runs >= 0) {
1684 if (!test->runs)
1685 test->runs = 1;
1687 for (i = 0; i < test->runs; i++) {
1688 if (unpriv && test->retvals[i].retval_unpriv)
1689 expected_val = test->retvals[i].retval_unpriv;
1691 expected_val = test->retvals[i].retval;
1694 test->retvals[i].data,
1695 sizeof(test->retvals[i].data));
1697 printf("(run %d/%d) ", i + 1, test->runs);
1718 if (test->fill_insns)
1719 free(test->fill_insns);
1736 /* The test checks for finer cap as CAP_NET_ADMIN,
1748 static bool test_as_unpriv(struct bpf_test *test)
1760 if (test->flags & F_NEEDS_EFFICIENT_UNALIGNED_ACCESS)
1763 return !test->prog_type ||
1764 test->prog_type == BPF_PROG_TYPE_SOCKET_FILTER ||
1765 test->prog_type == BPF_PROG_TYPE_CGROUP_SKB;
1779 struct bpf_test *test = &tests[i];
1784 if (test_as_unpriv(test) && unpriv_disabled) {
1785 printf("#%d/u %s SKIP\n", i, test->descr);
1787 } else if (test_as_unpriv(test)) {
1790 printf("#%d/u %s ", i, test->descr);
1791 do_test_single(test, true, &passes, &errors);
1797 printf("#%d/p %s SKIP\n", i, test->descr);
1800 printf("#%d/p %s ", i, test->descr);
1801 do_test_single(test, false, &passes, &errors);