Commit | Line | Data |
---|---|---|
df8b7e52 MJ |
1 | /* Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com> |
2 | * | |
3 | * This library is free software; you can redistribute it and/or | |
4 | * modify it under the terms of the GNU Lesser General Public | |
5 | * License as published by the Free Software Foundation; only | |
6 | * version 2.1 of the License. | |
7 | * | |
8 | * This library is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
11 | * Lesser General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU Lesser General Public | |
14 | * License along with this library; if not, write to the Free Software | |
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
16 | */ | |
17 | ||
18 | #include <stdio.h> | |
19 | #include <string.h> | |
20 | #include "compat.h" | |
21 | ||
22 | #include "tap.h" | |
23 | ||
24 | #define TEST_NAME_PROPER_LEN 16 | |
25 | ||
26 | int main() | |
27 | { | |
28 | int ret; | |
29 | char name[TEST_NAME_PROPER_LEN]; | |
30 | char short_name[] = "labatt50"; | |
31 | char short_name_ust[] = "labatt50-ust"; | |
32 | char long_name[] = "thisnameistoolong"; | |
33 | char long_name_ust[] = "thisnameist-ust"; | |
34 | ||
35 | plan_tests(9); | |
36 | ||
37 | ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN); | |
38 | ok(ret == 0, "Get the thread name: %s", name); | |
39 | ||
40 | /* Set a thread name of less than 16 bytes */ | |
41 | ret = lttng_pthread_setname_np(short_name); | |
42 | ok(ret == 0, "Set a short thread name: %s", short_name); | |
43 | ||
44 | ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN); | |
45 | ok(ret == 0, "Get a short thread name: %s", name); | |
46 | ok(strcmp(short_name, name) == 0, "Compare the short thread name: %s == %s", short_name, name); | |
47 | ||
48 | /* Append "-ust" to the thread name */ | |
49 | lttng_ust_setustprocname(); | |
50 | ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN); | |
51 | ok(strcmp(short_name_ust, name) == 0, "Compare the short UST thread name: %s == %s", short_name_ust, name); | |
52 | ||
53 | ||
54 | /* Set a thread name of more than 16 bytes */ | |
55 | ret = lttng_pthread_setname_np(long_name); | |
56 | ok(ret == 0, "Set a long thread name: %s", long_name); | |
57 | ||
58 | ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN); | |
59 | ok(ret == 0, "Get a truncated long thread name: %s", name); | |
60 | ok(strncmp(long_name, name, TEST_NAME_PROPER_LEN - 1) == 0, "Compare the truncated long thread name: %s == %s", long_name, name); | |
61 | ||
62 | /* Append "-ust" to the thread name which will truncate its end */ | |
63 | lttng_ust_setustprocname(); | |
64 | ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN); | |
65 | ok(strcmp(long_name_ust, name) == 0, "Compare the long UST thread name: %s == %s", long_name_ust, name); | |
66 | ||
67 | return exit_status(); | |
68 | } |