~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/futex/include/logging.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0-or-later */
  2 /******************************************************************************
  3  *
  4  *   Copyright © International Business Machines  Corp., 2009
  5  *
  6  * DESCRIPTION
  7  *      Glibc independent futex library for testing kernel functionality.
  8  *
  9  * AUTHOR
 10  *      Darren Hart <dvhart@linux.intel.com>
 11  *
 12  * HISTORY
 13  *      2009-Nov-6: Initial version by Darren Hart <dvhart@linux.intel.com>
 14  *
 15  *****************************************************************************/
 16 
 17 #ifndef _LOGGING_H
 18 #define _LOGGING_H
 19 
 20 #include <stdio.h>
 21 #include <string.h>
 22 #include <unistd.h>
 23 #include <linux/futex.h>
 24 #include "kselftest.h"
 25 
 26 /*
 27  * Define PASS, ERROR, and FAIL strings with and without color escape
 28  * sequences, default to no color.
 29  */
 30 #define ESC 0x1B, '['
 31 #define BRIGHT '1'
 32 #define GREEN '3', '2'
 33 #define YELLOW '3', '3'
 34 #define RED '3', '1'
 35 #define ESCEND 'm'
 36 #define BRIGHT_GREEN ESC, BRIGHT, ';', GREEN, ESCEND
 37 #define BRIGHT_YELLOW ESC, BRIGHT, ';', YELLOW, ESCEND
 38 #define BRIGHT_RED ESC, BRIGHT, ';', RED, ESCEND
 39 #define RESET_COLOR ESC, '', 'm'
 40 static const char PASS_COLOR[] = {BRIGHT_GREEN, ' ', 'P', 'A', 'S', 'S',
 41                                   RESET_COLOR, 0};
 42 static const char ERROR_COLOR[] = {BRIGHT_YELLOW, 'E', 'R', 'R', 'O', 'R',
 43                                    RESET_COLOR, 0};
 44 static const char FAIL_COLOR[] = {BRIGHT_RED, ' ', 'F', 'A', 'I', 'L',
 45                                   RESET_COLOR, 0};
 46 static const char INFO_NORMAL[] = " INFO";
 47 static const char PASS_NORMAL[] = " PASS";
 48 static const char ERROR_NORMAL[] = "ERROR";
 49 static const char FAIL_NORMAL[] = " FAIL";
 50 const char *INFO = INFO_NORMAL;
 51 const char *PASS = PASS_NORMAL;
 52 const char *ERROR = ERROR_NORMAL;
 53 const char *FAIL = FAIL_NORMAL;
 54 
 55 /* Verbosity setting for INFO messages */
 56 #define VQUIET    0
 57 #define VCRITICAL 1
 58 #define VINFO     2
 59 #define VMAX      VINFO
 60 int _verbose = VCRITICAL;
 61 
 62 /* Functional test return codes */
 63 #define RET_PASS   0
 64 #define RET_ERROR -1
 65 #define RET_FAIL  -2
 66 
 67 /**
 68  * log_color() - Use colored output for PASS, ERROR, and FAIL strings
 69  * @use_color:  use color (1) or not (0)
 70  */
 71 void log_color(int use_color)
 72 {
 73         if (use_color) {
 74                 PASS = PASS_COLOR;
 75                 ERROR = ERROR_COLOR;
 76                 FAIL = FAIL_COLOR;
 77         } else {
 78                 PASS = PASS_NORMAL;
 79                 ERROR = ERROR_NORMAL;
 80                 FAIL = FAIL_NORMAL;
 81         }
 82 }
 83 
 84 /**
 85  * log_verbosity() - Set verbosity of test output
 86  * @verbose:    Enable (1) verbose output or not (0)
 87  *
 88  * Currently setting verbose=1 will enable INFO messages and 0 will disable
 89  * them. FAIL and ERROR messages are always displayed.
 90  */
 91 void log_verbosity(int level)
 92 {
 93         if (level > VMAX)
 94                 level = VMAX;
 95         else if (level < 0)
 96                 level = 0;
 97         _verbose = level;
 98 }
 99 
100 /**
101  * print_result() - Print standard PASS | ERROR | FAIL results
102  * @ret:        the return value to be considered: 0 | RET_ERROR | RET_FAIL
103  *
104  * print_result() is primarily intended for functional tests.
105  */
106 void print_result(const char *test_name, int ret)
107 {
108         switch (ret) {
109         case RET_PASS:
110                 ksft_test_result_pass("%s\n", test_name);
111                 ksft_print_cnts();
112                 return;
113         case RET_ERROR:
114                 ksft_test_result_error("%s\n", test_name);
115                 ksft_print_cnts();
116                 return;
117         case RET_FAIL:
118                 ksft_test_result_fail("%s\n", test_name);
119                 ksft_print_cnts();
120                 return;
121         }
122 }
123 
124 /* log level macros */
125 #define info(message, vargs...) \
126 do { \
127         if (_verbose >= VINFO) \
128                 fprintf(stderr, "\t%s: "message, INFO, ##vargs); \
129 } while (0)
130 
131 #define error(message, err, args...) \
132 do { \
133         if (_verbose >= VCRITICAL) {\
134                 if (err) \
135                         fprintf(stderr, "\t%s: %s: "message, \
136                                 ERROR, strerror(err), ##args); \
137                 else \
138                         fprintf(stderr, "\t%s: "message, ERROR, ##args); \
139         } \
140 } while (0)
141 
142 #define fail(message, args...) \
143 do { \
144         if (_verbose >= VCRITICAL) \
145                 fprintf(stderr, "\t%s: "message, FAIL, ##args); \
146 } while (0)
147 
148 #endif
149 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php