Lines Matching +full:spec +full:-

1 // SPDX-License-Identifier: GPL-2.0-only
16 (strncmp(str, pfx, __builtin_constant_p(pfx) ? sizeof(pfx) - 1 : strlen(pfx)) == 0)
51 static int sysctl_unpriv_disabled = -1;
96 if (!tester->log_buf) {
97 tester->log_buf_sz = TEST_LOADER_LOG_BUF_SZ;
98 tester->log_buf = calloc(tester->log_buf_sz, 1);
99 if (!ASSERT_OK_PTR(tester->log_buf, "tester_log_buf"))
100 return -ENOMEM;
111 free(tester->log_buf);
118 for (i = 0; i < msgs->cnt; i++)
119 if (msgs->patterns[i].is_regex)
120 regfree(&msgs->patterns[i].regex);
121 free(msgs->patterns);
122 msgs->patterns = NULL;
123 msgs->cnt = 0;
126 static void free_test_spec(struct test_spec *spec)
129 free_msgs(&spec->priv.expect_msgs);
130 free_msgs(&spec->unpriv.expect_msgs);
131 free_msgs(&spec->priv.expect_xlated);
132 free_msgs(&spec->unpriv.expect_xlated);
133 free_msgs(&spec->priv.jited);
134 free_msgs(&spec->unpriv.jited);
136 free(spec->priv.name);
137 free(spec->unpriv.name);
138 spec->priv.name = NULL;
139 spec->unpriv.name = NULL;
150 * For example, pattern "foo{{[0-9]+}}" matches strings like
162 while (*pattern && ptr < buf_end - 2) {
187 return -EINVAL;
191 return -EINVAL;
197 return -EINVAL;
208 tmp = realloc(msgs->patterns,
209 (1 + msgs->cnt) * sizeof(struct expect_msg));
212 return -ENOMEM;
214 msgs->patterns = tmp;
215 msg = &msgs->patterns[msgs->cnt];
216 msg->on_next_line = on_next_line;
217 msg->substr = pattern;
218 msg->is_regex = false;
220 err = compile_regex(pattern, &msg->regex);
223 msg->is_regex = true;
225 msgs->cnt += 1;
234 for (i = 0; i < from->cnt; i++) {
235 msg = &from->patterns[i];
236 err = __push_msg(msg->substr, msg->on_next_line, to);
275 return -EINVAL;
289 return -EINVAL;
295 if (!strncmp("CAP_", token, sizeof("CAP_") - 1)) {
297 return -EINVAL;
302 return -EINVAL;
346 * Test suite uses two-component tags for such cases:
353 * [18] DECL_TAG 'comment:test_expect_msg=0=foo' type_id=15 component_idx=-1
354 * [19] DECL_TAG 'comment:test_expect_msg=1=foo' type_id=15 component_idx=-1
397 struct test_spec *spec)
412 memset(spec, 0, sizeof(*spec));
414 spec->prog_name = bpf_program__name(prog);
415 spec->prog_flags = testing_prog_flags();
420 return -EINVAL;
423 func_id = btf__find_by_name_kind(btf, spec->prog_name, BTF_KIND_FUNC);
425 ASSERT_FAIL("failed to find FUNC BTF type for '%s'", spec->prog_name);
426 return -EINVAL;
439 if (t->type != func_id || btf_decl_tag(t)->component_idx != -1)
442 s = btf__str_by_offset(btf, t->name_off);
444 description = s + sizeof(TEST_TAG_DESCRIPTION_PFX) - 1;
446 spec->priv.expect_failure = true;
447 spec->mode_mask |= PRIV;
449 spec->priv.expect_failure = false;
450 spec->mode_mask |= PRIV;
452 spec->unpriv.expect_failure = true;
453 spec->mode_mask |= UNPRIV;
456 spec->unpriv.expect_failure = false;
457 spec->mode_mask |= UNPRIV;
460 spec->auxiliary = true;
461 spec->mode_mask |= PRIV;
463 spec->auxiliary = true;
464 spec->mode_mask |= UNPRIV;
466 err = push_msg(msg, &spec->priv.expect_msgs);
469 spec->mode_mask |= PRIV;
471 err = push_msg(msg, &spec->unpriv.expect_msgs);
474 spec->mode_mask |= UNPRIV;
482 &spec->priv.jited);
485 spec->mode_mask |= PRIV;
494 &spec->unpriv.jited);
497 spec->mode_mask |= UNPRIV;
501 &spec->priv.expect_xlated);
504 spec->mode_mask |= PRIV;
507 &spec->unpriv.expect_xlated);
510 spec->mode_mask |= UNPRIV;
512 val = s + sizeof(TEST_TAG_RETVAL_PFX) - 1;
513 err = parse_retval(val, &spec->priv.retval, "__retval");
516 spec->priv.execute = true;
517 spec->mode_mask |= PRIV;
519 val = s + sizeof(TEST_TAG_RETVAL_PFX_UNPRIV) - 1;
520 err = parse_retval(val, &spec->unpriv.retval, "__retval_unpriv");
523 spec->mode_mask |= UNPRIV;
524 spec->unpriv.execute = true;
527 val = s + sizeof(TEST_TAG_LOG_LEVEL_PFX) - 1;
528 err = parse_int(val, &spec->log_level, "test log level");
532 val = s + sizeof(TEST_TAG_PROG_FLAGS_PFX) - 1;
539 update_flags(&spec->prog_flags, BPF_F_STRICT_ALIGNMENT, clear);
541 update_flags(&spec->prog_flags, BPF_F_ANY_ALIGNMENT, clear);
543 update_flags(&spec->prog_flags, BPF_F_TEST_RND_HI32, clear);
545 update_flags(&spec->prog_flags, BPF_F_TEST_STATE_FREQ, clear);
547 update_flags(&spec->prog_flags, BPF_F_SLEEPABLE, clear);
549 update_flags(&spec->prog_flags, BPF_F_XDP_HAS_FRAGS, clear);
551 update_flags(&spec->prog_flags, BPF_F_TEST_REG_INVARIANTS, clear);
556 update_flags(&spec->prog_flags, flags, clear);
559 val = s + sizeof(TEST_TAG_ARCH) - 1;
567 PRINT_FAIL("bad arch spec: '%s'", val);
568 err = -EINVAL;
576 spec->btf_custom_path = s + sizeof(TEST_BTF_PATH) - 1;
578 val = s + sizeof(TEST_TAG_CAPS_UNPRIV) - 1;
579 err = parse_caps(val, &spec->unpriv.caps, "test caps");
582 spec->mode_mask |= UNPRIV;
586 spec->arch_mask = arch_mask ?: -1;
588 if (spec->mode_mask == 0)
589 spec->mode_mask = PRIV;
592 description = spec->prog_name;
594 if (spec->mode_mask & PRIV) {
595 spec->priv.name = strdup(description);
596 if (!spec->priv.name) {
598 err = -ENOMEM;
603 if (spec->mode_mask & UNPRIV) {
611 err = -ENOMEM;
617 spec->unpriv.name = name;
620 if (spec->mode_mask & (PRIV | UNPRIV)) {
622 spec->unpriv.expect_failure = spec->priv.expect_failure;
625 spec->unpriv.retval = spec->priv.retval;
626 spec->unpriv.execute = spec->priv.execute;
629 if (spec->unpriv.expect_msgs.cnt == 0)
630 clone_msgs(&spec->priv.expect_msgs, &spec->unpriv.expect_msgs);
631 if (spec->unpriv.expect_xlated.cnt == 0)
632 clone_msgs(&spec->priv.expect_xlated, &spec->unpriv.expect_xlated);
633 if (spec->unpriv.jited.cnt == 0)
634 clone_msgs(&spec->priv.jited, &spec->unpriv.jited);
637 spec->valid = true;
642 free_test_spec(spec);
647 struct test_spec *spec,
658 bpf_program__set_log_buf(prog, tester->log_buf, tester->log_buf_sz);
664 if ((spec->log_level & 3) < min_log_level)
665 bpf_program__set_log_level(prog, (spec->log_level & 4) | min_log_level);
667 bpf_program__set_log_level(prog, spec->log_level);
670 bpf_program__set_flags(prog, prog_flags | spec->prog_flags);
672 tester->log_buf[0] = '\0';
705 prev_match_line = -1;
708 for (i = 0; i < msgs->cnt; i++) {
709 struct expect_msg *msg = &msgs->patterns[i];
713 if (!msg->is_regex) {
714 match = strstr(log, msg->substr);
716 log = match + strlen(msg->substr);
718 err = regexec(&msg->regex, log, 1, reg_match, 0);
729 wrong_line = msg->on_next_line && prev_match_line >= 0 &&
738 msg = &msgs->patterns[j];
745 msg = &msgs->patterns[j];
748 msg->is_regex ? " REGEX" : "SUBSTR",
749 msg->substr);
774 err = cap_disable_effective(caps_to_drop, &caps->old_caps);
780 caps->initialized = true;
788 if (!caps->initialized)
791 err = cap_enable_effective(caps->old_caps, NULL);
794 caps->initialized = false;
798 static bool can_execute_unpriv(struct test_loader *tester, struct test_spec *spec)
804 if ((spec->prog_flags & BPF_F_ANY_ALIGNMENT) && !EFFICIENT_UNALIGNED_ACCESS)
870 static bool should_do_test_run(struct test_spec *spec, struct test_subspec *subspec)
872 if (!subspec->execute)
875 if (subspec->expect_failure)
878 if ((spec->prog_flags & BPF_F_ANY_ALIGNMENT) && !EFFICIENT_UNALIGNED_ACCESS) {
905 i = insn - insn_start;
927 struct test_spec *spec,
930 struct test_subspec *subspec = unpriv ? &spec->unpriv : &spec->priv;
941 if (!test__start_subtest(subspec->name))
944 if ((get_current_arch() & spec->arch_mask) == 0) {
950 if (!can_execute_unpriv(tester, spec)) {
959 if (subspec->caps) {
960 err = cap_enable_effective(subspec->caps, NULL);
969 open_opts->btf_custom_path = spec->btf_custom_path;
980 if (spec_iter->valid) {
981 if (strcmp(bpf_program__name(tprog_iter), spec->prog_name) == 0) {
986 if (spec_iter->auxiliary &&
987 spec_iter->mode_mask & (unpriv ? UNPRIV : PRIV))
994 prepare_case(tester, spec, tobj, tprog);
1005 if (subspec->expect_failure) {
1007 emit_verifier_log(tester->log_buf, false /*force*/);
1012 emit_verifier_log(tester->log_buf, true /*force*/);
1016 emit_verifier_log(tester->log_buf, false /*force*/);
1017 validate_msgs(tester->log_buf, &subspec->expect_msgs, emit_verifier_log);
1019 if (subspec->expect_xlated.cnt) {
1021 tester->log_buf, tester->log_buf_sz);
1024 emit_xlated(tester->log_buf, false /*force*/);
1025 validate_msgs(tester->log_buf, &subspec->expect_xlated, emit_xlated);
1028 if (subspec->jited.cnt) {
1030 tester->log_buf, tester->log_buf_sz);
1031 if (err == -EOPNOTSUPP) {
1039 emit_jited(tester->log_buf, false /*force*/);
1040 validate_msgs(tester->log_buf, &subspec->jited, emit_jited);
1043 if (should_do_test_run(spec, subspec)) {
1051 * This should trigger bpf_struct_ops->reg callback on kernel side.
1070 if (tester->pre_execution_cb) {
1071 err = tester->pre_execution_cb(tobj);
1080 if (retval != subspec->retval && subspec->retval != POINTER_VALUE) {
1081 PRINT_FAIL("Unexpected retval: %d != %d\n", retval, subspec->retval);
1086 bpf_link__destroy(links[--links_cnt]);
1091 bpf_link__destroy(links[--links_cnt]);
1131 PRINT_FAIL("Can't parse test spec for program '%s'\n",
1137 struct test_spec *spec = &specs[i++];
1139 if (!spec->valid || spec->auxiliary)
1142 if (spec->mode_mask & PRIV)
1144 specs, spec, false);
1145 if (spec->mode_mask & UNPRIV)
1147 specs, spec, true);