1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 2fd20e811SArnaldo Carvalho de Melo #include <inttypes.h> 39808143bSJiri Olsa #include <linux/compiler.h> 49808143bSJiri Olsa #include <linux/types.h> 5*8520a98dSArnaldo Carvalho de Melo #include <string.h> 69808143bSJiri Olsa #include "tests.h" 758db1d6eSArnaldo Carvalho de Melo #include "units.h" 89808143bSJiri Olsa #include "debug.h" 99808143bSJiri Olsa 1081f17c90SArnaldo Carvalho de Melo int test__unit_number__scnprint(struct test *t __maybe_unused, int subtest __maybe_unused) 119808143bSJiri Olsa { 129808143bSJiri Olsa struct { 139808143bSJiri Olsa u64 n; 149808143bSJiri Olsa const char *str; 159808143bSJiri Olsa } test[] = { 169808143bSJiri Olsa { 1, "1B" }, 179808143bSJiri Olsa { 10*1024, "10K" }, 189808143bSJiri Olsa { 20*1024*1024, "20M" }, 199808143bSJiri Olsa { 30*1024*1024*1024ULL, "30G" }, 209808143bSJiri Olsa { 0, "0B" }, 219808143bSJiri Olsa { 0, NULL }, 229808143bSJiri Olsa }; 239808143bSJiri Olsa unsigned i = 0; 249808143bSJiri Olsa 259808143bSJiri Olsa while (test[i].str) { 269808143bSJiri Olsa char buf[100]; 279808143bSJiri Olsa 289808143bSJiri Olsa unit_number__scnprintf(buf, sizeof(buf), test[i].n); 299808143bSJiri Olsa 309808143bSJiri Olsa pr_debug("n %" PRIu64 ", str '%s', buf '%s'\n", 319808143bSJiri Olsa test[i].n, test[i].str, buf); 329808143bSJiri Olsa 339808143bSJiri Olsa if (strcmp(test[i].str, buf)) 349808143bSJiri Olsa return TEST_FAIL; 359808143bSJiri Olsa 369808143bSJiri Olsa i++; 379808143bSJiri Olsa } 389808143bSJiri Olsa 399808143bSJiri Olsa return TEST_OK; 409808143bSJiri Olsa } 41