These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / tools / perf / tests / parse-events.c
index 3de7449..636d7b4 100644 (file)
@@ -3,11 +3,11 @@
 #include "evsel.h"
 #include "evlist.h"
 #include <api/fs/fs.h>
-#include <api/fs/tracefs.h>
-#include <api/fs/debugfs.h>
 #include "tests.h"
 #include "debug.h"
+#include "util.h"
 #include <linux/hw_breakpoint.h>
+#include <api/fs/fs.h>
 
 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
                             PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
@@ -82,8 +82,12 @@ static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
        TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
        TEST_ASSERT_VAL("wrong config",
                        PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
+       /*
+        * The period value gets configured within perf_evlist__config,
+        * while this test executes only parse events method.
+        */
        TEST_ASSERT_VAL("wrong period",
-                       100000 == evsel->attr.sample_period);
+                       0 == evsel->attr.sample_period);
        TEST_ASSERT_VAL("wrong config1",
                        0 == evsel->attr.config1);
        TEST_ASSERT_VAL("wrong config2",
@@ -406,7 +410,11 @@ static int test__checkevent_pmu(struct perf_evlist *evlist)
        TEST_ASSERT_VAL("wrong config",    10 == evsel->attr.config);
        TEST_ASSERT_VAL("wrong config1",    1 == evsel->attr.config1);
        TEST_ASSERT_VAL("wrong config2",    3 == evsel->attr.config2);
-       TEST_ASSERT_VAL("wrong period",  1000 == evsel->attr.sample_period);
+       /*
+        * The period value gets configured within perf_evlist__config,
+        * while this test executes only parse events method.
+        */
+       TEST_ASSERT_VAL("wrong period",     0 == evsel->attr.sample_period);
 
        return 0;
 }
@@ -427,7 +435,7 @@ static int test__checkevent_list(struct perf_evlist *evlist)
        TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv);
        TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip);
 
-       /* syscalls:sys_enter_open:k */
+       /* syscalls:sys_enter_openat:k */
        evsel = perf_evsel__next(evsel);
        TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
        TEST_ASSERT_VAL("wrong sample_type",
@@ -471,6 +479,39 @@ static int test__checkevent_pmu_name(struct perf_evlist *evlist)
        return 0;
 }
 
