@@ -453,12 +453,90 @@ static int test__name_cmp(struct test_suite *test __maybe_unused, int subtest __
453
453
return TEST_OK ;
454
454
}
455
455
456
+ /**
457
+ * Test perf_pmu__match() that's used to search for a PMU given a name passed
458
+ * on the command line. The name that's passed may also be a filename type glob
459
+ * match.
460
+ */
461
+ static int test__pmu_match (struct test_suite * test __maybe_unused , int subtest __maybe_unused )
462
+ {
463
+ struct perf_pmu test_pmu ;
464
+
465
+ test_pmu .name = "pmuname" ;
466
+ TEST_ASSERT_EQUAL ("Exact match" , perf_pmu__match (& test_pmu , "pmuname" ), true);
467
+ TEST_ASSERT_EQUAL ("Longer token" , perf_pmu__match (& test_pmu , "longertoken" ), false);
468
+ TEST_ASSERT_EQUAL ("Shorter token" , perf_pmu__match (& test_pmu , "pmu" ), false);
469
+
470
+ test_pmu .name = "pmuname_10" ;
471
+ TEST_ASSERT_EQUAL ("Diff suffix_" , perf_pmu__match (& test_pmu , "pmuname_2" ), false);
472
+ TEST_ASSERT_EQUAL ("Sub suffix_" , perf_pmu__match (& test_pmu , "pmuname_1" ), true);
473
+ TEST_ASSERT_EQUAL ("Same suffix_" , perf_pmu__match (& test_pmu , "pmuname_10" ), true);
474
+ TEST_ASSERT_EQUAL ("No suffix_" , perf_pmu__match (& test_pmu , "pmuname" ), true);
475
+ TEST_ASSERT_EQUAL ("Underscore_" , perf_pmu__match (& test_pmu , "pmuname_" ), true);
476
+ TEST_ASSERT_EQUAL ("Substring_" , perf_pmu__match (& test_pmu , "pmuna" ), false);
477
+
478
+ test_pmu .name = "pmuname_ab23" ;
479
+ TEST_ASSERT_EQUAL ("Diff suffix hex_" , perf_pmu__match (& test_pmu , "pmuname_2" ), false);
480
+ TEST_ASSERT_EQUAL ("Sub suffix hex_" , perf_pmu__match (& test_pmu , "pmuname_ab" ), true);
481
+ TEST_ASSERT_EQUAL ("Same suffix hex_" , perf_pmu__match (& test_pmu , "pmuname_ab23" ), true);
482
+ TEST_ASSERT_EQUAL ("No suffix hex_" , perf_pmu__match (& test_pmu , "pmuname" ), true);
483
+ TEST_ASSERT_EQUAL ("Underscore hex_" , perf_pmu__match (& test_pmu , "pmuname_" ), true);
484
+ TEST_ASSERT_EQUAL ("Substring hex_" , perf_pmu__match (& test_pmu , "pmuna" ), false);
485
+
486
+ test_pmu .name = "pmuname10" ;
487
+ TEST_ASSERT_EQUAL ("Diff suffix" , perf_pmu__match (& test_pmu , "pmuname2" ), false);
488
+ TEST_ASSERT_EQUAL ("Sub suffix" , perf_pmu__match (& test_pmu , "pmuname1" ), true);
489
+ TEST_ASSERT_EQUAL ("Same suffix" , perf_pmu__match (& test_pmu , "pmuname10" ), true);
490
+ TEST_ASSERT_EQUAL ("No suffix" , perf_pmu__match (& test_pmu , "pmuname" ), true);
491
+ TEST_ASSERT_EQUAL ("Underscore" , perf_pmu__match (& test_pmu , "pmuname_" ), false);
492
+ TEST_ASSERT_EQUAL ("Substring" , perf_pmu__match (& test_pmu , "pmuna" ), false);
493
+
494
+ test_pmu .name = "pmunameab23" ;
495
+ TEST_ASSERT_EQUAL ("Diff suffix hex" , perf_pmu__match (& test_pmu , "pmuname2" ), false);
496
+ TEST_ASSERT_EQUAL ("Sub suffix hex" , perf_pmu__match (& test_pmu , "pmunameab" ), true);
497
+ TEST_ASSERT_EQUAL ("Same suffix hex" , perf_pmu__match (& test_pmu , "pmunameab23" ), true);
498
+ TEST_ASSERT_EQUAL ("No suffix hex" , perf_pmu__match (& test_pmu , "pmuname" ), true);
499
+ TEST_ASSERT_EQUAL ("Underscore hex" , perf_pmu__match (& test_pmu , "pmuname_" ), false);
500
+ TEST_ASSERT_EQUAL ("Substring hex" , perf_pmu__match (& test_pmu , "pmuna" ), false);
501
+
502
+ /*
503
+ * 2 hex chars or less are not considered suffixes so it shouldn't be
504
+ * possible to wildcard by skipping the suffix. Therefore there are more
505
+ * false results here than above.
506
+ */
507
+ test_pmu .name = "pmuname_a3" ;
508
+ TEST_ASSERT_EQUAL ("Diff suffix 2 hex_" , perf_pmu__match (& test_pmu , "pmuname_2" ), false);
509
+ /*
510
+ * This one should be false, but because pmuname_a3 ends in 3 which is
511
+ * decimal, it's not possible to determine if it's a short hex suffix or
512
+ * a normal decimal suffix following text. And we want to match on any
513
+ * length of decimal suffix. Run the test anyway and expect the wrong
514
+ * result. And slightly fuzzy matching shouldn't do too much harm.
515
+ */
516
+ TEST_ASSERT_EQUAL ("Sub suffix 2 hex_" , perf_pmu__match (& test_pmu , "pmuname_a" ), true);
517
+ TEST_ASSERT_EQUAL ("Same suffix 2 hex_" , perf_pmu__match (& test_pmu , "pmuname_a3" ), true);
518
+ TEST_ASSERT_EQUAL ("No suffix 2 hex_" , perf_pmu__match (& test_pmu , "pmuname" ), false);
519
+ TEST_ASSERT_EQUAL ("Underscore 2 hex_" , perf_pmu__match (& test_pmu , "pmuname_" ), false);
520
+ TEST_ASSERT_EQUAL ("Substring 2 hex_" , perf_pmu__match (& test_pmu , "pmuna" ), false);
521
+
522
+ test_pmu .name = "pmuname_5" ;
523
+ TEST_ASSERT_EQUAL ("Glob 1" , perf_pmu__match (& test_pmu , "pmu*" ), true);
524
+ TEST_ASSERT_EQUAL ("Glob 2" , perf_pmu__match (& test_pmu , "nomatch*" ), false);
525
+ TEST_ASSERT_EQUAL ("Seq 1" , perf_pmu__match (& test_pmu , "pmuname_[12345]" ), true);
526
+ TEST_ASSERT_EQUAL ("Seq 2" , perf_pmu__match (& test_pmu , "pmuname_[67890]" ), false);
527
+ TEST_ASSERT_EQUAL ("? 1" , perf_pmu__match (& test_pmu , "pmuname_?" ), true);
528
+ TEST_ASSERT_EQUAL ("? 2" , perf_pmu__match (& test_pmu , "pmuname_1?" ), false);
529
+
530
+ return TEST_OK ;
531
+ }
532
+
456
533
static struct test_case tests__pmu [] = {
457
534
TEST_CASE ("Parsing with PMU format directory" , pmu_format ),
458
535
TEST_CASE ("Parsing with PMU event" , pmu_events ),
459
536
TEST_CASE ("PMU event names" , pmu_event_names ),
460
537
TEST_CASE ("PMU name combining" , name_len ),
461
538
TEST_CASE ("PMU name comparison" , name_cmp ),
539
+ TEST_CASE ("PMU cmdline match" , pmu_match ),
462
540
{ .name = NULL , }
463
541
};
464
542
0 commit comments