From: Jonathan Rajotte Date: Thu, 19 Sep 2019 21:26:06 +0000 (-0400) Subject: Tests: unit testing for backward compatibility of group-output-by-session X-Git-Tag: v2.12.0-rc1~248 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=73e9abbe73eebb1cff3ef1267394f919306e5927;p=lttng-tools.git Tests: unit testing for backward compatibility of group-output-by-session These unit tests aim to reproduce the stream path received by lttng-relayd when dealing with a producer using a protocol version < 2.11. We then pass them through the transform function for --group-output-by-session used when producer are using protocol version greater or equal to 2.4 and small than 2.11. Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau --- diff --git a/.gitignore b/.gitignore index 00a68d427..61d7ca38f 100644 --- a/.gitignore +++ b/.gitignore @@ -85,6 +85,7 @@ compile_commands.json /tests/unit/test_utils_expand_path /tests/unit/test_notification /tests/unit/test_directory_handle +/tests/unit/test_relayd_backward_compat_group_by_session kernel_all_events_basic kernel_event_basic ust_global_event_wildcard diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index dd83bc636..0509d5114 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -16,6 +16,7 @@ TESTS = test_kernel_data \ test_string_utils \ test_notification \ test_directory_handle \ + test_relayd_backward_compat_group_by_session \ ini_config/test_ini_config LIBTAP=$(top_builddir)/tests/utils/tap/libtap.la @@ -31,7 +32,8 @@ LIBLTTNG_CTL=$(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la noinst_PROGRAMS = test_uri test_session test_kernel_data \ test_utils_parse_size_suffix test_utils_parse_time_suffix \ test_utils_expand_path test_utils_compat_poll \ - test_string_utils test_notification test_directory_handle + test_string_utils test_notification test_directory_handle \ + test_relayd_backward_compat_group_by_session if HAVE_LIBLTTNG_UST_CTL noinst_PROGRAMS += test_ust_data @@ -90,6 +92,8 @@ SESSIOND_OBJS += $(top_builddir)/src/bin/lttng-sessiond/trace-ust.$(OBJEXT) \ $(top_builddir)/src/bin/lttng-sessiond/ust-field-utils.$(OBJEXT) endif +RELAYD_OBJS = $(top_builddir)/src/bin/lttng-relayd/backward-compatibility-group-by.$(OBJEXT) + test_session_SOURCES = test_session.c test_session_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBRELAYD) $(LIBSESSIOND_COMM) \ $(LIBHASHTABLE) $(DL_LIBS) -lrt -lurcu-common -lurcu \ @@ -170,3 +174,8 @@ test_string_utils_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBSTRINGUTILS) $(DL_LIBS) # Notification api test_notification_SOURCES = test_notification.c test_notification_LDADD = $(LIBTAP) $(LIBLTTNG_CTL) $(DL_LIBS) + +# relayd backward compat for groou-by-session utilities +test_relayd_backward_compat_group_by_session_SOURCES = test_relayd_backward_compat_group_by_session.c +test_relayd_backward_compat_group_by_session_LDADD = $(LIBTAP) $(LIBCOMMON) $(RELAYD_OBJS) +test_relayd_backward_compat_group_by_session_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src/bin/lttng-relayd diff --git a/tests/unit/test_relayd_backward_compat_group_by_session.c b/tests/unit/test_relayd_backward_compat_group_by_session.c new file mode 100644 index 000000000..733a39a68 --- /dev/null +++ b/tests/unit/test_relayd_backward_compat_group_by_session.c @@ -0,0 +1,161 @@ +/* + * Copyright (c) - 2019 Jonathan Rajotte-Julien + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by as + * published by the Free Software Foundation; only version 2 of the License. + * + * This program 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include +#include +#include + +#include "backward-compatibility-group-by.h" + +/* Number of TAP tests in this file */ +#define NUM_TESTS_PER_TEST 1 + +struct test { + char *stream_path; + char *session_name; + char *hostname; + char *creation_time; + char *extra_path; + char *leftover; + bool is_valid; +}; + +int lttng_opt_quiet; +int lttng_opt_mi; +int lttng_opt_verbose; + +struct test tests[] = { + /* Default name session streaming. */ + {"hostname/auto-20190918-164429/ust/uid/1000/64-bit", + "auto-20190918-164429", "hostname", + "20190918-164429", "", "ust/uid/1000/64-bit", + true}, + /* Custom default name session */ + {"hostname/custom_auto-20190319-120000/ust/uid/1000/64-bit", + "custom_auto-20190319-120000", "hostname", + "20190319-120000", "", "ust/uid/1000/64-bit", + true}, + /* Named session streaming */ + {"hostname/test-20190918-164709/ust/uid/1000/64-bit", "test", + "hostname", "20190918-164709", "", + "ust/uid/1000/64-bit", true}, + /* Default session snapshot streaming */ + {"hostname//snapshot-1-20190918-164829-0/ust//uid/1000/64-bit", + "my_session", "hostname", "", "", + "snapshot-1-20190918-164829-0/ust//uid/1000/64-bit", + true}, + /* Named session snapshot streaming */ + {"hostname//snapshot-1-20190918-175919-0/ust//uid/1000/64-bit", + "my_session", "hostname", "", "", + "snapshot-1-20190918-175919-0/ust//uid/1000/64-bit", + true}, + /* Default name session, live */ + {"hostname//auto-20190918-171641/ust/uid/1000/64-bit", + "auto-20190918-171641", "hostname", + "20190918-171641", "", "ust/uid/1000/64-bit", + true}, + /* Named session, live */ + {"hostname//test-20190918-180333//ust/uid/1000/64-bit", + "test-20190918-180333", "hostname", + "20190918-180333", "", "/ust/uid/1000/64-bit", + true}, + /* Default name session, streaming & live , extra path */ + {"hostname/extra/path/ust/uid/1000/64-bit", + "auto-20190919-122110", "hostname", + "20190919-122110", "extra", + "path/ust/uid/1000/64-bit", true}, + /* Named session, live, extra path */ + {"hostname/extra/path/ust/uid/1000/64-bit", "test", "hostname", + "", "extra", "path/ust/uid/1000/64-bit", true}, + /* Named session, snapshot, extra path */ + {"hostname/extra/path/snapshot-1-20190919-140702-0/ust//uid/1000/64-bit", + "test", "hostname", "", "extra", + "path/snapshot-1-20190919-140702-0/ust//uid/1000/64-bit", + true}, + /* Corner cases*/ + /* Named session with valid datetime in it */ + /* Default name session, extra path with session name in it*/ + {"hostname/test-20190319-120000-20190918-180921/ust/uid/1000/64-bit", + "test-20190319-120000", "hostname", + "20190918-180921", "", "ust/uid/1000/64-bit", + true}, + /* Empty path */ + {"", "test", "", "", "", "", false}, + /* Path without second token */ + {"hostname", "test", "hostname", "", "", "", false}, + /* No leftover */ + {"hostname/test", "test", "hostname", "", "", "", true}, + /* Path with ession name but no datetime */ + {"hostname/test/ust/uid/1000/64-bit", "test", "hostname", "", + "", "ust/uid/1000/64-bit", true}, +}; + +static char *craft_expected(struct test *test) +{ + int ret; + char *result = NULL; + + ret = asprintf(&result, "%s/%s%s%s/%s%s%s", test->session_name, + test->hostname, + test->creation_time[0] != '\0' ? "-" : "", + test->creation_time, test->extra_path, + test->extra_path[0] != '\0' ? "/" : "", test->leftover); + if (ret < 0) { + result = NULL; + } + return result; +} + +int main(int argc, char **argv) +{ + int num_test = sizeof(tests) / sizeof(struct test); + + plan_tests(NUM_TESTS_PER_TEST * num_test); + diag("Backward compatibility utils for lttng-relayd --group-by-session"); + for (int i = 0; i < num_test; i++) { + char *expected = NULL; + char *result = NULL; + + expected = craft_expected(&tests[i]); + if (!expected) { + fprintf(stderr, "Failed to craft expected output\n"); + goto loop; + } + + result = backward_compat_group_by_session( + tests[i].stream_path, tests[i].session_name); + if (!result && tests[i].is_valid) { + fprintf(stderr, "Failed to get result\n"); + goto loop; + } else if (!result && tests[i].is_valid == false) { + pass("Returned null as expected"); + goto loop; + } + + ok(strncmp(expected, result, strlen(expected)) == 0, + "In: %s, out: %s, expected: %s", + tests[i].stream_path, result, expected); + loop: + free(expected); + free(result); + } + return exit_status(); +}