Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/bpf: Allow prog name matching for tests with __description

For tests that carry a __description tag, allow matching on both the
description string and program name for convenience. Before this commit,
the description string must be spelt out to filter the tests.

Suggested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20260407145606.3991770-1-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Kumar Kartikeya Dwivedi and committed by
Alexei Starovoitov
a8aa3067 1c22483a

+76 -20
+2 -2
tools/testing/selftests/bpf/progs/bpf_misc.h
··· 103 103 * - TEST_DATA_LEN 104 104 * __retval_unpriv Same, but load program in unprivileged mode. 105 105 * 106 - * __description Text to be used instead of a program name for display 107 - * and filtering purposes. 106 + * __description Text to be used for display and as an additional filter 107 + * alias, while the original program name stays matchable. 108 108 * 109 109 * __log_level Log level to use for the program, numeric value expected. 110 110 *
+37 -9
tools/testing/selftests/bpf/test_loader.c
··· 69 69 70 70 struct test_subspec { 71 71 char *name; 72 + char *description; 72 73 bool expect_failure; 73 74 struct expected_msgs expect_msgs; 74 75 struct expected_msgs expect_xlated; ··· 143 142 free_msgs(&spec->priv.stdout); 144 143 145 144 free(spec->priv.name); 145 + free(spec->priv.description); 146 146 free(spec->unpriv.name); 147 + free(spec->unpriv.description); 147 148 spec->priv.name = NULL; 149 + spec->priv.description = NULL; 148 150 spec->unpriv.name = NULL; 151 + spec->unpriv.description = NULL; 149 152 } 150 153 151 154 /* Compiles regular expression matching pattern. ··· 664 659 if (spec->mode_mask == 0) 665 660 spec->mode_mask = PRIV; 666 661 667 - if (!description) 668 - description = spec->prog_name; 669 - 670 662 if (spec->mode_mask & PRIV) { 671 - spec->priv.name = strdup(description); 663 + spec->priv.name = strdup(spec->prog_name); 672 664 if (!spec->priv.name) { 673 665 PRINT_FAIL("failed to allocate memory for priv.name\n"); 674 666 err = -ENOMEM; 675 667 goto cleanup; 676 668 } 669 + 670 + if (description) { 671 + spec->priv.description = strdup(description); 672 + if (!spec->priv.description) { 673 + PRINT_FAIL("failed to allocate memory for priv.description\n"); 674 + err = -ENOMEM; 675 + goto cleanup; 676 + } 677 + } 677 678 } 678 679 679 680 if (spec->mode_mask & UNPRIV) { 680 - int descr_len = strlen(description); 681 + int name_len = strlen(spec->prog_name); 681 682 const char *suffix = " @unpriv"; 683 + int suffix_len = strlen(suffix); 682 684 char *name; 683 685 684 - name = malloc(descr_len + strlen(suffix) + 1); 686 + name = malloc(name_len + suffix_len + 1); 685 687 if (!name) { 686 688 PRINT_FAIL("failed to allocate memory for unpriv.name\n"); 687 689 err = -ENOMEM; 688 690 goto cleanup; 689 691 } 690 692 691 - strcpy(name, description); 692 - strcpy(&name[descr_len], suffix); 693 + strcpy(name, spec->prog_name); 694 + strcpy(&name[name_len], suffix); 693 695 spec->unpriv.name = name; 696 + 697 + if (description) { 698 + int descr_len = strlen(description); 699 + char *descr; 700 + 701 + descr = malloc(descr_len + suffix_len + 1); 702 + if (!descr) { 703 + PRINT_FAIL("failed to allocate memory for unpriv.description\n"); 704 + err = -ENOMEM; 705 + goto cleanup; 706 + } 707 + 708 + strcpy(descr, description); 709 + strcpy(&descr[descr_len], suffix); 710 + spec->unpriv.description = descr; 711 + } 694 712 } 695 713 696 714 if (spec->mode_mask & (PRIV | UNPRIV)) { ··· 1176 1148 int links_cnt = 0; 1177 1149 bool should_load; 1178 1150 1179 - if (!test__start_subtest(subspec->name)) 1151 + if (!test__start_subtest_with_desc(subspec->name, subspec->description)) 1180 1152 return; 1181 1153 1182 1154 if ((get_current_arch() & spec->arch_mask) == 0) {
+36 -9
tools/testing/selftests/bpf/test_progs.c
··· 308 308 return false; 309 309 } 310 310 311 + static bool match_subtest_desc(struct test_filter_set *filter, 312 + const char *test_name, 313 + const char *subtest_name, 314 + const char *subtest_desc) 315 + { 316 + if (match_subtest(filter, test_name, subtest_name)) 317 + return true; 318 + 319 + if (!subtest_desc || !subtest_desc[0] || 320 + strcmp(subtest_name, subtest_desc) == 0) 321 + return false; 322 + 323 + return match_subtest(filter, test_name, subtest_desc); 324 + } 325 + 311 326 static bool should_run_subtest(struct test_selector *sel, 312 327 struct test_selector *subtest_sel, 313 328 int subtest_num, 314 329 const char *test_name, 315 - const char *subtest_name) 330 + const char *subtest_name, 331 + const char *subtest_desc) 316 332 { 317 - if (match_subtest(&sel->blacklist, test_name, subtest_name)) 333 + if (match_subtest_desc(&sel->blacklist, test_name, 334 + subtest_name, subtest_desc)) 318 335 return false; 319 336 320 - if (match_subtest(&sel->whitelist, test_name, subtest_name)) 337 + if (match_subtest_desc(&sel->whitelist, test_name, 338 + subtest_name, subtest_desc)) 321 339 return true; 322 340 323 341 if (!sel->whitelist.cnt && !subtest_sel->num_set) ··· 562 544 env.subtest_state = NULL; 563 545 } 564 546 565 - bool test__start_subtest(const char *subtest_name) 547 + bool test__start_subtest_with_desc(const char *subtest_name, const char *subtest_desc) 566 548 { 567 549 struct prog_test_def *test = env.test; 568 550 struct test_state *state = env.test_state; 569 551 struct subtest_state *subtest_state; 552 + const char *subtest_display_name; 570 553 size_t sub_state_size = sizeof(*subtest_state); 571 554 572 555 if (env.subtest_state) ··· 593 574 return false; 594 575 } 595 576 596 - subtest_state->name = strdup(subtest_name); 577 + subtest_display_name = subtest_desc ? subtest_desc : subtest_name; 578 + 579 + subtest_state->name = strdup(subtest_display_name); 597 580 if (!subtest_state->name) { 598 581 fprintf(env.stderr_saved, 599 582 "Subtest #%d: failed to copy subtest name!\n", ··· 607 586 &env.subtest_selector, 608 587 state->subtest_num, 609 588 test->test_name, 610 - subtest_name)) { 589 + subtest_name, 590 + subtest_desc)) { 611 591 subtest_state->filtered = true; 612 592 return false; 613 593 } 614 594 615 - subtest_state->should_tmon = match_subtest(&env.tmon_selector.whitelist, 616 - test->test_name, 617 - subtest_name); 595 + subtest_state->should_tmon = match_subtest_desc(&env.tmon_selector.whitelist, 596 + test->test_name, subtest_name, 597 + subtest_desc); 618 598 619 599 env.subtest_state = subtest_state; 620 600 stdio_hijack_init(&subtest_state->log_buf, &subtest_state->log_cnt); 621 601 watchdog_start(); 622 602 623 603 return true; 604 + } 605 + 606 + bool test__start_subtest(const char *subtest_name) 607 + { 608 + return test__start_subtest_with_desc(subtest_name, NULL); 624 609 } 625 610 626 611 void test__force_log(void)
+1
tools/testing/selftests/bpf/test_progs.h
··· 181 181 extern struct test_env env; 182 182 183 183 void test__force_log(void); 184 + bool test__start_subtest_with_desc(const char *name, const char *description); 184 185 bool test__start_subtest(const char *name); 185 186 void test__end_subtest(void); 186 187 void test__skip(void);