aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/parse-events-test.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2012-06-15 02:31:42 -0400
committerIngo Molnar <mingo@kernel.org>2012-06-18 06:13:26 -0400
commit4429392e1484319df4209d41a98244c76d0caf56 (patch)
treefa8bb52d2e46dc60384fe1c4740fce9c2bf31dd3 /tools/perf/util/parse-events-test.c
parenta6146d5040cce560f700221158d77dd335eed332 (diff)
perf/tool: Add automated test for pure terms parsing
Adding automated test for parsing terms out of the event grammar. Also slightly changing current event parsing test functions to follow up more generic namespace. Signed-off-by: Jiri Olsa <jolsa@redhat.com> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1339741902-8449-14-git-send-email-zheng.z.yan@intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/perf/util/parse-events-test.c')
-rw-r--r--tools/perf/util/parse-events-test.c122
1 files changed, 117 insertions, 5 deletions
diff --git a/tools/perf/util/parse-events-test.c b/tools/perf/util/parse-events-test.c
index 76b98e2a587d..af1039cdb853 100644
--- a/tools/perf/util/parse-events-test.c
+++ b/tools/perf/util/parse-events-test.c
@@ -430,6 +430,49 @@ static int test__checkevent_pmu_name(struct perf_evlist *evlist)
430 return 0; 430 return 0;
431} 431}
432 432
433static int test__checkterms_simple(struct list_head *terms)
434{
435 struct parse_events__term *term;
436
437 /* config=10 */
438 term = list_entry(terms->next, struct parse_events__term, list);
439 TEST_ASSERT_VAL("wrong type term",
440 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG);
441 TEST_ASSERT_VAL("wrong type val",
442 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
443 TEST_ASSERT_VAL("wrong val", term->val.num == 10);
444 TEST_ASSERT_VAL("wrong config", !term->config);
445
446 /* config1 */
447 term = list_entry(term->list.next, struct parse_events__term, list);
448 TEST_ASSERT_VAL("wrong type term",
449 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG1);
450 TEST_ASSERT_VAL("wrong type val",
451 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
452 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
453 TEST_ASSERT_VAL("wrong config", !term->config);
454
455 /* config2=3 */
456 term = list_entry(term->list.next, struct parse_events__term, list);
457 TEST_ASSERT_VAL("wrong type term",
458 term->type_term == PARSE_EVENTS__TERM_TYPE_CONFIG2);
459 TEST_ASSERT_VAL("wrong type val",
460 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
461 TEST_ASSERT_VAL("wrong val", term->val.num == 3);
462 TEST_ASSERT_VAL("wrong config", !term->config);
463
464 /* umask=1*/
465 term = list_entry(term->list.next, struct parse_events__term, list);
466 TEST_ASSERT_VAL("wrong type term",
467 term->type_term == PARSE_EVENTS__TERM_TYPE_USER);
468 TEST_ASSERT_VAL("wrong type val",
469 term->type_val == PARSE_EVENTS__TERM_TYPE_NUM);
470 TEST_ASSERT_VAL("wrong val", term->val.num == 1);
471 TEST_ASSERT_VAL("wrong config", !strcmp(term->config, "umask"));
472
473 return 0;
474}
475
433struct test__event_st { 476struct test__event_st {
434 const char *name; 477 const char *name;
435 __u32 type; 478 __u32 type;
@@ -559,7 +602,23 @@ static struct test__event_st test__events_pmu[] = {
559#define TEST__EVENTS_PMU_CNT (sizeof(test__events_pmu) / \ 602#define TEST__EVENTS_PMU_CNT (sizeof(test__events_pmu) / \
560 sizeof(struct test__event_st)) 603 sizeof(struct test__event_st))
561 604
562static int test(struct test__event_st *e) 605struct test__term {
606 const char *str;
607 __u32 type;
608 int (*check)(struct list_head *terms);
609};
610
611static struct test__term test__terms[] = {
612 [0] = {
613 .str = "config=10,config1,config2=3,umask=1",
614 .check = test__checkterms_simple,
615 },
616};
617
618#define TEST__TERMS_CNT (sizeof(test__terms) / \
619 sizeof(struct test__term))
620
621static int test_event(struct test__event_st *e)
563{ 622{
564 struct perf_evlist *evlist; 623 struct perf_evlist *evlist;
565 int ret; 624 int ret;
@@ -590,7 +649,48 @@ static int test_events(struct test__event_st *events, unsigned cnt)
590 struct test__event_st *e = &events[i]; 649 struct test__event_st *e = &events[i];
591 650
592 pr_debug("running test %d '%s'\n", i, e->name); 651 pr_debug("running test %d '%s'\n", i, e->name);
593 ret = test(e); 652 ret = test_event(e);
653 if (ret)
654 break;
655 }
656
657 return ret;
658}
659
660static int test_term(struct test__term *t)
661{
662 struct list_head *terms;
663 int ret;
664
665 terms = malloc(sizeof(*terms));
666 if (!terms)
667 return -ENOMEM;
668
669 INIT_LIST_HEAD(terms);
670
671 ret = parse_events_terms(terms, t->str);
672 if (ret) {
673 pr_debug("failed to parse terms '%s', err %d\n",
674 t->str , ret);
675 return ret;
676 }
677
678 ret = t->check(terms);
679 parse_events__free_terms(terms);
680
681 return ret;
682}
683
684static int test_terms(struct test__term *terms, unsigned cnt)
685{
686 int ret = 0;
687 unsigned i;
688
689 for (i = 0; i < cnt; i++) {
690 struct test__term *t = &terms[i];
691
692 pr_debug("running test %d '%s'\n", i, t->str);
693 ret = test_term(t);
594 if (ret) 694 if (ret)
595 break; 695 break;
596 } 696 }
@@ -617,9 +717,21 @@ int parse_events__test(void)
617{ 717{
618 int ret; 718 int ret;
619 719
620 ret = test_events(test__events, TEST__EVENTS_CNT); 720 do {
621 if (!ret && test_pmu()) 721 ret = test_events(test__events, TEST__EVENTS_CNT);
622 ret = test_events(test__events_pmu, TEST__EVENTS_PMU_CNT); 722 if (ret)
723 break;
724
725 if (test_pmu()) {
726 ret = test_events(test__events_pmu,
727 TEST__EVENTS_PMU_CNT);
728 if (ret)
729 break;
730 }
731
732 ret = test_terms(test__terms, TEST__TERMS_CNT);
733
734 } while (0);
623 735
624 return ret; 736 return ret;
625} 737}