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; | |
db833f80 MJ |
29 | char name1[TEST_NAME_PROPER_LEN]; |
30 | char name2[TEST_NAME_PROPER_LEN]; | |
31 | char too_long_name[] = "thisnameistoolong"; | |
df8b7e52 MJ |
32 | char short_name[] = "labatt50"; |
33 | char short_name_ust[] = "labatt50-ust"; | |
db833f80 MJ |
34 | char long_name[] = "procrastinating"; |
35 | char long_name_ust[] = "procrastina-ust"; | |
df8b7e52 | 36 | |
db833f80 | 37 | plan_tests(12); |
df8b7e52 | 38 | |
db833f80 MJ |
39 | /* Get the initial thread name */ |
40 | ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN); | |
41 | ok(ret == 0, "Get the thread name: '%s'", name1); | |
42 | ||
43 | /* Set a thread name of more than 16 bytes, should fail */ | |
44 | ret = lttng_pthread_setname_np(too_long_name); | |
45 | ok(ret == ERANGE, "Set a too long thread name: '%s'", too_long_name); | |
46 | ||
47 | /* Get the thread name again, shouldn't have changed */ | |
48 | ret = lttng_pthread_getname_np(name2, TEST_NAME_PROPER_LEN); | |
49 | ok(ret == 0, "Get the thread name: '%s'", name2); | |
50 | ok(strcmp(name1, name2) == 0, "Compare the initial thread name: '%s' == '%s'", name1, name2); | |
df8b7e52 MJ |
51 | |
52 | /* Set a thread name of less than 16 bytes */ | |
53 | ret = lttng_pthread_setname_np(short_name); | |
db833f80 | 54 | ok(ret == 0, "Set a short thread name: '%s'", short_name); |
df8b7e52 | 55 | |
db833f80 MJ |
56 | /* Get the thread name again, should be the one we set */ |
57 | ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN); | |
58 | ok(ret == 0, "Get a short thread name: '%s'", name1); | |
59 | ok(strcmp(short_name, name1) == 0, "Compare the short thread name: '%s' == '%s'", short_name, name1); | |
df8b7e52 MJ |
60 | |
61 | /* Append "-ust" to the thread name */ | |
62 | lttng_ust_setustprocname(); | |
db833f80 MJ |
63 | ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN); |
64 | ok(strcmp(short_name_ust, name1) == 0, "Compare the short UST thread name: '%s' == '%s'", short_name_ust, name1); | |
df8b7e52 MJ |
65 | |
66 | ||
db833f80 | 67 | /* Set a thread name of 16 bytes */ |
df8b7e52 | 68 | ret = lttng_pthread_setname_np(long_name); |
db833f80 | 69 | ok(ret == 0, "Set a long thread name: '%s'", long_name); |
df8b7e52 | 70 | |
db833f80 MJ |
71 | /* Get the thread name again, should be the one we set */ |
72 | ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN); | |
73 | ok(ret == 0, "Get a long thread name: '%s'", name1); | |
74 | ok(strncmp(long_name, name1, TEST_NAME_PROPER_LEN - 1) == 0, "Compare the long thread name: '%s' == '%s'", long_name, name1); | |
df8b7e52 MJ |
75 | |
76 | /* Append "-ust" to the thread name which will truncate its end */ | |
77 | lttng_ust_setustprocname(); | |
db833f80 MJ |
78 | ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN); |
79 | ok(strcmp(long_name_ust, name1) == 0, "Compare the long UST thread name: '%s' == '%s'", long_name_ust, name1); | |
df8b7e52 MJ |
80 | |
81 | return exit_status(); | |
82 | } |