2017-04-18 02:23:08 +08:00
|
|
|
#include <inttypes.h>
|
2017-01-09 17:51:55 +08:00
|
|
|
#include <linux/compiler.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include "tests.h"
|
2017-04-20 03:05:56 +08:00
|
|
|
#include "units.h"
|
2017-01-09 17:51:55 +08:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
int test__unit_number__scnprint(int subtest __maybe_unused)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
u64 n;
|
|
|
|
const char *str;
|
|
|
|
} test[] = {
|
|
|
|
{ 1, "1B" },
|
|
|
|
{ 10*1024, "10K" },
|
|
|
|
{ 20*1024*1024, "20M" },
|
|
|
|
{ 30*1024*1024*1024ULL, "30G" },
|
|
|
|
{ 0, "0B" },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
unsigned i = 0;
|
|
|
|
|
|
|
|
while (test[i].str) {
|
|
|
|
char buf[100];
|
|
|
|
|
|
|
|
unit_number__scnprintf(buf, sizeof(buf), test[i].n);
|
|
|
|
|
|
|
|
pr_debug("n %" PRIu64 ", str '%s', buf '%s'\n",
|
|
|
|
test[i].n, test[i].str, buf);
|
|
|
|
|
|
|
|
if (strcmp(test[i].str, buf))
|
|
|
|
return TEST_FAIL;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TEST_OK;
|
|
|
|
}
|