Merge branch 'work.splice_read' of git://git.kernel.org/pub/scm/linux/kernel/git...
[cascardo/linux.git] / tools / testing / selftests / powerpc / utils.h
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 #define __cacheline_aligned __attribute__((aligned(128)))
10
11 #include <stdint.h>
12 #include <stdbool.h>
13 #include <linux/auxvec.h>
14 #include "reg.h"
15
16 /* Avoid headaches with PRI?64 - just use %ll? always */
17 typedef unsigned long long u64;
18 typedef   signed long long s64;
19
20 /* Just for familiarity */
21 typedef uint32_t u32;
22 typedef uint16_t u16;
23 typedef uint8_t u8;
24
25
26 int test_harness(int (test_function)(void), char *name);
27 extern void *get_auxv_entry(int type);
28 int pick_online_cpu(void);
29
30 static inline bool have_hwcap(unsigned long ftr)
31 {
32         return ((unsigned long)get_auxv_entry(AT_HWCAP) & ftr) == ftr;
33 }
34
35 static inline bool have_hwcap2(unsigned long ftr2)
36 {
37         return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;
38 }
39
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
50 /* The test harness uses this, yes it's gross */
51 #define MAGIC_SKIP_RETURN_VALUE 99
52
53 #define SKIP_IF(x)                                              \
54 do {                                                            \
55         if ((x)) {                                              \
56                 fprintf(stderr,                                 \
57                 "[SKIP] Test skipped on line %d\n", __LINE__);  \
58                 return MAGIC_SKIP_RETURN_VALUE;                 \
59         }                                                       \
60 } while (0)
61
62 #define _str(s) #s
63 #define str(s) _str(s)
64
65 /* POWER9 feature */
66 #ifndef PPC_FEATURE2_ARCH_3_00
67 #define PPC_FEATURE2_ARCH_3_00 0x00800000
68 #endif
69
70 #endif /* _SELFTESTS_POWERPC_UTILS_H */