1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /******************************************************************************
4 * Copyright © International Business Machines Corp., 2009
7 * Glibc independent futex library for testing kernel functionality.
10 * Darren Hart <dvhart@linux.intel.com>
13 * 2009-Nov-6: Initial version by Darren Hart <dvhart@linux.intel.com>
15 *****************************************************************************/
23 #include <linux/futex.h>
24 #include "kselftest.h"
27 * Define PASS, ERROR, and FAIL strings with and without color escape
28 * sequences, default to no color.
32 #define GREEN '3', '2'
33 #define YELLOW '3', '3'
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, '0', 'm'
40 static const char PASS_COLOR
[] = {BRIGHT_GREEN
, ' ', 'P', 'A', 'S', 'S',
42 static const char ERROR_COLOR
[] = {BRIGHT_YELLOW
, 'E', 'R', 'R', 'O', 'R',
44 static const char FAIL_COLOR
[] = {BRIGHT_RED
, ' ', 'F', 'A', 'I', 'L',
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
;
55 /* Verbosity setting for INFO messages */
60 int _verbose
= VCRITICAL
;
62 /* Functional test return codes */
68 * log_color() - Use colored output for PASS, ERROR, and FAIL strings
69 * @use_color: use color (1) or not (0)
71 void log_color(int use_color
)
85 * log_verbosity() - Set verbosity of test output
86 * @verbose: Enable (1) verbose output or not (0)
88 * Currently setting verbose=1 will enable INFO messages and 0 will disable
89 * them. FAIL and ERROR messages are always displayed.
91 void log_verbosity(int level
)
101 * print_result() - Print standard PASS | ERROR | FAIL results
102 * @ret: the return value to be considered: 0 | RET_ERROR | RET_FAIL
104 * print_result() is primarily intended for functional tests.
106 void print_result(const char *test_name
, int ret
)
110 ksft_test_result_pass("%s\n", test_name
);
114 ksft_test_result_error("%s\n", test_name
);
118 ksft_test_result_fail("%s\n", test_name
);
124 /* log level macros */
125 #define info(message, vargs...) \
127 if (_verbose >= VINFO) \
128 fprintf(stderr, "\t%s: "message, INFO, ##vargs); \
131 #define error(message, err, args...) \
133 if (_verbose >= VCRITICAL) {\
135 fprintf(stderr, "\t%s: %s: "message, \
136 ERROR, strerror(err), ##args); \
138 fprintf(stderr, "\t%s: "message, ERROR, ##args); \
142 #define fail(message, args...) \
144 if (_verbose >= VCRITICAL) \
145 fprintf(stderr, "\t%s: "message, FAIL, ##args); \