ust-fd: Add close_range declaration
[lttng-ust.git] / tests / unit / pthread_name / pthread_name.c
CommitLineData
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>
27b98e6c
MJ
9#include "common/compat/pthread.h"
10#include "common/procname.h"
df8b7e52
MJ
11
12#include "tap.h"
13
14#define TEST_NAME_PROPER_LEN 16
15
4b4a1337 16int main(void)
df8b7e52
MJ
17{
18 int ret;
db833f80
MJ
19 char name1[TEST_NAME_PROPER_LEN];
20 char name2[TEST_NAME_PROPER_LEN];
21 char too_long_name[] = "thisnameistoolong";
df8b7e52
MJ
22 char short_name[] = "labatt50";
23 char short_name_ust[] = "labatt50-ust";
db833f80
MJ
24 char long_name[] = "procrastinating";
25 char long_name_ust[] = "procrastina-ust";
df8b7e52 26
db833f80 27 plan_tests(12);
df8b7e52 28
db833f80
MJ
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);
df8b7e52
MJ
41
42 /* Set a thread name of less than 16 bytes */
43 ret = lttng_pthread_setname_np(short_name);
db833f80 44 ok(ret == 0, "Set a short thread name: '%s'", short_name);
df8b7e52 45
db833f80
MJ
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);
df8b7e52
MJ
50
51 /* Append "-ust" to the thread name */
52 lttng_ust_setustprocname();
db833f80
MJ
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);
df8b7e52
MJ
55
56
db833f80 57 /* Set a thread name of 16 bytes */
df8b7e52 58 ret = lttng_pthread_setname_np(long_name);
db833f80 59 ok(ret == 0, "Set a long thread name: '%s'", long_name);
df8b7e52 60
db833f80
MJ
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);
df8b7e52
MJ
65
66 /* Append "-ust" to the thread name which will truncate its end */
67 lttng_ust_setustprocname();
db833f80
MJ
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);
df8b7e52
MJ
70
71 return exit_status();
72}
This page took 0.032631 seconds and 5 git commands to generate.