]> git.karo-electronics.de Git - karo-tx-linux.git/blob - tools/perf/tests/unit_number__scnprintf.c
Merge branches 'pm-core', 'pm-qos', 'pm-domains' and 'pm-opp'
[karo-tx-linux.git] / tools / perf / tests / unit_number__scnprintf.c
1 #include <linux/compiler.h>
2 #include <linux/types.h>
3 #include "tests.h"
4 #include "util.h"
5 #include "debug.h"
6
7 int test__unit_number__scnprint(int subtest __maybe_unused)
8 {
9         struct {
10                 u64              n;
11                 const char      *str;
12         } test[] = {
13                 { 1,                    "1B"    },
14                 { 10*1024,              "10K"   },
15                 { 20*1024*1024,         "20M"   },
16                 { 30*1024*1024*1024ULL, "30G"   },
17                 { 0,                    "0B"    },
18                 { 0,                    NULL    },
19         };
20         unsigned i = 0;
21
22         while (test[i].str) {
23                 char buf[100];
24
25                 unit_number__scnprintf(buf, sizeof(buf), test[i].n);
26
27                 pr_debug("n %" PRIu64 ", str '%s', buf '%s'\n",
28                          test[i].n, test[i].str, buf);
29
30                 if (strcmp(test[i].str, buf))
31                         return TEST_FAIL;
32
33                 i++;
34         }
35
36         return TEST_OK;
37 }