1*fd20e811SArnaldo Carvalho de Melo #include <inttypes.h> 29808143bSJiri Olsa #include <linux/compiler.h> 39808143bSJiri Olsa #include <linux/types.h> 49808143bSJiri Olsa #include "tests.h" 59808143bSJiri Olsa #include "util.h" 69808143bSJiri Olsa #include "debug.h" 79808143bSJiri Olsa 89808143bSJiri Olsa int test__unit_number__scnprint(int subtest __maybe_unused) 99808143bSJiri Olsa { 109808143bSJiri Olsa struct { 119808143bSJiri Olsa u64 n; 129808143bSJiri Olsa const char *str; 139808143bSJiri Olsa } test[] = { 149808143bSJiri Olsa { 1, "1B" }, 159808143bSJiri Olsa { 10*1024, "10K" }, 169808143bSJiri Olsa { 20*1024*1024, "20M" }, 179808143bSJiri Olsa { 30*1024*1024*1024ULL, "30G" }, 189808143bSJiri Olsa { 0, "0B" }, 199808143bSJiri Olsa { 0, NULL }, 209808143bSJiri Olsa }; 219808143bSJiri Olsa unsigned i = 0; 229808143bSJiri Olsa 239808143bSJiri Olsa while (test[i].str) { 249808143bSJiri Olsa char buf[100]; 259808143bSJiri Olsa 269808143bSJiri Olsa unit_number__scnprintf(buf, sizeof(buf), test[i].n); 279808143bSJiri Olsa 289808143bSJiri Olsa pr_debug("n %" PRIu64 ", str '%s', buf '%s'\n", 299808143bSJiri Olsa test[i].n, test[i].str, buf); 309808143bSJiri Olsa 319808143bSJiri Olsa if (strcmp(test[i].str, buf)) 329808143bSJiri Olsa return TEST_FAIL; 339808143bSJiri Olsa 349808143bSJiri Olsa i++; 359808143bSJiri Olsa } 369808143bSJiri Olsa 379808143bSJiri Olsa return TEST_OK; 389808143bSJiri Olsa } 39