utils.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #define __cacheline_aligned __attribute__((aligned(128)))
  8. #include <stdint.h>
  9. #include <stdbool.h>
  10. #include <linux/auxvec.h>
  11. #include "reg.h"
  12. /* Avoid headaches with PRI?64 - just use %ll? always */
  13. typedef unsigned long long u64;
  14. typedef signed long long s64;
  15. /* Just for familiarity */
  16. typedef uint32_t u32;
  17. typedef uint16_t u16;
  18. typedef uint8_t u8;
  19. void test_harness_set_timeout(uint64_t time);
  20. int test_harness(int (test_function)(void), char *name);
  21. extern void *get_auxv_entry(int type);
  22. int pick_online_cpu(void);
  23. static inline bool have_hwcap(unsigned long ftr)
  24. {
  25. return ((unsigned long)get_auxv_entry(AT_HWCAP) & ftr) == ftr;
  26. }
  27. #ifdef AT_HWCAP2
  28. static inline bool have_hwcap2(unsigned long ftr2)
  29. {
  30. return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;
  31. }
  32. #else
  33. static inline bool have_hwcap2(unsigned long ftr2)
  34. {
  35. return false;
  36. }
  37. #endif
  38. /* Yes, this is evil */
  39. #define FAIL_IF(x) \
  40. do { \
  41. if ((x)) { \
  42. fprintf(stderr, \
  43. "[FAIL] Test FAILED on line %d\n", __LINE__); \
  44. return 1; \
  45. } \
  46. } while (0)
  47. /* The test harness uses this, yes it's gross */
  48. #define MAGIC_SKIP_RETURN_VALUE 99
  49. #define SKIP_IF(x) \
  50. do { \
  51. if ((x)) { \
  52. fprintf(stderr, \
  53. "[SKIP] Test skipped on line %d\n", __LINE__); \
  54. return MAGIC_SKIP_RETURN_VALUE; \
  55. } \
  56. } while (0)
  57. #define _str(s) #s
  58. #define str(s) _str(s)
  59. /* POWER9 feature */
  60. #ifndef PPC_FEATURE2_ARCH_3_00
  61. #define PPC_FEATURE2_ARCH_3_00 0x00800000
  62. #endif
  63. #endif /* _SELFTESTS_POWERPC_UTILS_H */