1 /* Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
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.
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.
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
24 #define TEST_NAME_PROPER_LEN 16
29 char name1
[TEST_NAME_PROPER_LEN
];
30 char name2
[TEST_NAME_PROPER_LEN
];
31 char too_long_name
[] = "thisnameistoolong";
32 char short_name
[] = "labatt50";
33 char short_name_ust
[] = "labatt50-ust";
34 char long_name
[] = "procrastinating";
35 char long_name_ust
[] = "procrastina-ust";
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
);
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
);
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
);
52 /* Set a thread name of less than 16 bytes */
53 ret
= lttng_pthread_setname_np(short_name
);
54 ok(ret
== 0, "Set a short thread name: '%s'", short_name
);
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
);
61 /* Append "-ust" to the thread name */
62 lttng_ust_setustprocname();
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
);
67 /* Set a thread name of 16 bytes */
68 ret
= lttng_pthread_setname_np(long_name
);
69 ok(ret
== 0, "Set a long thread name: '%s'", long_name
);
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
);
76 /* Append "-ust" to the thread name which will truncate its end */
77 lttng_ust_setustprocname();
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
);
This page took 0.032133 seconds and 5 git commands to generate.