hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/tools/perf/tests/thread-map.c
....@@ -1,18 +1,27 @@
11 // SPDX-License-Identifier: GPL-2.0
22 #include <stdlib.h>
3
+#include <string.h>
34 #include <sys/types.h>
45 #include <unistd.h>
56 #include <sys/prctl.h>
67 #include "tests.h"
78 #include "thread_map.h"
89 #include "debug.h"
10
+#include "event.h"
11
+#include "util/synthetic-events.h"
12
+#include <linux/zalloc.h>
13
+#include <perf/event.h>
14
+
15
+struct perf_sample;
16
+struct perf_tool;
17
+struct machine;
918
1019 #define NAME (const char *) "perf"
1120 #define NAMEUL (unsigned long) NAME
1221
1322 int test__thread_map(struct test *test __maybe_unused, int subtest __maybe_unused)
1423 {
15
- struct thread_map *map;
24
+ struct perf_thread_map *map;
1625
1726 TEST_ASSERT_VAL("failed to set process name",
1827 !prctl(PR_SET_NAME, NAMEUL, 0, 0, 0));
....@@ -25,28 +34,28 @@
2534
2635 TEST_ASSERT_VAL("wrong nr", map->nr == 1);
2736 TEST_ASSERT_VAL("wrong pid",
28
- thread_map__pid(map, 0) == getpid());
37
+ perf_thread_map__pid(map, 0) == getpid());
2938 TEST_ASSERT_VAL("wrong comm",
30
- thread_map__comm(map, 0) &&
31
- !strcmp(thread_map__comm(map, 0), NAME));
39
+ perf_thread_map__comm(map, 0) &&
40
+ !strcmp(perf_thread_map__comm(map, 0), NAME));
3241 TEST_ASSERT_VAL("wrong refcnt",
3342 refcount_read(&map->refcnt) == 1);
34
- thread_map__put(map);
43
+ perf_thread_map__put(map);
3544
3645 /* test dummy pid */
37
- map = thread_map__new_dummy();
46
+ map = perf_thread_map__new_dummy();
3847 TEST_ASSERT_VAL("failed to alloc map", map);
3948
4049 thread_map__read_comms(map);
4150
4251 TEST_ASSERT_VAL("wrong nr", map->nr == 1);
43
- TEST_ASSERT_VAL("wrong pid", thread_map__pid(map, 0) == -1);
52
+ TEST_ASSERT_VAL("wrong pid", perf_thread_map__pid(map, 0) == -1);
4453 TEST_ASSERT_VAL("wrong comm",
45
- thread_map__comm(map, 0) &&
46
- !strcmp(thread_map__comm(map, 0), "dummy"));
54
+ perf_thread_map__comm(map, 0) &&
55
+ !strcmp(perf_thread_map__comm(map, 0), "dummy"));
4756 TEST_ASSERT_VAL("wrong refcnt",
4857 refcount_read(&map->refcnt) == 1);
49
- thread_map__put(map);
58
+ perf_thread_map__put(map);
5059 return 0;
5160 }
5261
....@@ -55,8 +64,8 @@
5564 struct perf_sample *sample __maybe_unused,
5665 struct machine *machine __maybe_unused)
5766 {
58
- struct thread_map_event *map = &event->thread_map;
59
- struct thread_map *threads;
67
+ struct perf_record_thread_map *map = &event->thread_map;
68
+ struct perf_thread_map *threads;
6069
6170 TEST_ASSERT_VAL("wrong nr", map->nr == 1);
6271 TEST_ASSERT_VAL("wrong pid", map->entries[0].pid == (u64) getpid());
....@@ -67,19 +76,19 @@
6776
6877 TEST_ASSERT_VAL("wrong nr", threads->nr == 1);
6978 TEST_ASSERT_VAL("wrong pid",
70
- thread_map__pid(threads, 0) == getpid());
79
+ perf_thread_map__pid(threads, 0) == getpid());
7180 TEST_ASSERT_VAL("wrong comm",
72
- thread_map__comm(threads, 0) &&
73
- !strcmp(thread_map__comm(threads, 0), NAME));
81
+ perf_thread_map__comm(threads, 0) &&
82
+ !strcmp(perf_thread_map__comm(threads, 0), NAME));
7483 TEST_ASSERT_VAL("wrong refcnt",
7584 refcount_read(&threads->refcnt) == 1);
76
- thread_map__put(threads);
85
+ perf_thread_map__put(threads);
7786 return 0;
7887 }
7988
8089 int test__thread_map_synthesize(struct test *test __maybe_unused, int subtest __maybe_unused)
8190 {
82
- struct thread_map *threads;
91
+ struct perf_thread_map *threads;
8392
8493 TEST_ASSERT_VAL("failed to set process name",
8594 !prctl(PR_SET_NAME, NAMEUL, 0, 0, 0));
....@@ -98,7 +107,7 @@
98107
99108 int test__thread_map_remove(struct test *test __maybe_unused, int subtest __maybe_unused)
100109 {
101
- struct thread_map *threads;
110
+ struct perf_thread_map *threads;
102111 char *str;
103112 int i;
104113
....@@ -133,7 +142,7 @@
133142 thread_map__remove(threads, 0));
134143
135144 for (i = 0; i < threads->nr; i++)
136
- free(threads->map[i].comm);
145
+ zfree(&threads->map[i].comm);
137146
138147 free(threads);
139148 return 0;