2 * Copyright (C) - 2015 Simon Marchi <simon.marchi@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by as
6 * published by the Free Software Foundation; only version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <common/utils.h>
28 int lttng_opt_quiet
= 1;
29 int lttng_opt_verbose
= 3;
32 struct valid_test_input
{
34 uint64_t expected_result
;
37 /* Valid test cases */
38 static struct valid_test_input valid_tests_inputs
[] = {
46 { "20m", 1200000000 },
48 { "5h", 18000000000 },
66 static const int num_valid_tests
= sizeof(valid_tests_inputs
) / sizeof(valid_tests_inputs
[0]);
68 /* Invalid test cases */
69 static char *invalid_tests_inputs
[] = {
74 "4611686018427387904s",
90 "14ms garbage after value",
101 static const int num_invalid_tests
= sizeof(invalid_tests_inputs
) / sizeof(invalid_tests_inputs
[0]);
103 static void test_utils_parse_time_suffix(void)
109 /* Test valid cases */
110 for (i
= 0; i
< num_valid_tests
; i
++) {
113 ret
= utils_parse_time_suffix(valid_tests_inputs
[i
].input
, &result
);
114 sprintf(name
, "valid test case: %s expected %" PRIu64
, valid_tests_inputs
[i
].input
, result
);
115 ok(ret
== 0 && result
== valid_tests_inputs
[i
].expected_result
, name
);
118 /* Test invalid cases */
119 for (i
= 0; i
< num_invalid_tests
; i
++) {
122 sprintf(name
, "invalid test case: %s", invalid_tests_inputs
[i
]);
124 ret
= utils_parse_time_suffix(invalid_tests_inputs
[i
], &result
);
129 int main(int argc
, char **argv
)
131 plan_tests(num_valid_tests
+ num_invalid_tests
);
133 diag("utils_parse_time_suffix tests");
135 test_utils_parse_time_suffix();
137 return exit_status();