utils.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. int test_harness(int (test_function)(void), char *name);
  20. extern void *get_auxv_entry(int type);
  21. int pick_online_cpu(void);
  22. static inline bool have_hwcap2(unsigned long ftr2)
  23. {
  24. return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;
  25. }
  26. /* Yes, this is evil */
  27. #define FAIL_IF(x) \
  28. do { \
  29. if ((x)) { \
  30. fprintf(stderr, \
  31. "[FAIL] Test FAILED on line %d\n", __LINE__); \
  32. return 1; \
  33. } \
  34. } while (0)
  35. /* The test harness uses this, yes it's gross */
  36. #define MAGIC_SKIP_RETURN_VALUE 99
  37. #define SKIP_IF(x) \
  38. do { \
  39. if ((x)) { \
  40. fprintf(stderr, \
  41. "[SKIP] Test skipped on line %d\n", __LINE__); \
  42. return MAGIC_SKIP_RETURN_VALUE; \
  43. } \
  44. } while (0)
  45. #define _str(s) #s
  46. #define str(s) _str(s)
  47. /* POWER9 feature */
  48. #ifndef PPC_FEATURE2_ARCH_3_00
  49. #define PPC_FEATURE2_ARCH_3_00 0x00800000
  50. #endif
  51. #endif /* _SELFTESTS_POWERPC_UTILS_H */