fix: pthread_setname_np tests to match compat behavior
authorMichael Jeanson <mjeanson@efficios.com>
Fri, 16 Oct 2020 19:45:43 +0000 (15:45 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 16 Oct 2020 20:28:22 +0000 (16:28 -0400)
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 <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Iee41d8ea845836d273f01e890ea4196ae2ed43ef

tests/pthread_name/Makefile.am
tests/pthread_name/pthread_name.c

index 66fa7181c6e55e37d0536d725933987dc2a7583d..173191d724dc6b9f2baba3cf7f0c25c8f2e73e44 100644 (file)
@@ -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
index 05298f5bbeff26409b55664441586370cfc1ce31..b6c7831b5720d0c8b4d8cd389736a1d5b055956f 100644 (file)
 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();
 }
This page took 0.026129 seconds and 5 git commands to generate.