X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=tests%2Funit%2Ftest_relayd_backward_compat_group_by_session.c;h=0ebcf34ab87cf873bd1ad6df6c54807ba61c6a60;hp=733a39a6819289b24dd783c5c92e8cbff27a569e;hb=ae0a823f9f7e1d3800479488a58efc2f92f27d89;hpb=73e9abbe73eebb1cff3ef1267394f919306e5927 diff --git a/tests/unit/test_relayd_backward_compat_group_by_session.c b/tests/unit/test_relayd_backward_compat_group_by_session.c index 733a39a68..0ebcf34ab 100644 --- a/tests/unit/test_relayd_backward_compat_group_by_session.c +++ b/tests/unit/test_relayd_backward_compat_group_by_session.c @@ -1,19 +1,8 @@ /* - * Copyright (c) - 2019 Jonathan Rajotte-Julien - * + * Copyright (C) 2019 Jonathan Rajotte * - * 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. + * SPDX-License-Identifier: GPL-2.0-only * - * 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 @@ -23,18 +12,20 @@ #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; + const char *stream_path; + const char *session_name; + const char *hostname; + const char *creation_time; + const char *extra_path; + const char *leftover; bool is_valid; }; @@ -108,40 +99,61 @@ struct test tests[] = { "", "ust/uid/1000/64-bit", true}, }; -static char *craft_expected(struct test *test) +static char *craft_expected(struct test *test, time_t relay_session_creation_time) { int ret; char *result = NULL; + char relay_session_creation_datetime[DATETIME_STR_LEN]; - ret = asprintf(&result, "%s/%s%s%s/%s%s%s", test->session_name, + ret = time_to_datetime_str(relay_session_creation_time, + relay_session_creation_datetime, + sizeof(relay_session_creation_datetime)); + if (ret < 0) { + result = NULL; + goto end; + } + + ret = asprintf(&result, "%s/%s-%s/%s%s%s", test->session_name, test->hostname, - test->creation_time[0] != '\0' ? "-" : "", - test->creation_time, test->extra_path, + test->creation_time[0] == '\0' ? + relay_session_creation_datetime : + test->creation_time, + test->extra_path, test->extra_path[0] != '\0' ? "/" : "", test->leftover); if (ret < 0) { result = NULL; + goto end; } +end: return result; } int main(int argc, char **argv) { + int i; int num_test = sizeof(tests) / sizeof(struct test); + const time_t test_time = time(NULL); 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++) { + + if (test_time == (time_t) -1) { + perror("Failed to sample time"); + return exit_status(); + } + + for (i = 0; i < num_test; i++) { char *expected = NULL; char *result = NULL; - expected = craft_expected(&tests[i]); + expected = craft_expected(&tests[i], test_time); 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); + result = backward_compat_group_by_session(tests[i].stream_path, + tests[i].session_name, test_time); if (!result && tests[i].is_valid) { fprintf(stderr, "Failed to get result\n"); goto loop;