Introduce a shared header `utils.h` providing basic test harness macros and timeout handling for PowerPC selftests. This consolidates common functionality used across RTAS, NVRAM, FADump, and other selftests.
The header defines: - SKIP_IF() macro for conditional skip - FAIL_IF() macro for unconditional failure - FAIL_IF_MSG() macro for failure with message - test_harness_set_timeout() helper for alarm-based timeouts This reduces duplication and ensures consistent behavior across selftests. Signed-off-by: Shirisha G <[email protected]> --- tools/testing/selftests/powerpc/rtas/utils.h | 39 ++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tools/testing/selftests/powerpc/rtas/utils.h diff --git a/tools/testing/selftests/powerpc/rtas/utils.h b/tools/testing/selftests/powerpc/rtas/utils.h new file mode 100644 index 000000000000..58eef7642a3f --- /dev/null +++ b/tools/testing/selftests/powerpc/rtas/utils.h @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-only +#ifndef _RTAS_TEST_UTILS_H +#define _RTAS_TEST_UTILS_H + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +/* Test macros */ +#define SKIP_IF(x) \ + do { \ + if (x) { \ + fprintf(stderr, "SKIP: %s\n", #x); \ + exit(4); \ + } \ + } while (0) + +#define FAIL_IF(x) \ + do { \ + if (x) { \ + fprintf(stderr, "FAIL: %s\n", #x); \ + exit(1); \ + } \ + } while (0) + +#define FAIL_IF_MSG(x, fmt, ...) \ + do { \ + if (x) { \ + fprintf(stderr, "FAIL: " fmt "\n", ##__VA_ARGS__); \ + exit(1); \ + } \ + } while (0) + +static inline void test_harness_set_timeout(int seconds) +{ + alarm(seconds); +} + +#endif /* _RTAS_TEST_UTILS_H */ -- 2.43.5
