1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2988dd774SJiri Olsa #include <linux/compiler.h>
3877a7a11SArnaldo Carvalho de Melo #include <linux/kernel.h>
4988dd774SJiri Olsa #include "tests.h"
5988dd774SJiri Olsa #include "debug.h"
6fea01392SArnaldo Carvalho de Melo #include "print_binary.h"
7988dd774SJiri Olsa
test__is_printable_array(struct test_suite * test __maybe_unused,int subtest __maybe_unused)8*33f44bfdSIan Rogers static int test__is_printable_array(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
9988dd774SJiri Olsa {
10988dd774SJiri Olsa char buf1[] = { 'k', 'r', 4, 'v', 'a', 0 };
11988dd774SJiri Olsa char buf2[] = { 'k', 'r', 'a', 'v', 4, 0 };
12988dd774SJiri Olsa struct {
13988dd774SJiri Olsa char *buf;
14988dd774SJiri Olsa unsigned int len;
15988dd774SJiri Olsa int ret;
16988dd774SJiri Olsa } t[] = {
17988dd774SJiri Olsa { (char *) "krava", sizeof("krava"), 1 },
18988dd774SJiri Olsa { (char *) "krava", sizeof("krava") - 1, 0 },
19988dd774SJiri Olsa { (char *) "", sizeof(""), 1 },
20988dd774SJiri Olsa { (char *) "", 0, 0 },
21988dd774SJiri Olsa { NULL, 0, 0 },
22988dd774SJiri Olsa { buf1, sizeof(buf1), 0 },
23988dd774SJiri Olsa { buf2, sizeof(buf2), 0 },
24988dd774SJiri Olsa };
25988dd774SJiri Olsa unsigned int i;
26988dd774SJiri Olsa
27988dd774SJiri Olsa for (i = 0; i < ARRAY_SIZE(t); i++) {
28988dd774SJiri Olsa int ret;
29988dd774SJiri Olsa
30988dd774SJiri Olsa ret = is_printable_array((char *) t[i].buf, t[i].len);
31988dd774SJiri Olsa if (ret != t[i].ret) {
32988dd774SJiri Olsa pr_err("failed: test %u\n", i);
33988dd774SJiri Olsa return TEST_FAIL;
34988dd774SJiri Olsa }
35988dd774SJiri Olsa }
36988dd774SJiri Olsa
37988dd774SJiri Olsa return TEST_OK;
38988dd774SJiri Olsa }
39d68f0365SIan Rogers
40d68f0365SIan Rogers DEFINE_SUITE("is_printable_array", is_printable_array);
41