test_util.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * tools/testing/selftests/kvm/include/test_util.h
  3. *
  4. * Copyright (C) 2018, Google LLC.
  5. *
  6. * This work is licensed under the terms of the GNU GPL, version 2.
  7. *
  8. */
  9. #ifndef TEST_UTIL_H
  10. #define TEST_UTIL_H 1
  11. #include <stdlib.h>
  12. #include <stdarg.h>
  13. #include <stdbool.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <inttypes.h>
  17. #include <errno.h>
  18. #include <unistd.h>
  19. #include <fcntl.h>
  20. #include "kselftest.h"
  21. ssize_t test_write(int fd, const void *buf, size_t count);
  22. ssize_t test_read(int fd, void *buf, size_t count);
  23. int test_seq_read(const char *path, char **bufp, size_t *sizep);
  24. void test_assert(bool exp, const char *exp_str,
  25. const char *file, unsigned int line, const char *fmt, ...);
  26. #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
  27. #define TEST_ASSERT(e, fmt, ...) \
  28. test_assert((e), #e, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
  29. #define ASSERT_EQ(a, b) do { \
  30. typeof(a) __a = (a); \
  31. typeof(b) __b = (b); \
  32. TEST_ASSERT(__a == __b, \
  33. "ASSERT_EQ(%s, %s) failed.\n" \
  34. "\t%s is %#lx\n" \
  35. "\t%s is %#lx", \
  36. #a, #b, #a, (unsigned long) __a, #b, (unsigned long) __b); \
  37. } while (0)
  38. #endif /* TEST_UTIL_H */