Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __LIBPERF_INTERNAL_TESTS_H
0003 #define __LIBPERF_INTERNAL_TESTS_H
0004 
0005 #include <stdio.h>
0006 #include <unistd.h>
0007 
0008 extern int tests_failed;
0009 extern int tests_verbose;
0010 
0011 static inline int get_verbose(char **argv, int argc)
0012 {
0013     int c;
0014     int verbose = 0;
0015 
0016     while ((c = getopt(argc, argv, "v")) != -1) {
0017         switch (c)
0018         {
0019         case 'v':
0020             verbose = 1;
0021             break;
0022         default:
0023             break;
0024         }
0025     }
0026     optind = 1;
0027 
0028     return verbose;
0029 }
0030 
0031 #define __T_START                   \
0032 do {                            \
0033     tests_verbose = get_verbose(argv, argc);    \
0034     fprintf(stdout, "- running %s...", __FILE__);   \
0035     fflush(NULL);                   \
0036     tests_failed = 0;               \
0037 } while (0)
0038 
0039 #define __T_END                             \
0040 do {                                    \
0041     if (tests_failed)                       \
0042         fprintf(stdout, "  FAILED (%d)\n", tests_failed);   \
0043     else                                \
0044         fprintf(stdout, "OK\n");                \
0045 } while (0)
0046 
0047 #define __T(text, cond)                                                          \
0048 do {                                                                             \
0049     if (!(cond)) {                                                           \
0050         fprintf(stderr, "FAILED %s:%d %s\n", __FILE__, __LINE__, text);  \
0051         tests_failed++;                                                  \
0052         return -1;                                                       \
0053     }                                                                        \
0054 } while (0)
0055 
0056 #define __T_VERBOSE(...)                        \
0057 do {                                    \
0058     if (tests_verbose) {                        \
0059         if (tests_verbose == 1) {               \
0060             fputc('\n', stderr);                \
0061             tests_verbose++;                \
0062         }                           \
0063         fprintf(stderr, ##__VA_ARGS__);             \
0064     }                               \
0065 } while (0)
0066 
0067 #endif /* __LIBPERF_INTERNAL_TESTS_H */