Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Arnaldo Carvalho de Melo | fd20e81 | 2017-04-17 15:23:08 -0300 | [diff] [blame] | 2 | #include <inttypes.h> |
Jiri Olsa | 9808143 | 2017-01-09 10:51:55 +0100 | [diff] [blame] | 3 | #include <linux/compiler.h> |
| 4 | #include <linux/types.h> |
| 5 | #include "tests.h" |
Arnaldo Carvalho de Melo | 58db1d6 | 2017-04-19 16:05:56 -0300 | [diff] [blame] | 6 | #include "units.h" |
Jiri Olsa | 9808143 | 2017-01-09 10:51:55 +0100 | [diff] [blame] | 7 | #include "debug.h" |
| 8 | |
Arnaldo Carvalho de Melo | 81f17c9 | 2017-08-03 15:16:31 -0300 | [diff] [blame] | 9 | int test__unit_number__scnprint(struct test *t __maybe_unused, int subtest __maybe_unused) |
Jiri Olsa | 9808143 | 2017-01-09 10:51:55 +0100 | [diff] [blame] | 10 | { |
| 11 | struct { |
| 12 | u64 n; |
| 13 | const char *str; |
| 14 | } test[] = { |
| 15 | { 1, "1B" }, |
| 16 | { 10*1024, "10K" }, |
| 17 | { 20*1024*1024, "20M" }, |
| 18 | { 30*1024*1024*1024ULL, "30G" }, |
| 19 | { 0, "0B" }, |
| 20 | { 0, NULL }, |
| 21 | }; |
| 22 | unsigned i = 0; |
| 23 | |
| 24 | while (test[i].str) { |
| 25 | char buf[100]; |
| 26 | |
| 27 | unit_number__scnprintf(buf, sizeof(buf), test[i].n); |
| 28 | |
| 29 | pr_debug("n %" PRIu64 ", str '%s', buf '%s'\n", |
| 30 | test[i].n, test[i].str, buf); |
| 31 | |
| 32 | if (strcmp(test[i].str, buf)) |
| 33 | return TEST_FAIL; |
| 34 | |
| 35 | i++; |
| 36 | } |
| 37 | |
| 38 | return TEST_OK; |
| 39 | } |