Clean-up: replace erroneous of empty parameter list by void
[lttng-tools.git] / tests / unit / test_utils_compat_pthread.c
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
8#include <stdio.h>
9#include <string.h>
10#include "common/compat/pthread.h"
11
12#include <tap/tap.h>
13
14#define TEST_NAME_PROPER_LEN 16
15
a3ecaea8 16int main(int argc, char **argv)
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);
47 ok(strcmp(short_name, name1) == 0, "Compare the short thread name: '%s' == '%s'", short_name, name1);
48
49
50 /* Set a thread name of 16 bytes */
51 ret = lttng_pthread_setname_np(long_name);
52 ok(ret == 0, "Set a long thread name: '%s'", long_name);
53
54 /* Get the thread name again, should be the one we set */
55 ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN);
56 ok(ret == 0, "Get a long thread name: '%s'", name1);
57 ok(strncmp(long_name, name1, TEST_NAME_PROPER_LEN - 1) == 0, "Compare the long thread name: '%s' == '%s'", long_name, name1);
58
59 return exit_status();
60}
This page took 0.024894 seconds and 4 git commands to generate.