From db833f805ed00e722fe27767353f25bca5ad0962 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Fri, 16 Oct 2020 15:45:43 -0400 Subject: [PATCH] fix: pthread_setname_np tests to match compat behavior Adjust the test to expect an error when setting a thread name of more than 16 bytes. Also don't override global AM_CPPFLAGS in pthread_name/Makefile.am so that we get the proper include configuration. Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers Change-Id: Iee41d8ea845836d273f01e890ea4196ae2ed43ef --- tests/pthread_name/Makefile.am | 2 +- tests/pthread_name/pthread_name.c | 52 ++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/tests/pthread_name/Makefile.am b/tests/pthread_name/Makefile.am index 66fa7181..173191d7 100644 --- a/tests/pthread_name/Makefile.am +++ b/tests/pthread_name/Makefile.am @@ -1,4 +1,4 @@ -AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/liblttng-ust -I$(top_srcdir)/tests/utils +AM_CPPFLAGS += -I$(top_srcdir)/include -I$(top_srcdir)/liblttng-ust -I$(top_srcdir)/tests/utils noinst_PROGRAMS = test_pthread_name test_pthread_name_SOURCES = pthread_name.c diff --git a/tests/pthread_name/pthread_name.c b/tests/pthread_name/pthread_name.c index 05298f5b..b6c7831b 100644 --- a/tests/pthread_name/pthread_name.c +++ b/tests/pthread_name/pthread_name.c @@ -26,43 +26,57 @@ int main() { int ret; - char name[TEST_NAME_PROPER_LEN]; + char name1[TEST_NAME_PROPER_LEN]; + char name2[TEST_NAME_PROPER_LEN]; + char too_long_name[] = "thisnameistoolong"; char short_name[] = "labatt50"; char short_name_ust[] = "labatt50-ust"; - char long_name[] = "thisnameistoolong"; - char long_name_ust[] = "thisnameist-ust"; + char long_name[] = "procrastinating"; + char long_name_ust[] = "procrastina-ust"; - plan_tests(9); + plan_tests(12); - ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN); - ok(ret == 0, "Get the thread name: %s", name); + /* 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); + ok(ret == 0, "Set a short thread name: '%s'", short_name); - ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN); - ok(ret == 0, "Get a short thread name: %s", name); - ok(strcmp(short_name, name) == 0, "Compare the short thread name: %s == %s", short_name, 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); /* Append "-ust" to the thread name */ lttng_ust_setustprocname(); - ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN); - ok(strcmp(short_name_ust, name) == 0, "Compare the short UST thread name: %s == %s", short_name_ust, name); + ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN); + ok(strcmp(short_name_ust, name1) == 0, "Compare the short UST thread name: '%s' == '%s'", short_name_ust, name1); - /* Set a thread name of more than 16 bytes */ + /* 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); + ok(ret == 0, "Set a long thread name: '%s'", long_name); - ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN); - ok(ret == 0, "Get a truncated long thread name: %s", name); - ok(strncmp(long_name, name, TEST_NAME_PROPER_LEN - 1) == 0, "Compare the truncated long thread name: %s == %s", long_name, 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); /* Append "-ust" to the thread name which will truncate its end */ lttng_ust_setustprocname(); - ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN); - ok(strcmp(long_name_ust, name) == 0, "Compare the long UST thread name: %s == %s", long_name_ust, name); + ret = lttng_pthread_getname_np(name1, TEST_NAME_PROPER_LEN); + ok(strcmp(long_name_ust, name1) == 0, "Compare the long UST thread name: '%s' == '%s'", long_name_ust, name1); return exit_status(); } -- 2.34.1