]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - tools/perf/tests/thread-map.c
6 #include "thread_map.h"
9 #define NAME (const char *) "perf"
10 #define NAMEUL (unsigned long) NAME
12 int test__thread_map(int subtest __maybe_unused
)
14 struct thread_map
*map
;
16 TEST_ASSERT_VAL("failed to set process name",
17 !prctl(PR_SET_NAME
, NAMEUL
, 0, 0, 0));
19 /* test map on current pid */
20 map
= thread_map__new_by_pid(getpid());
21 TEST_ASSERT_VAL("failed to alloc map", map
);
23 thread_map__read_comms(map
);
25 TEST_ASSERT_VAL("wrong nr", map
->nr
== 1);
26 TEST_ASSERT_VAL("wrong pid",
27 thread_map__pid(map
, 0) == getpid());
28 TEST_ASSERT_VAL("wrong comm",
29 thread_map__comm(map
, 0) &&
30 !strcmp(thread_map__comm(map
, 0), NAME
));
31 TEST_ASSERT_VAL("wrong refcnt",
32 refcount_read(&map
->refcnt
) == 1);
36 map
= thread_map__new_dummy();
37 TEST_ASSERT_VAL("failed to alloc map", map
);
39 thread_map__read_comms(map
);
41 TEST_ASSERT_VAL("wrong nr", map
->nr
== 1);
42 TEST_ASSERT_VAL("wrong pid", thread_map__pid(map
, 0) == -1);
43 TEST_ASSERT_VAL("wrong comm",
44 thread_map__comm(map
, 0) &&
45 !strcmp(thread_map__comm(map
, 0), "dummy"));
46 TEST_ASSERT_VAL("wrong refcnt",
47 refcount_read(&map
->refcnt
) == 1);
52 static int process_event(struct perf_tool
*tool __maybe_unused
,
53 union perf_event
*event
,
54 struct perf_sample
*sample __maybe_unused
,
55 struct machine
*machine __maybe_unused
)
57 struct thread_map_event
*map
= &event
->thread_map
;
58 struct thread_map
*threads
;
60 TEST_ASSERT_VAL("wrong nr", map
->nr
== 1);
61 TEST_ASSERT_VAL("wrong pid", map
->entries
[0].pid
== (u64
) getpid());
62 TEST_ASSERT_VAL("wrong comm", !strcmp(map
->entries
[0].comm
, NAME
));
64 threads
= thread_map__new_event(&event
->thread_map
);
65 TEST_ASSERT_VAL("failed to alloc map", threads
);
67 TEST_ASSERT_VAL("wrong nr", threads
->nr
== 1);
68 TEST_ASSERT_VAL("wrong pid",
69 thread_map__pid(threads
, 0) == getpid());
70 TEST_ASSERT_VAL("wrong comm",
71 thread_map__comm(threads
, 0) &&
72 !strcmp(thread_map__comm(threads
, 0), NAME
));
73 TEST_ASSERT_VAL("wrong refcnt",
74 refcount_read(&threads
->refcnt
) == 1);
75 thread_map__put(threads
);
79 int test__thread_map_synthesize(int subtest __maybe_unused
)
81 struct thread_map
*threads
;
83 TEST_ASSERT_VAL("failed to set process name",
84 !prctl(PR_SET_NAME
, NAMEUL
, 0, 0, 0));
86 /* test map on current pid */
87 threads
= thread_map__new_by_pid(getpid());
88 TEST_ASSERT_VAL("failed to alloc map", threads
);
90 thread_map__read_comms(threads
);
92 TEST_ASSERT_VAL("failed to synthesize map",
93 !perf_event__synthesize_thread_map2(NULL
, threads
, process_event
, NULL
));
98 int test__thread_map_remove(int subtest __maybe_unused
)
100 struct thread_map
*threads
;
104 TEST_ASSERT_VAL("failed to allocate map string",
105 asprintf(&str
, "%d,%d", getpid(), getppid()) >= 0);
107 threads
= thread_map__new_str(str
, NULL
, 0);
109 TEST_ASSERT_VAL("failed to allocate thread_map",
113 thread_map__fprintf(threads
, stderr
);
115 TEST_ASSERT_VAL("failed to remove thread",
116 !thread_map__remove(threads
, 0));
118 TEST_ASSERT_VAL("thread_map count != 1", threads
->nr
== 1);
121 thread_map__fprintf(threads
, stderr
);
123 TEST_ASSERT_VAL("failed to remove thread",
124 !thread_map__remove(threads
, 0));
126 TEST_ASSERT_VAL("thread_map count != 0", threads
->nr
== 0);
129 thread_map__fprintf(threads
, stderr
);
131 TEST_ASSERT_VAL("failed to not remove thread",
132 thread_map__remove(threads
, 0));
134 for (i
= 0; i
< threads
->nr
; i
++)
135 free(threads
->map
[i
].comm
);