is_printable_array.c 783 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <linux/compiler.h>
  2. #include "tests.h"
  3. #include "debug.h"
  4. #include "util.h"
  5. int test__is_printable_array(int subtest __maybe_unused)
  6. {
  7. char buf1[] = { 'k', 'r', 4, 'v', 'a', 0 };
  8. char buf2[] = { 'k', 'r', 'a', 'v', 4, 0 };
  9. struct {
  10. char *buf;
  11. unsigned int len;
  12. int ret;
  13. } t[] = {
  14. { (char *) "krava", sizeof("krava"), 1 },
  15. { (char *) "krava", sizeof("krava") - 1, 0 },
  16. { (char *) "", sizeof(""), 1 },
  17. { (char *) "", 0, 0 },
  18. { NULL, 0, 0 },
  19. { buf1, sizeof(buf1), 0 },
  20. { buf2, sizeof(buf2), 0 },
  21. };
  22. unsigned int i;
  23. for (i = 0; i < ARRAY_SIZE(t); i++) {
  24. int ret;
  25. ret = is_printable_array((char *) t[i].buf, t[i].len);
  26. if (ret != t[i].ret) {
  27. pr_err("failed: test %u\n", i);
  28. return TEST_FAIL;
  29. }
  30. }
  31. return TEST_OK;
  32. }