linux/tools/perf/tests/unit_number__scnprintf.c
Ian Rogers 33f44bfd3c perf test: Rename struct test to test_suite
This is to align with kunit's terminology.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Brendan Higgins <brendanhiggins@google.com>
Cc: Daniel Latypov <dlatypov@google.com>
Cc: David Gow <davidgow@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20211104064208.3156807-6-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-11-13 10:32:22 -03:00

43 lines
838 B
C

// SPDX-License-Identifier: GPL-2.0
#include <inttypes.h>
#include <linux/compiler.h>
#include <linux/types.h>
#include <string.h>
#include "tests.h"
#include "units.h"
#include "debug.h"
static int test__unit_number__scnprint(struct test_suite *t __maybe_unused, 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;
}
DEFINE_SUITE("unit_number__scnprintf", unit_number__scnprint);