Merge tag 'ceph-for-4.14-rc1' of git://github.com/ceph/ceph-client
[sfrench/cifs-2.6.git] / tools / perf / tests / unit_number__scnprintf.c
1 #include <inttypes.h>
2 #include <linux/compiler.h>
3 #include <linux/types.h>
4 #include "tests.h"
5 #include "units.h"
6 #include "debug.h"
7
8 int test__unit_number__scnprint(struct test *t __maybe_unused, 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 }