Add pthread_setname_np tests
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 15 Oct 2020 21:12:30 +0000 (17:12 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 15 Oct 2020 21:18:15 +0000 (17:18 -0400)
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I5999ecddf62be9ad25cd67a61ff7315b48f3306a

.gitignore
configure.ac
tests/Makefile.am
tests/pthread_name/Makefile.am [new file with mode: 0644]
tests/pthread_name/pthread_name.c [new file with mode: 0644]

index a6618cb19d3e34fb9514a10822b929f2aa9f5507..5dd6e931abe99214a3d90dc9c0fced42bba8b7d2 100644 (file)
@@ -87,6 +87,7 @@ tests/benchmark/bench2
 tests/ctf-types/ctf-types
 tests/test-app-ctx/hello
 tests/gcc-weak-hidden/test_gcc_weak_hidden
+tests/pthread_name/test_pthread_name
 
 # Java agent library
 *.class
index 15fb68057ba3dbf27376d6612e3aea7bb74cd171..e7b8358143e29808df4ed7b7907578fb7baf9da1 100644 (file)
@@ -575,6 +575,7 @@ AC_CONFIG_FILES([
        tests/snprintf/Makefile
        tests/ust-elf/Makefile
        tests/benchmark/Makefile
+       tests/pthread_name/Makefile
        tests/utils/Makefile
        tests/test-app-ctx/Makefile
        tests/gcc-weak-hidden/Makefile
index b1042dbef1e64c7b0307a2b528a751792e962c9c..d46c94a58fe293e51a84d3dd456d292ebef73bbc 100644 (file)
@@ -1,5 +1,5 @@
 SUBDIRS = utils hello same_line_tracepoint snprintf benchmark ust-elf \
-               ctf-types test-app-ctx gcc-weak-hidden hello-many
+               ctf-types test-app-ctx gcc-weak-hidden hello-many pthread_name
 
 if CXX_WORKS
 SUBDIRS += hello.cxx
@@ -11,7 +11,8 @@ LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
 
 TESTS = snprintf/test_snprintf \
        ust-elf/test_ust_elf \
-       gcc-weak-hidden/test_gcc_weak_hidden
+       gcc-weak-hidden/test_gcc_weak_hidden \
+       pthread_name/test_pthread_name
 
 EXTRA_DIST = README
 
diff --git a/tests/pthread_name/Makefile.am b/tests/pthread_name/Makefile.am
new file mode 100644 (file)
index 0000000..66fa718
--- /dev/null
@@ -0,0 +1,5 @@
+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
+test_pthread_name_LDADD = $(top_builddir)/tests/utils/libtap.a
diff --git a/tests/pthread_name/pthread_name.c b/tests/pthread_name/pthread_name.c
new file mode 100644 (file)
index 0000000..05298f5
--- /dev/null
@@ -0,0 +1,68 @@
+/* Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include "compat.h"
+
+#include "tap.h"
+
+#define TEST_NAME_PROPER_LEN 16
+
+int main()
+{
+       int ret;
+       char name[TEST_NAME_PROPER_LEN];
+       char short_name[] = "labatt50";
+       char short_name_ust[] = "labatt50-ust";
+       char long_name[] = "thisnameistoolong";
+       char long_name_ust[] = "thisnameist-ust";
+
+       plan_tests(9);
+
+       ret = lttng_pthread_getname_np(name, TEST_NAME_PROPER_LEN);
+       ok(ret == 0, "Get the thread name: %s", name);
+
+       /* 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);
+
+       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);
+
+       /* 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);
+
+
+       /* Set a thread name of more than 16 bytes */
+       ret = lttng_pthread_setname_np(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);
+
+       /* 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);
+
+       return exit_status();
+}
This page took 0.028695 seconds and 5 git commands to generate.