X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=tests%2Funit%2Ftest_utils_compat_pthread.c;fp=tests%2Funit%2Ftest_utils_compat_pthread.c;h=d9e59bccd7687ee86ae39b3e75c58dc6561ee1e5;hb=014d7d3b5e9d69989bf776cffb6c21ff7e1d36ff;hp=0000000000000000000000000000000000000000;hpb=5dee2ed25e797cc4a70a6180b7d5fc2bf0696c21;p=lttng-tools.git diff --git a/tests/unit/test_utils_compat_pthread.c b/tests/unit/test_utils_compat_pthread.c new file mode 100644 index 000000000..d9e59bccd --- /dev/null +++ b/tests/unit/test_utils_compat_pthread.c @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2020 Michael Jeanson + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#include +#include +#include "common/compat/pthread.h" + +#include + +#define TEST_NAME_PROPER_LEN 16 + +int main() +{ + int ret; + char name1[TEST_NAME_PROPER_LEN]; + char name2[TEST_NAME_PROPER_LEN]; + char too_long_name[] = "thisnameistoolong"; + char short_name[] = "labatt50"; + char long_name[] = "procrastinating"; + + plan_tests(10); + + /* Get the initial thread name */ + ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN); + ok(ret == 0, "Get the thread name: '%s'", name1); + + /* Set a thread name of more than 16 bytes, should fail */ + ret = lttng_pthread_setname_np(too_long_name); + ok(ret == ERANGE, "Set a too long thread name: '%s'", too_long_name); + + /* Get the thread name again, shouldn't have changed */ + ret = lttng_pthread_getname_np(name2, TEST_NAME_PROPER_LEN); + ok(ret == 0, "Get the thread name: '%s'", name2); + ok(strcmp(name1, name2) == 0, "Compare the initial thread name: '%s' == '%s'", name1, name2); + + /* Set a thread name of less than 16 bytes */ + ret = lttng_pthread_setname_np(short_name); + ok(ret == 0, "Set a short thread name: '%s'", short_name); + + /* Get the thread name again, should be the one we set */ + ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN); + ok(ret == 0, "Get a short thread name: '%s'", name1); + ok(strcmp(short_name, name1) == 0, "Compare the short thread name: '%s' == '%s'", short_name, name1); + + + /* Set a thread name of 16 bytes */ + ret = lttng_pthread_setname_np(long_name); + ok(ret == 0, "Set a long thread name: '%s'", long_name); + + /* Get the thread name again, should be the one we set */ + ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN); + ok(ret == 0, "Get a long thread name: '%s'", name1); + ok(strncmp(long_name, name1, TEST_NAME_PROPER_LEN - 1) == 0, "Compare the long thread name: '%s' == '%s'", long_name, name1); + + return exit_status(); +}