Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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 */
17typedef unsigned long long u64;
18typedef signed long long s64;
19
20/* Just for familiarity */
21typedef uint32_t u32;
22typedef uint16_t u16;
23typedef uint8_t u8;
24
25void test_harness_set_timeout(uint64_t time);
26int test_harness(int (test_function)(void), char *name);
27
28int read_auxv(char *buf, ssize_t buf_size);
29void *find_auxv_entry(int type, char *auxv);
30void *get_auxv_entry(int type);
31
32int pick_online_cpu(void);
33
34static inline bool have_hwcap(unsigned long ftr)
35{
36 return ((unsigned long)get_auxv_entry(AT_HWCAP) & ftr) == ftr;
37}
38
39#ifdef AT_HWCAP2
40static inline bool have_hwcap2(unsigned long ftr2)
41{
42 return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;
43}
44#else
45static inline bool have_hwcap2(unsigned long ftr2)
46{
47 return false;
48}
49#endif
50
51/* Yes, this is evil */
52#define FAIL_IF(x) \
53do { \
54 if ((x)) { \
55 fprintf(stderr, \
56 "[FAIL] Test FAILED on line %d\n", __LINE__); \
57 return 1; \
58 } \
59} while (0)
60
61/* The test harness uses this, yes it's gross */
62#define MAGIC_SKIP_RETURN_VALUE 99
63
64#define SKIP_IF(x) \
65do { \
66 if ((x)) { \
67 fprintf(stderr, \
68 "[SKIP] Test skipped on line %d\n", __LINE__); \
69 return MAGIC_SKIP_RETURN_VALUE; \
70 } \
71} while (0)
72
73#define _str(s) #s
74#define str(s) _str(s)
75
76/* POWER9 feature */
77#ifndef PPC_FEATURE2_ARCH_3_00
78#define PPC_FEATURE2_ARCH_3_00 0x00800000
79#endif
80
81#endif /* _SELFTESTS_POWERPC_UTILS_H */