2 * Copyright (C) 2015 EfficiOS Inc.
4 * SPDX-License-Identifier: GPL-2.0-only
14 #include <common/utils.hpp>
17 int lttng_opt_quiet
= 1;
18 int lttng_opt_verbose
= 3;
21 struct valid_test_input
{
23 uint64_t expected_result
;
26 /* Valid test cases */
27 static struct valid_test_input valid_tests_inputs
[] = {
35 { "20m", 1200000000 },
37 { "5h", 18000000000 },
55 static const int num_valid_tests
= sizeof(valid_tests_inputs
) / sizeof(valid_tests_inputs
[0]);
57 /* Invalid test cases */
58 static const char *invalid_tests_inputs
[] = {
63 "4611686018427387904s",
79 "14ms garbage after value",
90 static const int num_invalid_tests
= sizeof(invalid_tests_inputs
) / sizeof(invalid_tests_inputs
[0]);
92 static void test_utils_parse_time_suffix(void)
98 /* Test valid cases */
99 for (i
= 0; i
< num_valid_tests
; i
++) {
102 ret
= utils_parse_time_suffix(valid_tests_inputs
[i
].input
, &result
);
103 sprintf(name
, "valid test case: %s expected %" PRIu64
, valid_tests_inputs
[i
].input
, result
);
104 ok(ret
== 0 && result
== valid_tests_inputs
[i
].expected_result
, "%s", name
);
107 /* Test invalid cases */
108 for (i
= 0; i
< num_invalid_tests
; i
++) {
111 sprintf(name
, "invalid test case: %s", invalid_tests_inputs
[i
]);
113 ret
= utils_parse_time_suffix(invalid_tests_inputs
[i
], &result
);
114 ok(ret
!= 0, "%s", name
);
120 plan_tests(num_valid_tests
+ num_invalid_tests
);
122 diag("utils_parse_time_suffix tests");
124 test_utils_parse_time_suffix();
126 return exit_status();