blob: 2bb8cb0039c18468036aba68081097c4578db957 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Arnaldo Carvalho de Melofd20e812017-04-17 15:23:08 -03002#include <inttypes.h>
Jiri Olsa98081432017-01-09 10:51:55 +01003#include <linux/compiler.h>
4#include <linux/types.h>
5#include "tests.h"
Arnaldo Carvalho de Melo58db1d62017-04-19 16:05:56 -03006#include "units.h"
Jiri Olsa98081432017-01-09 10:51:55 +01007#include "debug.h"
8
Arnaldo Carvalho de Melo81f17c92017-08-03 15:16:31 -03009int test__unit_number__scnprint(struct test *t __maybe_unused, int subtest __maybe_unused)
Jiri Olsa98081432017-01-09 10:51:55 +010010{
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}