Linux 4.19.133
[linux/fpc-iii.git] / tools / testing / selftests / powerpc / include / utils.h
blobc58c370828b49e6d712c843f8b5e838ea0ba2fa1
1 /*
2 * Copyright 2013, Michael Ellerman, IBM Corp.
3 * Licensed under GPLv2.
4 */
6 #ifndef _SELFTESTS_POWERPC_UTILS_H
7 #define _SELFTESTS_POWERPC_UTILS_H
9 #define __cacheline_aligned __attribute__((aligned(128)))
11 #include <stdint.h>
12 #include <stdbool.h>
13 #include <linux/auxvec.h>
14 #include "reg.h"
16 /* Avoid headaches with PRI?64 - just use %ll? always */
17 typedef unsigned long long u64;
18 typedef signed long long s64;
20 /* Just for familiarity */
21 typedef uint32_t u32;
22 typedef uint16_t u16;
23 typedef uint8_t u8;
25 void test_harness_set_timeout(uint64_t time);
26 int test_harness(int (test_function)(void), char *name);
28 int read_auxv(char *buf, ssize_t buf_size);
29 void *find_auxv_entry(int type, char *auxv);
30 void *get_auxv_entry(int type);
32 int pick_online_cpu(void);
34 static inline bool have_hwcap(unsigned long ftr)
36 return ((unsigned long)get_auxv_entry(AT_HWCAP) & ftr) == ftr;
39 #ifdef AT_HWCAP2
40 static inline bool have_hwcap2(unsigned long ftr2)
42 return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;
44 #else
45 static inline bool have_hwcap2(unsigned long ftr2)
47 return false;
49 #endif
51 bool is_ppc64le(void);
53 /* Yes, this is evil */
54 #define FAIL_IF(x) \
55 do { \
56 if ((x)) { \
57 fprintf(stderr, \
58 "[FAIL] Test FAILED on line %d\n", __LINE__); \
59 return 1; \
60 } \
61 } while (0)
63 /* The test harness uses this, yes it's gross */
64 #define MAGIC_SKIP_RETURN_VALUE 99
66 #define SKIP_IF(x) \
67 do { \
68 if ((x)) { \
69 fprintf(stderr, \
70 "[SKIP] Test skipped on line %d\n", __LINE__); \
71 return MAGIC_SKIP_RETURN_VALUE; \
72 } \
73 } while (0)
75 #define _str(s) #s
76 #define str(s) _str(s)
78 /* POWER9 feature */
79 #ifndef PPC_FEATURE2_ARCH_3_00
80 #define PPC_FEATURE2_ARCH_3_00 0x00800000
81 #endif
83 #endif /* _SELFTESTS_POWERPC_UTILS_H */