2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
9 #include "common/compat/pthread.h"
10 #include "common/procname.h"
14 #define TEST_NAME_PROPER_LEN 16
19 char name1
[TEST_NAME_PROPER_LEN
];
20 char name2
[TEST_NAME_PROPER_LEN
];
21 char too_long_name
[] = "thisnameistoolong";
22 char short_name
[] = "labatt50";
23 char short_name_ust
[] = "labatt50-ust";
24 char long_name
[] = "procrastinating";
25 char long_name_ust
[] = "procrastina-ust";
29 /* Get the initial thread name */
30 ret
= lttng_pthread_getname_np(name1
, TEST_NAME_PROPER_LEN
);
31 ok(ret
== 0, "Get the thread name: '%s'", name1
);
33 /* Set a thread name of more than 16 bytes, should fail */
34 ret
= lttng_pthread_setname_np(too_long_name
);
35 ok(ret
== ERANGE
, "Set a too long thread name: '%s'", too_long_name
);
37 /* Get the thread name again, shouldn't have changed */
38 ret
= lttng_pthread_getname_np(name2
, TEST_NAME_PROPER_LEN
);
39 ok(ret
== 0, "Get the thread name: '%s'", name2
);
40 ok(strcmp(name1
, name2
) == 0, "Compare the initial thread name: '%s' == '%s'", name1
, name2
);
42 /* Set a thread name of less than 16 bytes */
43 ret
= lttng_pthread_setname_np(short_name
);
44 ok(ret
== 0, "Set a short thread name: '%s'", short_name
);
46 /* Get the thread name again, should be the one we set */
47 ret
= lttng_pthread_getname_np(name1
, TEST_NAME_PROPER_LEN
);
48 ok(ret
== 0, "Get a short thread name: '%s'", name1
);
49 ok(strcmp(short_name
, name1
) == 0, "Compare the short thread name: '%s' == '%s'", short_name
, name1
);
51 /* Append "-ust" to the thread name */
52 lttng_ust_setustprocname();
53 ret
= lttng_pthread_getname_np(name1
, TEST_NAME_PROPER_LEN
);
54 ok(strcmp(short_name_ust
, name1
) == 0, "Compare the short UST thread name: '%s' == '%s'", short_name_ust
, name1
);
57 /* Set a thread name of 16 bytes */
58 ret
= lttng_pthread_setname_np(long_name
);
59 ok(ret
== 0, "Set a long thread name: '%s'", long_name
);
61 /* Get the thread name again, should be the one we set */
62 ret
= lttng_pthread_getname_np(name1
, TEST_NAME_PROPER_LEN
);
63 ok(ret
== 0, "Get a long thread name: '%s'", name1
);
64 ok(strncmp(long_name
, name1
, TEST_NAME_PROPER_LEN
- 1) == 0, "Compare the long thread name: '%s' == '%s'", long_name
, name1
);
66 /* Append "-ust" to the thread name which will truncate its end */
67 lttng_ust_setustprocname();
68 ret
= lttng_pthread_getname_np(name1
, TEST_NAME_PROPER_LEN
);
69 ok(strcmp(long_name_ust
, name1
) == 0, "Compare the long UST thread name: '%s' == '%s'", long_name_ust
, name1
);
This page took 0.032032 seconds and 4 git commands to generate.