utils.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /* Yes, this is evil */
  41. #define FAIL_IF(x) \
  42. do { \
  43. if ((x)) { \
  44. fprintf(stderr, \
  45. "[FAIL] Test FAILED on line %d\n", __LINE__); \
  46. return 1; \
  47. } \
  48. } while (0)
  49. /* The test harness uses this, yes it's gross */
  50. #define MAGIC_SKIP_RETURN_VALUE 99
  51. #define SKIP_IF(x) \
  52. do { \
  53. if ((x)) { \
  54. fprintf(stderr, \
  55. "[SKIP] Test skipped on line %d\n", __LINE__); \
  56. return MAGIC_SKIP_RETURN_VALUE; \
  57. } \
  58. } while (0)
  59. #define _str(s) #s
  60. #define str(s) _str(s)
  61. /* POWER9 feature */
  62. #ifndef PPC_FEATURE2_ARCH_3_00
  63. #define PPC_FEATURE2_ARCH_3_00 0x00800000
  64. #endif
  65. #endif /* _SELFTESTS_POWERPC_UTILS_H */