Commit | Line | Data |
---|---|---|
c0c0989a MJ |
1 | /* |
2 | * SPDX-License-Identifier: LGPL-2.1-only | |
df8b7e52 | 3 | * |
c0c0989a | 4 | * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com> |
df8b7e52 MJ |
5 | */ |
6 | ||
7 | #include <stdio.h> | |
8 | #include <string.h> | |
9d4c8b2d | 9 | #include "../../../src/liblttng-ust/compat.h" |
df8b7e52 MJ |
10 | |
11 | #include "tap.h" | |
12 | ||
13 | #define TEST_NAME_PROPER_LEN 16 | |
14 | ||
4b4a1337 | 15 | int main(void) |
df8b7e52 MJ |
16 | { |
17 | int ret; | |
db833f80 MJ |
18 | char name1[TEST_NAME_PROPER_LEN]; |
19 | char name2[TEST_NAME_PROPER_LEN]; | |
20 | char too_long_name[] = "thisnameistoolong"; | |
df8b7e52 MJ |
21 | char short_name[] = "labatt50"; |
22 | char short_name_ust[] = "labatt50-ust"; | |
db833f80 MJ |
23 | char long_name[] = "procrastinating"; |
24 | char long_name_ust[] = "procrastina-ust"; | |
df8b7e52 | 25 | |
db833f80 | 26 | plan_tests(12); |
df8b7e52 | 27 | |
db833f80 MJ |
28 | /* Get the initial thread name */ |
29 | ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN); | |
30 | ok(ret == 0, "Get the thread name: '%s'", name1); | |
31 | ||
32 | /* Set a thread name of more than 16 bytes, should fail */ | |
33 | ret = lttng_pthread_setname_np(too_long_name); | |
34 | ok(ret == ERANGE, "Set a too long thread name: '%s'", too_long_name); | |
35 | ||
36 | /* Get the thread name again, shouldn't have changed */ | |
37 | ret = lttng_pthread_getname_np(name2, TEST_NAME_PROPER_LEN); | |
38 | ok(ret == 0, "Get the thread name: '%s'", name2); | |
39 | ok(strcmp(name1, name2) == 0, "Compare the initial thread name: '%s' == '%s'", name1, name2); | |
df8b7e52 MJ |
40 | |
41 | /* Set a thread name of less than 16 bytes */ | |
42 | ret = lttng_pthread_setname_np(short_name); | |
db833f80 | 43 | ok(ret == 0, "Set a short thread name: '%s'", short_name); |
df8b7e52 | 44 | |
db833f80 MJ |
45 | /* Get the thread name again, should be the one we set */ |
46 | ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN); | |
47 | ok(ret == 0, "Get a short thread name: '%s'", name1); | |
48 | ok(strcmp(short_name, name1) == 0, "Compare the short thread name: '%s' == '%s'", short_name, name1); | |
df8b7e52 MJ |
49 | |
50 | /* Append "-ust" to the thread name */ | |
51 | lttng_ust_setustprocname(); | |
db833f80 MJ |
52 | ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN); |
53 | ok(strcmp(short_name_ust, name1) == 0, "Compare the short UST thread name: '%s' == '%s'", short_name_ust, name1); | |
df8b7e52 MJ |
54 | |
55 | ||
db833f80 | 56 | /* Set a thread name of 16 bytes */ |
df8b7e52 | 57 | ret = lttng_pthread_setname_np(long_name); |
db833f80 | 58 | ok(ret == 0, "Set a long thread name: '%s'", long_name); |
df8b7e52 | 59 | |
db833f80 MJ |
60 | /* Get the thread name again, should be the one we set */ |
61 | ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN); | |
62 | ok(ret == 0, "Get a long thread name: '%s'", name1); | |
63 | ok(strncmp(long_name, name1, TEST_NAME_PROPER_LEN - 1) == 0, "Compare the long thread name: '%s' == '%s'", long_name, name1); | |
df8b7e52 MJ |
64 | |
65 | /* Append "-ust" to the thread name which will truncate its end */ | |
66 | lttng_ust_setustprocname(); | |
db833f80 MJ |
67 | ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN); |
68 | ok(strcmp(long_name_ust, name1) == 0, "Compare the long UST thread name: '%s' == '%s'", long_name_ust, name1); | |
df8b7e52 MJ |
69 | |
70 | return exit_status(); | |
71 | } |