utils.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. int read_auxv(char *buf, ssize_t buf_size);
  22. void *find_auxv_entry(int type, char *auxv);
  23. void *get_auxv_entry(int type);
  24. int pick_online_cpu(void);
  25. static inline bool have_hwcap(unsigned long ftr)
  26. {
  27. return ((unsigned long)get_auxv_entry(AT_HWCAP) & ftr) == ftr;
  28. }
  29. #ifdef AT_HWCAP2
  30. static inline bool have_hwcap2(unsigned long ftr2)
  31. {
  32. return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;
  33. }
  34. #else
  35. static inline bool have_hwcap2(unsigned long ftr2)
  36. {
  37. return false;
  38. }
  39. #endif
  40. bool is_ppc64le(void);
  41. /* Yes, this is evil */
  42. #define FAIL_IF(x) \
  43. do { \
  44. if ((x)) { \
  45. fprintf(stderr, \
  46. "[FAIL] Test FAILED on line %d\n", __LINE__); \
  47. return 1; \
  48. } \
  49. } while (0)
  50. /* The test harness uses this, yes it's gross */
  51. #define MAGIC_SKIP_RETURN_VALUE 99
  52. #define SKIP_IF(x) \
  53. do { \
  54. if ((x)) { \
  55. fprintf(stderr, \
  56. "[SKIP] Test skipped on line %d\n", __LINE__); \
  57. return MAGIC_SKIP_RETURN_VALUE; \
  58. } \
  59. } while (0)
  60. #define _str(s) #s
  61. #define str(s) _str(s)
  62. /* POWER9 feature */
  63. #ifndef PPC_FEATURE2_ARCH_3_00
  64. #define PPC_FEATURE2_ARCH_3_00 0x00800000
  65. #endif
  66. #endif /* _SELFTESTS_POWERPC_UTILS_H */