Path: blob/master/tools/lib/perf/include/internal/tests.h
26302 views
/* SPDX-License-Identifier: GPL-2.0 */1#ifndef __LIBPERF_INTERNAL_TESTS_H2#define __LIBPERF_INTERNAL_TESTS_H34#include <stdio.h>5#include <unistd.h>67extern int tests_failed;8extern int tests_verbose;910static inline int get_verbose(char **argv, int argc)11{12int c;13int verbose = 0;1415while ((c = getopt(argc, argv, "v")) != -1) {16switch (c)17{18case 'v':19verbose = 1;20break;21default:22break;23}24}25optind = 1;2627return verbose;28}2930#define __T_START \31do { \32tests_verbose = get_verbose(argv, argc); \33fprintf(stdout, "- running %s...", __FILE__); \34fflush(NULL); \35tests_failed = 0; \36} while (0)3738#define __T_END \39do { \40if (tests_failed) \41fprintf(stdout, " FAILED (%d)\n", tests_failed); \42else \43fprintf(stdout, "OK\n"); \44} while (0)4546#define __T(text, cond) \47do { \48if (!(cond)) { \49fprintf(stderr, "FAILED %s:%d %s\n", __FILE__, __LINE__, text); \50tests_failed++; \51return -1; \52} \53} while (0)5455#define __T_VERBOSE(...) \56do { \57if (tests_verbose) { \58if (tests_verbose == 1) { \59fputc('\n', stderr); \60tests_verbose++; \61} \62fprintf(stderr, ##__VA_ARGS__); \63} \64} while (0)6566#endif /* __LIBPERF_INTERNAL_TESTS_H */676869