+static int test__checkevent_pmu_partial_time_callgraph(struct perf_evlist *evlist)
+{
+       struct perf_evsel *evsel = perf_evlist__first(evlist);
+
+       /* cpu/config=1,call-graph=fp,time,period=100000/ */
+       TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
+       TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
+       TEST_ASSERT_VAL("wrong config",  1 == evsel->attr.config);
+       /*
+        * The period, time and callgraph value gets configured
+        * within perf_evlist__config,
+        * while this test executes only parse events method.
+        */
+       TEST_ASSERT_VAL("wrong period",     0 == evsel->attr.sample_period);
+       TEST_ASSERT_VAL("wrong callgraph",  !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type));
+       TEST_ASSERT_VAL("wrong time",  !(PERF_SAMPLE_TIME & evsel->attr.sample_type));
+
+       /* cpu/config=2,call-graph=no,time=0,period=2000/ */
+       evsel = perf_evsel__next(evsel);
+       TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
+       TEST_ASSERT_VAL("wrong config",  2 == evsel->attr.config);
+       /*
+        * The period, time and callgraph value gets configured
+        * within perf_evlist__config,
+        * while this test executes only parse events method.
+        */
+       TEST_ASSERT_VAL("wrong period",     0 == evsel->attr.sample_period);
+       TEST_ASSERT_VAL("wrong callgraph",  !(PERF_SAMPLE_CALLCHAIN & evsel->attr.sample_type));
+       TEST_ASSERT_VAL("wrong time",  !(PERF_SAMPLE_TIME & evsel->attr.sample_type));
+
+       return 0;
+}
+
 static int test__checkevent_pmu_events(struct perf_evlist *evlist)
 {
        struct perf_evsel *evsel = perf_evlist__first(evlist);
@@ -665,7 +706,7 @@ static int test__group3(struct perf_evlist *evlist __maybe_unused)
        TEST_ASSERT_VAL("wrong number of entries", 5 == evlist->nr_entries);
        TEST_ASSERT_VAL("wrong number of groups", 2 == evlist->nr_groups);
 
-       /* group1 syscalls:sys_enter_open:H */
+       /* group1 syscalls:sys_enter_openat:H */
        evsel = leader = perf_evlist__first(evlist);
        TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
        TEST_ASSERT_VAL("wrong sample_type",
@@ -1219,25 +1260,24 @@ test__checkevent_breakpoint_len_rw_modifier(struct perf_evlist *evlist)
        return test__checkevent_breakpoint_rw(evlist);
 }
 
+static int test__checkevent_precise_max_modifier(struct perf_evlist *evlist)
+{
+       struct perf_evsel *evsel = perf_evlist__first(evlist);
+
+       TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
+       TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
+       TEST_ASSERT_VAL("wrong config",
+                       PERF_COUNT_SW_TASK_CLOCK == evsel->attr.config);
+       return 0;
+}
+
 static int count_tracepoints(void)
 {
-       char events_path[PATH_MAX];
        struct dirent *events_ent;
-       const char *mountpoint;
        DIR *events_dir;
        int cnt = 0;
 
-       mountpoint = tracefs_find_mountpoint();
-       if (mountpoint) {
-               scnprintf(events_path, PATH_MAX, "%s/events",
-                         mountpoint);
-       } else {
-               mountpoint = debugfs_find_mountpoint();
-               scnprintf(events_path, PATH_MAX, "%s/tracing/events",
-                         mountpoint);
-       }
-
-       events_dir = opendir(events_path);
+       events_dir = opendir(tracing_events_path);
 
        TEST_ASSERT_VAL("Can't open events dir", events_dir);
 
@@ -1254,7 +1294,7 @@ static int count_tracepoints(void)
                        continue;
 
                scnprintf(sys_path, PATH_MAX, "%s/%s",
-                         events_path, events_ent->d_name);
+                         tracing_events_path, events_ent->d_name);
 
                sys_dir = opendir(sys_path);
                TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
@@ -1293,7 +1333,7 @@ struct evlist_test {
 
 static struct evlist_test test__events[] = {
        {
-               .name  = "syscalls:sys_enter_open",
+               .name  = "syscalls:sys_enter_openat",
                .check = test__checkevent_tracepoint,
                .id    = 0,
        },
@@ -1353,7 +1393,7 @@ static struct evlist_test test__events[] = {
                .id    = 11,
        },
        {
-               .name  = "syscalls:sys_enter_open:k",
+               .name  = "syscalls:sys_enter_openat:k",
                .check = test__checkevent_tracepoint_modifier,
                .id    = 12,
        },
@@ -1408,7 +1448,7 @@ static struct evlist_test test__events[] = {
                .id    = 22,
        },
        {
-               .name  = "r1,syscalls:sys_enter_open:k,1:1:hp",
+               .name  = "r1,syscalls:sys_enter_openat:k,1:1:hp",
                .check = test__checkevent_list,
                .id    = 23,
        },
@@ -1443,7 +1483,7 @@ static struct evlist_test test__events[] = {
                .id    = 29,
        },
        {
-               .name  = "group1{syscalls:sys_enter_open:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
+               .name  = "group1{syscalls:sys_enter_openat:H,cycles:kppp},group2{cycles,1:3}:G,instructions:u",
                .check = test__group3,
                .id    = 30,
        },
@@ -1534,6 +1574,11 @@ static struct evlist_test test__events[] = {
                .check = test__checkevent_exclude_idle_modifier_1,
                .id    = 46,
        },
+       {
+               .name  = "task-clock:P,cycles",
+               .check = test__checkevent_precise_max_modifier,
+               .id    = 47,
+       },
 };
 
 static struct evlist_test test__events_pmu[] = {
@@ -1547,6 +1592,11 @@ static struct evlist_test test__events_pmu[] = {
                .check = test__checkevent_pmu_name,
                .id    = 1,
        },
+       {
+               .name  = "cpu/config=1,call-graph=fp,time,period=100000/,cpu/config=2,call-graph=no,time=0,period=2000/",
+               .check = test__checkevent_pmu_partial_time_callgraph,
+               .id    = 2,
+       },
 };
 
 struct terms_test {
@@ -1571,7 +1621,7 @@ static int test_event(struct evlist_test *e)
        if (evlist == NULL)
                return -ENOMEM;
 
-       ret = parse_events(evlist, e->name);
+       ret = parse_events(evlist, e->name, NULL);
        if (ret) {
                pr_debug("failed to parse event '%s', err %d\n",
                         e->name, ret);
@@ -1704,6 +1754,17 @@ static int test_pmu_events(void)
        return ret;
 }
 
+static void debug_warn(const char *warn, va_list params)
+{
+       char msg[1024];
+
+       if (!verbose)
+               return;
+
+       vsnprintf(msg, sizeof(msg), warn, params);
+       fprintf(stderr, " Warning: %s\n", msg);
+}
+
 int test__parse_events(void)
 {
        int ret1, ret2 = 0;
@@ -1715,6 +1776,8 @@ do {                                                      \
                ret2 = ret1;                            \
 } while (0)
 
+       set_warning_routine(debug_warn);
+
        TEST_EVENTS(test__events);
 
        if (test_pmu())