aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/tests/unit_number__scnprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/tests/unit_number__scnprintf.c')
-rw-r--r--tools/perf/tests/unit_number__scnprintf.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/tools/perf/tests/unit_number__scnprintf.c b/tools/perf/tests/unit_number__scnprintf.c
new file mode 100644
index 000000000000..623c2aa53c4a
--- /dev/null
+++ b/tools/perf/tests/unit_number__scnprintf.c
@@ -0,0 +1,37 @@
1#include <linux/compiler.h>
2#include <linux/types.h>
3#include "tests.h"
4#include "util.h"
5#include "debug.h"
6
7int 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}