From: Michael Jeanson Date: Thu, 15 Oct 2020 21:12:30 +0000 (-0400) Subject: Add pthread_setname_np tests X-Git-Url: http://git.efficios.com/?p=deliverable%2Flttng-ust.git;a=commitdiff_plain;h=df8b7e52ec98f7f05422fc1e90929e19fcb8f03f Add pthread_setname_np tests Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers Change-Id: I5999ecddf62be9ad25cd67a61ff7315b48f3306a --- diff --git a/.gitignore b/.gitignore index a6618cb1..5dd6e931 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/configure.ac b/configure.ac index 15fb6805..e7b83581 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/tests/Makefile.am b/tests/Makefile.am index b1042dbe..d46c94a5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 00000000..66fa7181 --- /dev/null +++ b/tests/pthread_name/Makefile.am @@ -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 index 00000000..05298f5b --- /dev/null +++ b/tests/pthread_name/pthread_name.c @@ -0,0 +1,68 @@ +/* Copyright (C) 2020 Michael Jeanson + * + * 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 +#include +#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(); +}