blob: 175ac6ad10dde4cc8b753a063d456fe3b8be1269 [file] [log] [blame]
Michael Ellerman2fae0d72013-08-06 17:42:36 +10001/*
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 Ellermanede8ef32015-11-24 13:05:39 +110011#include <linux/auxvec.h>
Michael Ellerman2fae0d72013-08-06 17:42:36 +100012
13/* Avoid headaches with PRI?64 - just use %ll? always */
14typedef unsigned long long u64;
15typedef signed long long s64;
16
17/* Just for familiarity */
18typedef uint32_t u32;
Greg Kurz58dae822015-02-23 16:14:44 +010019typedef uint16_t u16;
Michael Ellerman2fae0d72013-08-06 17:42:36 +100020typedef uint8_t u8;
21
22
23int test_harness(int (test_function)(void), char *name);
Sam bobroff2b03fc12015-04-10 14:16:48 +100024extern void *get_auxv_entry(int type);
Michael Ellermand1301af2015-12-16 18:59:31 +110025int pick_online_cpu(void);
Michael Ellerman2fae0d72013-08-06 17:42:36 +100026
Michael Ellermanede8ef32015-11-24 13:05:39 +110027static inline bool have_hwcap2(unsigned long ftr2)
28{
29 return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;
30}
31
Michael Ellerman2fae0d72013-08-06 17:42:36 +100032/* Yes, this is evil */
33#define FAIL_IF(x) \
34do { \
35 if ((x)) { \
36 fprintf(stderr, \
37 "[FAIL] Test FAILED on line %d\n", __LINE__); \
38 return 1; \
39 } \
40} while (0)
41
Michael Ellerman33b48192014-06-10 22:23:09 +100042/* The test harness uses this, yes it's gross */
43#define MAGIC_SKIP_RETURN_VALUE 99
44
45#define SKIP_IF(x) \
46do { \
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 Ellerman22d651d2014-01-21 15:22:17 +110054#define _str(s) #s
55#define str(s) _str(s)
56
Michael Ellerman2fae0d72013-08-06 17:42:36 +100057#endif /* _SELFTESTS_POWERPC_UTILS_H */