diff options
Diffstat (limited to 'tools/perf/tests/thread-map.c')
-rw-r--r-- | tools/perf/tests/thread-map.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c index cee2a2cdc933..a4a4b4625ac3 100644 --- a/tools/perf/tests/thread-map.c +++ b/tools/perf/tests/thread-map.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #include <stdlib.h> | ||
1 | #include <sys/types.h> | 2 | #include <sys/types.h> |
2 | #include <unistd.h> | 3 | #include <unistd.h> |
3 | #include <sys/prctl.h> | 4 | #include <sys/prctl.h> |
@@ -93,3 +94,46 @@ int test__thread_map_synthesize(int subtest __maybe_unused) | |||
93 | 94 | ||
94 | return 0; | 95 | return 0; |
95 | } | 96 | } |
97 | |||
98 | int test__thread_map_remove(int subtest __maybe_unused) | ||
99 | { | ||
100 | struct thread_map *threads; | ||
101 | char *str; | ||
102 | int i; | ||
103 | |||
104 | TEST_ASSERT_VAL("failed to allocate map string", | ||
105 | asprintf(&str, "%d,%d", getpid(), getppid()) >= 0); | ||
106 | |||
107 | threads = thread_map__new_str(str, NULL, 0); | ||
108 | |||
109 | TEST_ASSERT_VAL("failed to allocate thread_map", | ||
110 | threads); | ||
111 | |||
112 | if (verbose) | ||
113 | thread_map__fprintf(threads, stderr); | ||
114 | |||
115 | TEST_ASSERT_VAL("failed to remove thread", | ||
116 | !thread_map__remove(threads, 0)); | ||
117 | |||
118 | TEST_ASSERT_VAL("thread_map count != 1", threads->nr == 1); | ||
119 | |||
120 | if (verbose) | ||
121 | thread_map__fprintf(threads, stderr); | ||
122 | |||
123 | TEST_ASSERT_VAL("failed to remove thread", | ||
124 | !thread_map__remove(threads, 0)); | ||
125 | |||
126 | TEST_ASSERT_VAL("thread_map count != 0", threads->nr == 0); | ||
127 | |||
128 | if (verbose) | ||
129 | thread_map__fprintf(threads, stderr); | ||
130 | |||
131 | TEST_ASSERT_VAL("failed to not remove thread", | ||
132 | thread_map__remove(threads, 0)); | ||
133 | |||
134 | for (i = 0; i < threads->nr; i++) | ||
135 | free(threads->map[i].comm); | ||
136 | |||
137 | free(threads); | ||
138 | return 0; | ||
139 | } | ||