docs: Add supported versions and fix-backport policy
[lttng-tools.git] / tests / unit / test_utils_compat_pthread.cpp
CommitLineData
014d7d3b
MJ
1/*
2 * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
c9e313bc 8#include "common/compat/pthread.hpp"
014d7d3b 9
28ab034a
JG
10#include <stdio.h>
11#include <string.h>
014d7d3b
MJ
12#include <tap/tap.h>
13
14#define TEST_NAME_PROPER_LEN 16
15
cd9adb8b 16int main()
014d7d3b
MJ
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 long_name[] = "procrastinating";
24
25 plan_tests(10);
26
27 /* Get the initial thread name */
28 ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN);
29 ok(ret == 0, "Get the thread name: '%s'", name1);
30
31 /* Set a thread name of more than 16 bytes, should fail */
32 ret = lttng_pthread_setname_np(too_long_name);
33 ok(ret == ERANGE, "Set a too long thread name: '%s'", too_long_name);
34
35 /* Get the thread name again, shouldn't have changed */
36 ret = lttng_pthread_getname_np(name2, TEST_NAME_PROPER_LEN);
37 ok(ret == 0, "Get the thread name: '%s'", name2);
38 ok(strcmp(name1, name2) == 0, "Compare the initial thread name: '%s' == '%s'", name1, name2);
39
40 /* Set a thread name of less than 16 bytes */
41 ret = lttng_pthread_setname_np(short_name);
42 ok(ret == 0, "Set a short thread name: '%s'", short_name);
43
44 /* Get the thread name again, should be the one we set */
45 ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN);
46 ok(ret == 0, "Get a short thread name: '%s'", name1);
28ab034a
JG
47 ok(strcmp(short_name, name1) == 0,
48 "Compare the short thread name: '%s' == '%s'",
49 short_name,
50 name1);
014d7d3b
MJ
51
52 /* Set a thread name of 16 bytes */
53 ret = lttng_pthread_setname_np(long_name);
54 ok(ret == 0, "Set a long thread name: '%s'", long_name);
55
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 long thread name: '%s'", name1);
28ab034a
JG
59 ok(strncmp(long_name, name1, TEST_NAME_PROPER_LEN - 1) == 0,
60 "Compare the long thread name: '%s' == '%s'",
61 long_name,
62 name1);
014d7d3b
MJ
63
64 return exit_status();
65}
This page took 0.043425 seconds and 4 git commands to generate.