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