| Michael Ellerman | 2fae0d7 | 2013-08-06 17:42:36 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013, Michael Ellerman, IBM Corp. |
| 3 | * Licensed under GPLv2. |
| 4 | */ |
| 5 | |
| 6 | #ifndef _SELFTESTS_POWERPC_UTILS_H |
| 7 | #define _SELFTESTS_POWERPC_UTILS_H |
| 8 | |
| 9 | #include <stdint.h> |
| 10 | #include <stdbool.h> |
| Michael Ellerman | ede8ef3 | 2015-11-24 13:05:39 +1100 | [diff] [blame] | 11 | #include <linux/auxvec.h> |
| Michael Ellerman | 2fae0d7 | 2013-08-06 17:42:36 +1000 | [diff] [blame] | 12 | |
| 13 | /* Avoid headaches with PRI?64 - just use %ll? always */ |
| 14 | typedef unsigned long long u64; |
| 15 | typedef signed long long s64; |
| 16 | |
| 17 | /* Just for familiarity */ |
| 18 | typedef uint32_t u32; |
| Greg Kurz | 58dae82 | 2015-02-23 16:14:44 +0100 | [diff] [blame] | 19 | typedef uint16_t u16; |
| Michael Ellerman | 2fae0d7 | 2013-08-06 17:42:36 +1000 | [diff] [blame] | 20 | typedef uint8_t u8; |
| 21 | |
| 22 | |
| 23 | int test_harness(int (test_function)(void), char *name); |
| Sam bobroff | 2b03fc1 | 2015-04-10 14:16:48 +1000 | [diff] [blame] | 24 | extern void *get_auxv_entry(int type); |
| Michael Ellerman | d1301af | 2015-12-16 18:59:31 +1100 | [diff] [blame] | 25 | int pick_online_cpu(void); |
| Michael Ellerman | 2fae0d7 | 2013-08-06 17:42:36 +1000 | [diff] [blame] | 26 | |
| Michael Ellerman | ede8ef3 | 2015-11-24 13:05:39 +1100 | [diff] [blame] | 27 | static inline bool have_hwcap2(unsigned long ftr2) |
| 28 | { |
| 29 | return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2; |
| 30 | } |
| 31 | |
| Michael Ellerman | 2fae0d7 | 2013-08-06 17:42:36 +1000 | [diff] [blame] | 32 | /* Yes, this is evil */ |
| 33 | #define FAIL_IF(x) \ |
| 34 | do { \ |
| 35 | if ((x)) { \ |
| 36 | fprintf(stderr, \ |
| 37 | "[FAIL] Test FAILED on line %d\n", __LINE__); \ |
| 38 | return 1; \ |
| 39 | } \ |
| 40 | } while (0) |
| 41 | |
| Michael Ellerman | 33b4819 | 2014-06-10 22:23:09 +1000 | [diff] [blame] | 42 | /* The test harness uses this, yes it's gross */ |
| 43 | #define MAGIC_SKIP_RETURN_VALUE 99 |
| 44 | |
| 45 | #define SKIP_IF(x) \ |
| 46 | do { \ |
| 47 | if ((x)) { \ |
| 48 | fprintf(stderr, \ |
| 49 | "[SKIP] Test skipped on line %d\n", __LINE__); \ |
| 50 | return MAGIC_SKIP_RETURN_VALUE; \ |
| 51 | } \ |
| 52 | } while (0) |
| 53 | |
| Michael Ellerman | 22d651d | 2014-01-21 15:22:17 +1100 | [diff] [blame] | 54 | #define _str(s) #s |
| 55 | #define str(s) _str(s) |
| 56 | |
| Michael Ellerman | 2fae0d7 | 2013-08-06 17:42:36 +1000 | [diff] [blame] | 57 | #endif /* _SELFTESTS_POWERPC_UTILS_H */ |