Skip to content

Commit

Permalink
selftests/powerpc: Add more utility macros
Browse files Browse the repository at this point in the history
Adds _MSG assertion variants to provide more context behind why a
failure occurred. Also include unistd.h for _exit() and stdio.h for
fprintf(), and move ARRAY_SIZE macro to utils.h.

The _MSG variants and ARRAY_SIZE will be used by the following
DEXCR selftests.

Signed-off-by: Benjamin Gray <[email protected]>
Reviewed-by: Russell Currey <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
Link: https://msgid.link/[email protected]
  • Loading branch information
BenjaminGrayNp1 authored and mpe committed Jun 19, 2023
1 parent 65d6c88 commit b9125c9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
27 changes: 26 additions & 1 deletion tools/testing/selftests/powerpc/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
#define __cacheline_aligned __attribute__((aligned(128)))

#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <linux/auxvec.h>
#include <linux/perf_event.h>
#include <asm/cputable.h>
#include "reg.h"
#include <unistd.h>

#ifndef ARRAY_SIZE
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif

/* Avoid headaches with PRI?64 - just use %ll? always */
typedef unsigned long long u64;
Expand Down Expand Up @@ -67,7 +73,6 @@ struct perf_event_read {
};

#if !defined(__GLIBC_PREREQ) || !__GLIBC_PREREQ(2, 30)
#include <unistd.h>
#include <sys/syscall.h>

static inline pid_t gettid(void)
Expand Down Expand Up @@ -116,6 +121,16 @@ do { \
} \
} while (0)

#define FAIL_IF_MSG(x, msg) \
do { \
if ((x)) { \
fprintf(stderr, \
"[FAIL] Test FAILED on line %d: %s\n", \
__LINE__, msg); \
return 1; \
} \
} while (0)

#define FAIL_IF_EXIT(x) \
do { \
if ((x)) { \
Expand All @@ -125,6 +140,16 @@ do { \
} \
} while (0)

#define FAIL_IF_EXIT_MSG(x, msg) \
do { \
if ((x)) { \
fprintf(stderr, \
"[FAIL] Test FAILED on line %d: %s\n", \
__LINE__, msg); \
_exit(1); \
} \
} while (0)

/* The test harness uses this, yes it's gross */
#define MAGIC_SKIP_RETURN_VALUE 99

Expand Down
2 changes: 0 additions & 2 deletions tools/testing/selftests/powerpc/pmu/sampling_tests/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#define MMCR1_RSQ 0x200000000000ULL /* radix scope qual field */
#define BHRB_DISABLE 0x2000000000ULL /* MMCRA BHRB DISABLE bit */

#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

extern int ev_mask_pmcxsel, ev_shift_pmcxsel;
extern int ev_mask_marked, ev_shift_marked;
extern int ev_mask_comb, ev_shift_comb;
Expand Down

0 comments on commit b9125c9

Please sign in to comment.