aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2012-11-09 19:46:50 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-11-14 14:50:19 -0500
commitcff7f956ec4a1ede9b752cfae3c12f588292ad80 (patch)
treebc8462de8d2aeedefc47047c9daeba374f6cf538 /tools
parentdc447eed59037c1c65feab9c72d372b6249af978 (diff)
perf tests: Move pmu tests into separate object
Separating pmu's object tests into pmu object under tests directory. Signed-off-by: Jiri Olsa <jolsa@redhat.com> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1352508412-16914-11-git-send-email-jolsa@redhat.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/Makefile1
-rw-r--r--tools/perf/tests/builtin-test.c7
-rw-r--r--tools/perf/tests/pmu.c178
-rw-r--r--tools/perf/tests/tests.h1
-rw-r--r--tools/perf/util/pmu.c185
-rw-r--r--tools/perf/util/pmu.h4
6 files changed, 191 insertions, 185 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 1e5055915549..9af012f37718 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -440,6 +440,7 @@ LIB_OBJS += $(OUTPUT)tests/perf-record.o
440LIB_OBJS += $(OUTPUT)tests/rdpmc.o 440LIB_OBJS += $(OUTPUT)tests/rdpmc.o
441LIB_OBJS += $(OUTPUT)tests/evsel-roundtrip-name.o 441LIB_OBJS += $(OUTPUT)tests/evsel-roundtrip-name.o
442LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o 442LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o
443LIB_OBJS += $(OUTPUT)tests/pmu.o
443LIB_OBJS += $(OUTPUT)tests/util.o 444LIB_OBJS += $(OUTPUT)tests/util.o
444 445
445BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o 446BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index bab849039852..d3b95e04b7a3 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -30,11 +30,6 @@
30#include <sched.h> 30#include <sched.h>
31 31
32 32
33static int test__perf_pmu(void)
34{
35 return perf_pmu__test();
36}
37
38static struct test { 33static struct test {
39 const char *desc; 34 const char *desc;
40 int (*func)(void); 35 int (*func)(void);
@@ -71,7 +66,7 @@ static struct test {
71 }, 66 },
72 { 67 {
73 .desc = "Test perf pmu format parsing", 68 .desc = "Test perf pmu format parsing",
74 .func = test__perf_pmu, 69 .func = test__pmu,
75 }, 70 },
76 { 71 {
77 .desc = "Test dso data interface", 72 .desc = "Test dso data interface",
diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c
new file mode 100644
index 000000000000..a5f379863b8f
--- /dev/null
+++ b/tools/perf/tests/pmu.c
@@ -0,0 +1,178 @@
1#include "parse-events.h"
2#include "pmu.h"
3#include "util.h"
4#include "tests.h"
5
6/* Simulated format definitions. */
7static struct test_format {
8 const char *name;
9 const char *value;
10} test_formats[] = {
11 { "krava01", "config:0-1,62-63\n", },
12 { "krava02", "config:10-17\n", },
13 { "krava03", "config:5\n", },
14 { "krava11", "config1:0,2,4,6,8,20-28\n", },
15 { "krava12", "config1:63\n", },
16 { "krava13", "config1:45-47\n", },
17 { "krava21", "config2:0-3,10-13,20-23,30-33,40-43,50-53,60-63\n", },
18 { "krava22", "config2:8,18,48,58\n", },
19 { "krava23", "config2:28-29,38\n", },
20};
21
22#define TEST_FORMATS_CNT (sizeof(test_formats) / sizeof(struct test_format))
23
24/* Simulated users input. */
25static struct parse_events__term test_terms[] = {
26 {
27 .config = (char *) "krava01",
28 .val.num = 15,
29 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
30 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
31 },
32 {
33 .config = (char *) "krava02",
34 .val.num = 170,
35 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
36 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
37 },
38 {
39 .config = (char *) "krava03",
40 .val.num = 1,
41 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
42 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
43 },
44 {
45 .config = (char *) "krava11",
46 .val.num = 27,
47 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
48 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
49 },
50 {
51 .config = (char *) "krava12",
52 .val.num = 1,
53 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
54 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
55 },
56 {
57 .config = (char *) "krava13",
58 .val.num = 2,
59 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
60 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
61 },
62 {
63 .config = (char *) "krava21",
64 .val.num = 119,
65 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
66 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
67 },
68 {
69 .config = (char *) "krava22",
70 .val.num = 11,
71 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
72 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
73 },
74 {
75 .config = (char *) "krava23",
76 .val.num = 2,
77 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
78 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
79 },
80};
81#define TERMS_CNT (sizeof(test_terms) / sizeof(struct parse_events__term))
82
83/*
84 * Prepare format directory data, exported by kernel
85 * at /sys/bus/event_source/devices/<dev>/format.
86 */
87static char *test_format_dir_get(void)
88{
89 static char dir[PATH_MAX];
90 unsigned int i;
91
92 snprintf(dir, PATH_MAX, "/tmp/perf-pmu-test-format-XXXXXX");
93 if (!mkdtemp(dir))
94 return NULL;
95
96 for (i = 0; i < TEST_FORMATS_CNT; i++) {
97 static char name[PATH_MAX];
98 struct test_format *format = &test_formats[i];
99 FILE *file;
100
101 snprintf(name, PATH_MAX, "%s/%s", dir, format->name);
102
103 file = fopen(name, "w");
104 if (!file)
105 return NULL;
106
107 if (1 != fwrite(format->value, strlen(format->value), 1, file))
108 break;
109
110 fclose(file);
111 }
112
113 return dir;
114}
115
116/* Cleanup format directory. */
117static int test_format_dir_put(char *dir)
118{
119 char buf[PATH_MAX];
120 snprintf(buf, PATH_MAX, "rm -f %s/*\n", dir);
121 if (system(buf))
122 return -1;
123
124 snprintf(buf, PATH_MAX, "rmdir %s\n", dir);
125 return system(buf);
126}
127
128static struct list_head *test_terms_list(void)
129{
130 static LIST_HEAD(terms);
131 unsigned int i;
132
133 for (i = 0; i < TERMS_CNT; i++)
134 list_add_tail(&test_terms[i].list, &terms);
135
136 return &terms;
137}
138
139#undef TERMS_CNT
140
141int test__pmu(void)
142{
143 char *format = test_format_dir_get();
144 LIST_HEAD(formats);
145 struct list_head *terms = test_terms_list();
146 int ret;
147
148 if (!format)
149 return -EINVAL;
150
151 do {
152 struct perf_event_attr attr;
153
154 memset(&attr, 0, sizeof(attr));
155
156 ret = perf_pmu__format_parse(format, &formats);
157 if (ret)
158 break;
159
160 ret = perf_pmu__config_terms(&formats, &attr, terms);
161 if (ret)
162 break;
163
164 ret = -EINVAL;
165
166 if (attr.config != 0xc00000000002a823)
167 break;
168 if (attr.config1 != 0x8000400000000145)
169 break;
170 if (attr.config2 != 0x0400000020041d07)
171 break;
172
173 ret = 0;
174 } while (0);
175
176 test_format_dir_put(format);
177 return ret;
178}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index f70f99848a22..88a55dfa99d0 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -11,6 +11,7 @@ int test__rdpmc(void);
11int test__perf_evsel__roundtrip_name_test(void); 11int test__perf_evsel__roundtrip_name_test(void);
12int test__perf_evsel__tp_sched_test(void); 12int test__perf_evsel__tp_sched_test(void);
13int test__syscall_open_tp_fields(void); 13int test__syscall_open_tp_fields(void);
14int test__pmu(void);
14 15
15/* Util */ 16/* Util */
16int trace_event__id(const char *evname); 17int trace_event__id(const char *evname);
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 18e84801d4d1..9bdc60c6f138 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -22,7 +22,7 @@ static LIST_HEAD(pmus);
22 * Parse & process all the sysfs attributes located under 22 * Parse & process all the sysfs attributes located under
23 * the directory specified in 'dir' parameter. 23 * the directory specified in 'dir' parameter.
24 */ 24 */
25static int pmu_format_parse(char *dir, struct list_head *head) 25int perf_pmu__format_parse(char *dir, struct list_head *head)
26{ 26{
27 struct dirent *evt_ent; 27 struct dirent *evt_ent;
28 DIR *format_dir; 28 DIR *format_dir;
@@ -77,7 +77,7 @@ static int pmu_format(char *name, struct list_head *format)
77 if (stat(path, &st) < 0) 77 if (stat(path, &st) < 0)
78 return 0; /* no error if format does not exist */ 78 return 0; /* no error if format does not exist */
79 79
80 if (pmu_format_parse(path, format)) 80 if (perf_pmu__format_parse(path, format))
81 return -1; 81 return -1;
82 82
83 return 0; 83 return 0;
@@ -446,8 +446,9 @@ static int pmu_config_term(struct list_head *formats,
446 return 0; 446 return 0;
447} 447}
448 448
449static int pmu_config(struct list_head *formats, struct perf_event_attr *attr, 449int perf_pmu__config_terms(struct list_head *formats,
450 struct list_head *head_terms) 450 struct perf_event_attr *attr,
451 struct list_head *head_terms)
451{ 452{
452 struct parse_events__term *term; 453 struct parse_events__term *term;
453 454
@@ -467,7 +468,7 @@ int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
467 struct list_head *head_terms) 468 struct list_head *head_terms)
468{ 469{
469 attr->type = pmu->type; 470 attr->type = pmu->type;
470 return pmu_config(&pmu->format, attr, head_terms); 471 return perf_pmu__config_terms(&pmu->format, attr, head_terms);
471} 472}
472 473
473static struct perf_pmu__alias *pmu_find_alias(struct perf_pmu *pmu, 474static struct perf_pmu__alias *pmu_find_alias(struct perf_pmu *pmu,
@@ -551,177 +552,3 @@ void perf_pmu__set_format(unsigned long *bits, long from, long to)
551 for (b = from; b <= to; b++) 552 for (b = from; b <= to; b++)
552 set_bit(b, bits); 553 set_bit(b, bits);
553} 554}
554
555/* Simulated format definitions. */
556static struct test_format {
557 const char *name;
558 const char *value;
559} test_formats[] = {
560 { "krava01", "config:0-1,62-63\n", },
561 { "krava02", "config:10-17\n", },
562 { "krava03", "config:5\n", },
563 { "krava11", "config1:0,2,4,6,8,20-28\n", },
564 { "krava12", "config1:63\n", },
565 { "krava13", "config1:45-47\n", },
566 { "krava21", "config2:0-3,10-13,20-23,30-33,40-43,50-53,60-63\n", },
567 { "krava22", "config2:8,18,48,58\n", },
568 { "krava23", "config2:28-29,38\n", },
569};
570
571#define TEST_FORMATS_CNT (sizeof(test_formats) / sizeof(struct test_format))
572
573/* Simulated users input. */
574static struct parse_events__term test_terms[] = {
575 {
576 .config = (char *) "krava01",
577 .val.num = 15,
578 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
579 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
580 },
581 {
582 .config = (char *) "krava02",
583 .val.num = 170,
584 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
585 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
586 },
587 {
588 .config = (char *) "krava03",
589 .val.num = 1,
590 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
591 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
592 },
593 {
594 .config = (char *) "krava11",
595 .val.num = 27,
596 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
597 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
598 },
599 {
600 .config = (char *) "krava12",
601 .val.num = 1,
602 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
603 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
604 },
605 {
606 .config = (char *) "krava13",
607 .val.num = 2,
608 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
609 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
610 },
611 {
612 .config = (char *) "krava21",
613 .val.num = 119,
614 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
615 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
616 },
617 {
618 .config = (char *) "krava22",
619 .val.num = 11,
620 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
621 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
622 },
623 {
624 .config = (char *) "krava23",
625 .val.num = 2,
626 .type_val = PARSE_EVENTS__TERM_TYPE_NUM,
627 .type_term = PARSE_EVENTS__TERM_TYPE_USER,
628 },
629};
630#define TERMS_CNT (sizeof(test_terms) / sizeof(struct parse_events__term))
631
632/*
633 * Prepare format directory data, exported by kernel
634 * at /sys/bus/event_source/devices/<dev>/format.
635 */
636static char *test_format_dir_get(void)
637{
638 static char dir[PATH_MAX];
639 unsigned int i;
640
641 snprintf(dir, PATH_MAX, "/tmp/perf-pmu-test-format-XXXXXX");
642 if (!mkdtemp(dir))
643 return NULL;
644
645 for (i = 0; i < TEST_FORMATS_CNT; i++) {
646 static char name[PATH_MAX];
647 struct test_format *format = &test_formats[i];
648 FILE *file;
649
650 snprintf(name, PATH_MAX, "%s/%s", dir, format->name);
651
652 file = fopen(name, "w");
653 if (!file)
654 return NULL;
655
656 if (1 != fwrite(format->value, strlen(format->value), 1, file))
657 break;
658
659 fclose(file);
660 }
661
662 return dir;
663}
664
665/* Cleanup format directory. */
666static int test_format_dir_put(char *dir)
667{
668 char buf[PATH_MAX];
669 snprintf(buf, PATH_MAX, "rm -f %s/*\n", dir);
670 if (system(buf))
671 return -1;
672
673 snprintf(buf, PATH_MAX, "rmdir %s\n", dir);
674 return system(buf);
675}
676
677static struct list_head *test_terms_list(void)
678{
679 static LIST_HEAD(terms);
680 unsigned int i;
681
682 for (i = 0; i < TERMS_CNT; i++)
683 list_add_tail(&test_terms[i].list, &terms);
684
685 return &terms;
686}
687
688#undef TERMS_CNT
689
690int perf_pmu__test(void)
691{
692 char *format = test_format_dir_get();
693 LIST_HEAD(formats);
694 struct list_head *terms = test_terms_list();
695 int ret;
696
697 if (!format)
698 return -EINVAL;
699
700 do {
701 struct perf_event_attr attr;
702
703 memset(&attr, 0, sizeof(attr));
704
705 ret = pmu_format_parse(format, &formats);
706 if (ret)
707 break;
708
709 ret = pmu_config(&formats, &attr, terms);
710 if (ret)
711 break;
712
713 ret = -EINVAL;
714
715 if (attr.config != 0xc00000000002a823)
716 break;
717 if (attr.config1 != 0x8000400000000145)
718 break;
719 if (attr.config2 != 0x0400000020041d07)
720 break;
721
722 ret = 0;
723 } while (0);
724
725 test_format_dir_put(format);
726 return ret;
727}
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 39f3abac7744..07d553fe8d83 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -37,6 +37,9 @@ struct perf_pmu {
37struct perf_pmu *perf_pmu__find(char *name); 37struct perf_pmu *perf_pmu__find(char *name);
38int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, 38int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
39 struct list_head *head_terms); 39 struct list_head *head_terms);
40int perf_pmu__config_terms(struct list_head *formats,
41 struct perf_event_attr *attr,
42 struct list_head *head_terms);
40int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms); 43int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms);
41struct list_head *perf_pmu__alias(struct perf_pmu *pmu, 44struct list_head *perf_pmu__alias(struct perf_pmu *pmu,
42 struct list_head *head_terms); 45 struct list_head *head_terms);
@@ -46,6 +49,7 @@ void perf_pmu_error(struct list_head *list, char *name, char const *msg);
46int perf_pmu__new_format(struct list_head *list, char *name, 49int perf_pmu__new_format(struct list_head *list, char *name,
47 int config, unsigned long *bits); 50 int config, unsigned long *bits);
48void perf_pmu__set_format(unsigned long *bits, long from, long to); 51void perf_pmu__set_format(unsigned long *bits, long from, long to);
52int perf_pmu__format_parse(char *dir, struct list_head *head);
49 53
50struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu); 54struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu);
51 55