summaryrefslogtreecommitdiffstats
path: root/unit/test-suffix-binary-parse.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-04-03 08:17:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-04-03 08:17:29 +0000
commit61c4ff8b2ddc3841050c17a5f87791653dbd2b7b (patch)
treee97b4f25c511372d73bdd96c389c5f468d99138a /unit/test-suffix-binary-parse.c
parentAdding upstream version 2.4. (diff)
downloadnvme-cli-61c4ff8b2ddc3841050c17a5f87791653dbd2b7b.tar.xz
nvme-cli-61c4ff8b2ddc3841050c17a5f87791653dbd2b7b.zip
Adding upstream version 2.4+really2.3.upstream/2.4+really2.3
This reverts commit f42531334c05b7f49ae43c0a27e347a487fb2667.
Diffstat (limited to '')
-rw-r--r--unit/test-suffix-binary-parse.c68
1 files changed, 0 insertions, 68 deletions
diff --git a/unit/test-suffix-binary-parse.c b/unit/test-suffix-binary-parse.c
deleted file mode 100644
index 5f6ac4a..0000000
--- a/unit/test-suffix-binary-parse.c
+++ /dev/null
@@ -1,68 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include "../util/suffix.h"
-#include "../util/types.h"
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
-static int test_rc;
-
-static void check_num(const char *val, __u64 exp, __u64 num)
-{
- if (exp == num)
- return;
-
- printf("ERROR: printing {%s}, got '%llu', expected '%llu'\n",
- val, (unsigned long long)num, (unsigned long long)exp);
-
- test_rc = 1;
-}
-
-struct tonum_test {
- const char *val;
- const uint64_t exp;
- int ret;
-};
-
-static struct tonum_test tonum_tests[] = {
- { "1234", 1234, 0 },
- { "1Ki", 1024, 0},
- { "34Gi", 36507222016, 0 },
- { "34.9Ki", 0, -EINVAL},
- { "32Gii", 0, -EINVAL },
-};
-
-void tonum_test(struct tonum_test *test)
-{
- char *endptr;
- uint64_t num;
- int ret;
-
- ret = suffix_binary_parse(test->val, &endptr, &num);
- if (ret != test->ret) {
- printf("ERROR: converting {%s} failed\n", test->val);
- test_rc = 1;
- return;
- }
- if (ret)
- return;
-
- check_num(test->val, test->exp, num);
-}
-
-int main(void)
-{
- unsigned int i;
-
- test_rc = 0;
-
- for (i = 0; i < ARRAY_SIZE(tonum_tests); i++)
- tonum_test(&tonum_tests[i]);
-
- return test_rc ? EXIT_FAILURE : EXIT_SUCCESS;
-}