]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - tools/testing/selftests/futex/include/logging.h
1 /******************************************************************************
3 * Copyright © International Business Machines Corp., 2009
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
11 * Glibc independent futex library for testing kernel functionality.
14 * Darren Hart <dvhart@linux.intel.com>
17 * 2009-Nov-6: Initial version by Darren Hart <dvhart@linux.intel.com>
19 *****************************************************************************/
26 #include <linux/futex.h>
29 * Define PASS, ERROR, and FAIL strings with and without color escape
30 * sequences, default to no color.
34 #define GREEN '3', '2'
35 #define YELLOW '3', '3'
38 #define BRIGHT_GREEN ESC, BRIGHT, ';', GREEN, ESCEND
39 #define BRIGHT_YELLOW ESC, BRIGHT, ';', YELLOW, ESCEND
40 #define BRIGHT_RED ESC, BRIGHT, ';', RED, ESCEND
41 #define RESET_COLOR ESC, '0', 'm'
42 static const char PASS_COLOR
[] = {BRIGHT_GREEN
, ' ', 'P', 'A', 'S', 'S',
44 static const char ERROR_COLOR
[] = {BRIGHT_YELLOW
, 'E', 'R', 'R', 'O', 'R',
46 static const char FAIL_COLOR
[] = {BRIGHT_RED
, ' ', 'F', 'A', 'I', 'L',
48 static const char INFO_NORMAL
[] = " INFO";
49 static const char PASS_NORMAL
[] = " PASS";
50 static const char ERROR_NORMAL
[] = "ERROR";
51 static const char FAIL_NORMAL
[] = " FAIL";
52 const char *INFO
= INFO_NORMAL
;
53 const char *PASS
= PASS_NORMAL
;
54 const char *ERROR
= ERROR_NORMAL
;
55 const char *FAIL
= FAIL_NORMAL
;
57 /* Verbosity setting for INFO messages */
62 int _verbose
= VCRITICAL
;
64 /* Functional test return codes */
70 * log_color() - Use colored output for PASS, ERROR, and FAIL strings
71 * @use_color: use color (1) or not (0)
73 void log_color(int use_color
)
87 * log_verbosity() - Set verbosity of test output
88 * @verbose: Enable (1) verbose output or not (0)
90 * Currently setting verbose=1 will enable INFO messages and 0 will disable
91 * them. FAIL and ERROR messages are always displayed.
93 void log_verbosity(int level
)
103 * print_result() - Print standard PASS | ERROR | FAIL results
104 * @ret: the return value to be considered: 0 | RET_ERROR | RET_FAIL
106 * print_result() is primarily intended for functional tests.
108 void print_result(int ret
)
110 const char *result
= "Unknown return code";
123 printf("Result: %s\n", result
);
126 /* log level macros */
127 #define info(message, vargs...) \
129 if (_verbose >= VINFO) \
130 fprintf(stderr, "\t%s: "message, INFO, ##vargs); \
133 #define error(message, err, args...) \
135 if (_verbose >= VCRITICAL) {\
137 fprintf(stderr, "\t%s: %s: "message, \
138 ERROR, strerror(err), ##args); \
140 fprintf(stderr, "\t%s: "message, ERROR, ##args); \
144 #define fail(message, args...) \
146 if (_verbose >= VCRITICAL) \
147 fprintf(stderr, "\t%s: "message, FAIL, ##args); \