18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#include <inttypes.h>
38c2ecf20Sopenharmony_ci#include <linux/compiler.h>
48c2ecf20Sopenharmony_ci#include <linux/types.h>
58c2ecf20Sopenharmony_ci#include <string.h>
68c2ecf20Sopenharmony_ci#include "tests.h"
78c2ecf20Sopenharmony_ci#include "units.h"
88c2ecf20Sopenharmony_ci#include "debug.h"
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciint test__unit_number__scnprint(struct test *t __maybe_unused, int subtest __maybe_unused)
118c2ecf20Sopenharmony_ci{
128c2ecf20Sopenharmony_ci	struct {
138c2ecf20Sopenharmony_ci		u64		 n;
148c2ecf20Sopenharmony_ci		const char	*str;
158c2ecf20Sopenharmony_ci	} test[] = {
168c2ecf20Sopenharmony_ci		{ 1,			"1B"	},
178c2ecf20Sopenharmony_ci		{ 10*1024,		"10K"	},
188c2ecf20Sopenharmony_ci		{ 20*1024*1024,		"20M"	},
198c2ecf20Sopenharmony_ci		{ 30*1024*1024*1024ULL,	"30G"	},
208c2ecf20Sopenharmony_ci		{ 0,			"0B"	},
218c2ecf20Sopenharmony_ci		{ 0,			NULL	},
228c2ecf20Sopenharmony_ci	};
238c2ecf20Sopenharmony_ci	unsigned i = 0;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	while (test[i].str) {
268c2ecf20Sopenharmony_ci		char buf[100];
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci		unit_number__scnprintf(buf, sizeof(buf), test[i].n);
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci		pr_debug("n %" PRIu64 ", str '%s', buf '%s'\n",
318c2ecf20Sopenharmony_ci			 test[i].n, test[i].str, buf);
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci		if (strcmp(test[i].str, buf))
348c2ecf20Sopenharmony_ci			return TEST_FAIL;
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci		i++;
378c2ecf20Sopenharmony_ci	}
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	return TEST_OK;
408c2ecf20Sopenharmony_ci}
41