blob: 44589de084b824319063df71ce0543f7f054088b [file] [log] [blame]
Arnaldo Carvalho de Melofd20e812017-04-17 15:23:08 -03001#include <inttypes.h>
Jiri Olsa98081432017-01-09 10:51:55 +01002#include <linux/compiler.h>
3#include <linux/types.h>
4#include "tests.h"
Arnaldo Carvalho de Melo58db1d62017-04-19 16:05:56 -03005#include "units.h"
Jiri Olsa98081432017-01-09 10:51:55 +01006#include "debug.h"
7
8int 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}