utils.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2013, Michael Ellerman, IBM Corp.
  3. * Licensed under GPLv2.
  4. */
  5. #ifndef _SELFTESTS_POWERPC_UTILS_H
  6. #define _SELFTESTS_POWERPC_UTILS_H
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include <linux/auxvec.h>
  10. /* Avoid headaches with PRI?64 - just use %ll? always */
  11. typedef unsigned long long u64;
  12. typedef signed long long s64;
  13. /* Just for familiarity */
  14. typedef uint32_t u32;
  15. typedef uint16_t u16;
  16. typedef uint8_t u8;
  17. int test_harness(int (test_function)(void), char *name);
  18. extern void *get_auxv_entry(int type);
  19. int pick_online_cpu(void);
  20. static inline bool have_hwcap2(unsigned long ftr2)
  21. {
  22. return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;
  23. }
  24. /* Yes, this is evil */
  25. #define FAIL_IF(x) \
  26. do { \
  27. if ((x)) { \
  28. fprintf(stderr, \
  29. "[FAIL] Test FAILED on line %d\n", __LINE__); \
  30. return 1; \
  31. } \
  32. } while (0)
  33. /* The test harness uses this, yes it's gross */
  34. #define MAGIC_SKIP_RETURN_VALUE 99
  35. #define SKIP_IF(x) \
  36. do { \
  37. if ((x)) { \
  38. fprintf(stderr, \
  39. "[SKIP] Test skipped on line %d\n", __LINE__); \
  40. return MAGIC_SKIP_RETURN_VALUE; \
  41. } \
  42. } while (0)
  43. #define _str(s) #s
  44. #define str(s) _str(s)
  45. #endif /* _SELFTESTS_POWERPC_UTILS_H */