2 * Copyright (C) 2019 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
15 #include "backward-compatibility-group-by.h"
17 /* Number of TAP tests in this file */
18 #define NUM_TESTS_PER_TEST 1
32 int lttng_opt_verbose
;
34 struct test tests
[] = {
35 /* Default name session streaming. */
36 {"hostname/auto-20190918-164429/ust/uid/1000/64-bit",
37 "auto-20190918-164429", "hostname",
38 "20190918-164429", "", "ust/uid/1000/64-bit",
40 /* Custom default name session */
41 {"hostname/custom_auto-20190319-120000/ust/uid/1000/64-bit",
42 "custom_auto-20190319-120000", "hostname",
43 "20190319-120000", "", "ust/uid/1000/64-bit",
45 /* Named session streaming */
46 {"hostname/test-20190918-164709/ust/uid/1000/64-bit", "test",
47 "hostname", "20190918-164709", "",
48 "ust/uid/1000/64-bit", true},
49 /* Default session snapshot streaming */
50 {"hostname//snapshot-1-20190918-164829-0/ust//uid/1000/64-bit",
51 "my_session", "hostname", "", "",
52 "snapshot-1-20190918-164829-0/ust//uid/1000/64-bit",
54 /* Named session snapshot streaming */
55 {"hostname//snapshot-1-20190918-175919-0/ust//uid/1000/64-bit",
56 "my_session", "hostname", "", "",
57 "snapshot-1-20190918-175919-0/ust//uid/1000/64-bit",
59 /* Default name session, live */
60 {"hostname//auto-20190918-171641/ust/uid/1000/64-bit",
61 "auto-20190918-171641", "hostname",
62 "20190918-171641", "", "ust/uid/1000/64-bit",
64 /* Named session, live */
65 {"hostname//test-20190918-180333//ust/uid/1000/64-bit",
66 "test-20190918-180333", "hostname",
67 "20190918-180333", "", "/ust/uid/1000/64-bit",
69 /* Default name session, streaming & live , extra path */
70 {"hostname/extra/path/ust/uid/1000/64-bit",
71 "auto-20190919-122110", "hostname",
72 "20190919-122110", "extra",
73 "path/ust/uid/1000/64-bit", true},
74 /* Named session, live, extra path */
75 {"hostname/extra/path/ust/uid/1000/64-bit", "test", "hostname",
76 "", "extra", "path/ust/uid/1000/64-bit", true},
77 /* Named session, snapshot, extra path */
78 {"hostname/extra/path/snapshot-1-20190919-140702-0/ust//uid/1000/64-bit",
79 "test", "hostname", "", "extra",
80 "path/snapshot-1-20190919-140702-0/ust//uid/1000/64-bit",
83 /* Named session with valid datetime in it */
84 /* Default name session, extra path with session name in it*/
85 {"hostname/test-20190319-120000-20190918-180921/ust/uid/1000/64-bit",
86 "test-20190319-120000", "hostname",
87 "20190918-180921", "", "ust/uid/1000/64-bit",
90 {"", "test", "", "", "", "", false},
91 /* Path without second token */
92 {"hostname", "test", "hostname", "", "", "", false},
94 {"hostname/test", "test", "hostname", "", "", "", true},
95 /* Path with ession name but no datetime */
96 {"hostname/test/ust/uid/1000/64-bit", "test", "hostname", "",
97 "", "ust/uid/1000/64-bit", true},
100 static char *craft_expected(struct test
*test
)
105 ret
= asprintf(&result
, "%s/%s%s%s/%s%s%s", test
->session_name
,
107 test
->creation_time
[0] != '\0' ? "-" : "",
108 test
->creation_time
, test
->extra_path
,
109 test
->extra_path
[0] != '\0' ? "/" : "", test
->leftover
);
116 int main(int argc
, char **argv
)
119 int num_test
= sizeof(tests
) / sizeof(struct test
);
121 plan_tests(NUM_TESTS_PER_TEST
* num_test
);
122 diag("Backward compatibility utils for lttng-relayd --group-by-session");
123 for (i
= 0; i
< num_test
; i
++) {
124 char *expected
= NULL
;
127 expected
= craft_expected(&tests
[i
]);
129 fprintf(stderr
, "Failed to craft expected output\n");
133 result
= backward_compat_group_by_session(
134 tests
[i
].stream_path
, tests
[i
].session_name
);
135 if (!result
&& tests
[i
].is_valid
) {
136 fprintf(stderr
, "Failed to get result\n");
138 } else if (!result
&& tests
[i
].is_valid
== false) {
139 pass("Returned null as expected");
143 ok(strncmp(expected
, result
, strlen(expected
)) == 0,
144 "In: %s, out: %s, expected: %s",
145 tests
[i
].stream_path
, result
, expected
);
150 return exit_status();
This page took 0.034024 seconds and 5 git commands to generate.