Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/compiler.h>
0003 #include <linux/kernel.h>
0004 #include "tests.h"
0005 #include "debug.h"
0006 #include "print_binary.h"
0007 
0008 static int test__is_printable_array(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
0009 {
0010     char buf1[] = { 'k', 'r', 4, 'v', 'a', 0 };
0011     char buf2[] = { 'k', 'r', 'a', 'v', 4, 0 };
0012     struct {
0013         char        *buf;
0014         unsigned int     len;
0015         int      ret;
0016     } t[] = {
0017         { (char *) "krava", sizeof("krava"),    1 },
0018         { (char *) "krava", sizeof("krava") - 1,    0 },
0019         { (char *) "",      sizeof(""),     1 },
0020         { (char *) "",      0,          0 },
0021         { NULL,         0,          0 },
0022         { buf1,         sizeof(buf1),       0 },
0023         { buf2,         sizeof(buf2),       0 },
0024     };
0025     unsigned int i;
0026 
0027     for (i = 0; i < ARRAY_SIZE(t); i++) {
0028         int ret;
0029 
0030         ret = is_printable_array((char *) t[i].buf, t[i].len);
0031         if (ret != t[i].ret) {
0032             pr_err("failed: test %u\n", i);
0033             return TEST_FAIL;
0034         }
0035     }
0036 
0037     return TEST_OK;
0038 }
0039 
0040 DEFINE_SUITE("is_printable_array", is_printable_array);