4 #include "thread_map.h"
7 int test__thread_map(int subtest __maybe_unused
)
9 struct thread_map
*map
;
11 /* test map on current pid */
12 map
= thread_map__new_by_pid(getpid());
13 TEST_ASSERT_VAL("failed to alloc map", map
);
15 thread_map__read_comms(map
);
17 TEST_ASSERT_VAL("wrong nr", map
->nr
== 1);
18 TEST_ASSERT_VAL("wrong pid",
19 thread_map__pid(map
, 0) == getpid());
20 TEST_ASSERT_VAL("wrong comm",
21 thread_map__comm(map
, 0) &&
22 !strcmp(thread_map__comm(map
, 0), "perf"));
23 TEST_ASSERT_VAL("wrong refcnt",
24 atomic_read(&map
->refcnt
) == 1);
28 map
= thread_map__new_dummy();
29 TEST_ASSERT_VAL("failed to alloc map", map
);
31 thread_map__read_comms(map
);
33 TEST_ASSERT_VAL("wrong nr", map
->nr
== 1);
34 TEST_ASSERT_VAL("wrong pid", thread_map__pid(map
, 0) == -1);
35 TEST_ASSERT_VAL("wrong comm",
36 thread_map__comm(map
, 0) &&
37 !strcmp(thread_map__comm(map
, 0), "dummy"));
38 TEST_ASSERT_VAL("wrong refcnt",
39 atomic_read(&map
->refcnt
) == 1);
44 static int process_event(struct perf_tool
*tool __maybe_unused
,
45 union perf_event
*event
,
46 struct perf_sample
*sample __maybe_unused
,
47 struct machine
*machine __maybe_unused
)
49 struct thread_map_event
*map
= &event
->thread_map
;
50 struct thread_map
*threads
;
52 TEST_ASSERT_VAL("wrong nr", map
->nr
== 1);
53 TEST_ASSERT_VAL("wrong pid", map
->entries
[0].pid
== (u64
) getpid());
54 TEST_ASSERT_VAL("wrong comm", !strcmp(map
->entries
[0].comm
, "perf"));
56 threads
= thread_map__new_event(&event
->thread_map
);
57 TEST_ASSERT_VAL("failed to alloc map", threads
);
59 TEST_ASSERT_VAL("wrong nr", threads
->nr
== 1);
60 TEST_ASSERT_VAL("wrong pid",
61 thread_map__pid(threads
, 0) == getpid());
62 TEST_ASSERT_VAL("wrong comm",
63 thread_map__comm(threads
, 0) &&
64 !strcmp(thread_map__comm(threads
, 0), "perf"));
65 TEST_ASSERT_VAL("wrong refcnt",
66 atomic_read(&threads
->refcnt
) == 1);
67 thread_map__put(threads
);
71 int test__thread_map_synthesize(int subtest __maybe_unused
)
73 struct thread_map
*threads
;
75 /* test map on current pid */
76 threads
= thread_map__new_by_pid(getpid());
77 TEST_ASSERT_VAL("failed to alloc map", threads
);
79 thread_map__read_comms(threads
);
81 TEST_ASSERT_VAL("failed to synthesize map",
82 !perf_event__synthesize_thread_map2(NULL
, threads
, process_event
, NULL
));