ust-fd: Add close_range declaration
[lttng-ust.git] / tests / unit / pthread_name / pthread_name.c
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
5 */
6
7 #include <stdio.h>
8 #include <string.h>
9 #include "common/compat/pthread.h"
10 #include "common/procname.h"
11
12 #include "tap.h"
13
14 #define TEST_NAME_PROPER_LEN 16
15
16 int main(void)
17 {
18 int ret;
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";
26
27 plan_tests(12);
28
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);
32
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);
36
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);
41
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);
45
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);
50
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);
55
56
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);
60
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);
65
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);
70
71 return exit_status();
72 }
This page took 0.032001 seconds and 5 git commands to generate.