xref: /openbmc/linux/tools/perf/tests/is_printable_array.c (revision 877a7a11050ee4d465364c57f8fbf78f6b1a2559)
1988dd774SJiri Olsa #include <linux/compiler.h>
2*877a7a11SArnaldo Carvalho de Melo #include <linux/kernel.h>
3988dd774SJiri Olsa #include "tests.h"
4988dd774SJiri Olsa #include "debug.h"
5988dd774SJiri Olsa #include "util.h"
6988dd774SJiri Olsa 
7988dd774SJiri Olsa int test__is_printable_array(int subtest __maybe_unused)
8988dd774SJiri Olsa {
9988dd774SJiri Olsa 	char buf1[] = { 'k', 'r', 4, 'v', 'a', 0 };
10988dd774SJiri Olsa 	char buf2[] = { 'k', 'r', 'a', 'v', 4, 0 };
11988dd774SJiri Olsa 	struct {
12988dd774SJiri Olsa 		char		*buf;
13988dd774SJiri Olsa 		unsigned int	 len;
14988dd774SJiri Olsa 		int		 ret;
15988dd774SJiri Olsa 	} t[] = {
16988dd774SJiri Olsa 		{ (char *) "krava",	sizeof("krava"),	1 },
17988dd774SJiri Olsa 		{ (char *) "krava",	sizeof("krava") - 1,	0 },
18988dd774SJiri Olsa 		{ (char *) "",		sizeof(""),		1 },
19988dd774SJiri Olsa 		{ (char *) "",		0,			0 },
20988dd774SJiri Olsa 		{ NULL,			0,			0 },
21988dd774SJiri Olsa 		{ buf1,			sizeof(buf1),		0 },
22988dd774SJiri Olsa 		{ buf2,			sizeof(buf2),		0 },
23988dd774SJiri Olsa 	};
24988dd774SJiri Olsa 	unsigned int i;
25988dd774SJiri Olsa 
26988dd774SJiri Olsa 	for (i = 0; i < ARRAY_SIZE(t); i++) {
27988dd774SJiri Olsa 		int ret;
28988dd774SJiri Olsa 
29988dd774SJiri Olsa 		ret = is_printable_array((char *) t[i].buf, t[i].len);
30988dd774SJiri Olsa 		if (ret != t[i].ret) {
31988dd774SJiri Olsa 			pr_err("failed: test %u\n", i);
32988dd774SJiri Olsa 			return TEST_FAIL;
33988dd774SJiri Olsa 		}
34988dd774SJiri Olsa 	}
35988dd774SJiri Olsa 
36988dd774SJiri Olsa 	return TEST_OK;
37988dd774SJiri Olsa }
38