5 #include "thread_map.h"
8 #define NAME (const char *) "perf"
9 #define NAMEUL (unsigned long) NAME
11 int test__thread_map(int subtest __maybe_unused
)
13 struct thread_map
*map
;
15 TEST_ASSERT_VAL("failed to set process name",
16 !prctl(PR_SET_NAME
, NAMEUL
, 0, 0, 0));
18 /* test map on current pid */
19 map
= thread_map__new_by_pid(getpid());
20 TEST_ASSERT_VAL("failed to alloc map", map
);
22 thread_map__read_comms(map
);
24 TEST_ASSERT_VAL("wrong nr", map
->nr
== 1);
25 TEST_ASSERT_VAL("wrong pid",
26 thread_map__pid(map
, 0) == getpid());
27 TEST_ASSERT_VAL("wrong comm",
28 thread_map__comm(map
, 0) &&
29 !strcmp(thread_map__comm(map
, 0), NAME
));
30 TEST_ASSERT_VAL("wrong refcnt",
31 atomic_read(&map
->refcnt
) == 1);
35 map
= thread_map__new_dummy();
36 TEST_ASSERT_VAL("failed to alloc map", map
);
38 thread_map__read_comms(map
);
40 TEST_ASSERT_VAL("wrong nr", map
->nr
== 1);
41 TEST_ASSERT_VAL("wrong pid", thread_map__pid(map
, 0) == -1);
42 TEST_ASSERT_VAL("wrong comm",
43 thread_map__comm(map
, 0) &&
44 !strcmp(thread_map__comm(map
, 0), "dummy"));
45 TEST_ASSERT_VAL("wrong refcnt",
46 atomic_read(&map
->refcnt
) == 1);
51 static int process_event(struct perf_tool
*tool __maybe_unused
,
52 union perf_event
*event
,
53 struct perf_sample
*sample __maybe_unused
,
54 struct machine
*machine __maybe_unused
)
56 struct thread_map_event
*map
= &event
->thread_map
;
57 struct thread_map
*threads
;
59 TEST_ASSERT_VAL("wrong nr", map
->nr
== 1);
60 TEST_ASSERT_VAL("wrong pid", map
->entries
[0].pid
== (u64
) getpid());
61 TEST_ASSERT_VAL("wrong comm", !strcmp(map
->entries
[0].comm
, NAME
));
63 threads
= thread_map__new_event(&event
->thread_map
);
64 TEST_ASSERT_VAL("failed to alloc map", threads
);
66 TEST_ASSERT_VAL("wrong nr", threads
->nr
== 1);
67 TEST_ASSERT_VAL("wrong pid",
68 thread_map__pid(threads
, 0) == getpid());
69 TEST_ASSERT_VAL("wrong comm",
70 thread_map__comm(threads
, 0) &&
71 !strcmp(thread_map__comm(threads
, 0), NAME
));
72 TEST_ASSERT_VAL("wrong refcnt",
73 atomic_read(&threads
->refcnt
) == 1);
74 thread_map__put(threads
);
78 int test__thread_map_synthesize(int subtest __maybe_unused
)
80 struct thread_map
*threads
;
82 TEST_ASSERT_VAL("failed to set process name",
83 !prctl(PR_SET_NAME
, NAMEUL
, 0, 0, 0));
85 /* test map on current pid */
86 threads
= thread_map__new_by_pid(getpid());
87 TEST_ASSERT_VAL("failed to alloc map", threads
);
89 thread_map__read_comms(threads
);
91 TEST_ASSERT_VAL("failed to synthesize map",
92 !perf_event__synthesize_thread_map2(NULL
, threads
, process_event
, NULL
));
This page took 0.034026 seconds and 5 git commands to generate.