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>
27 #include "kselftest.h"
30 * Define PASS, ERROR, and FAIL strings with and without color escape
31 * sequences, default to no color.
35 #define GREEN '3', '2'
36 #define YELLOW '3', '3'
39 #define BRIGHT_GREEN ESC, BRIGHT, ';', GREEN, ESCEND
40 #define BRIGHT_YELLOW ESC, BRIGHT, ';', YELLOW, ESCEND
41 #define BRIGHT_RED ESC, BRIGHT, ';', RED, ESCEND
42 #define RESET_COLOR ESC, '0', 'm'
43 static const char PASS_COLOR
[] = {BRIGHT_GREEN
, ' ', 'P', 'A', 'S', 'S',
45 static const char ERROR_COLOR
[] = {BRIGHT_YELLOW
, 'E', 'R', 'R', 'O', 'R',
47 static const char FAIL_COLOR
[] = {BRIGHT_RED
, ' ', 'F', 'A', 'I', 'L',
49 static const char INFO_NORMAL
[] = " INFO";
50 static const char PASS_NORMAL
[] = " PASS";
51 static const char ERROR_NORMAL
[] = "ERROR";
52 static const char FAIL_NORMAL
[] = " FAIL";
53 const char *INFO
= INFO_NORMAL
;
54 const char *PASS
= PASS_NORMAL
;
55 const char *ERROR
= ERROR_NORMAL
;
56 const char *FAIL
= FAIL_NORMAL
;
58 /* Verbosity setting for INFO messages */
63 int _verbose
= VCRITICAL
;
65 /* Functional test return codes */
71 * log_color() - Use colored output for PASS, ERROR, and FAIL strings
72 * @use_color: use color (1) or not (0)
74 void log_color(int use_color
)
88 * log_verbosity() - Set verbosity of test output
89 * @verbose: Enable (1) verbose output or not (0)
91 * Currently setting verbose=1 will enable INFO messages and 0 will disable
92 * them. FAIL and ERROR messages are always displayed.
94 void log_verbosity(int level
)
104 * print_result() - Print standard PASS | ERROR | FAIL results
105 * @ret: the return value to be considered: 0 | RET_ERROR | RET_FAIL
107 * print_result() is primarily intended for functional tests.
109 void print_result(int ret
)
111 const char *result
= "Unknown return code";
126 printf("Result: %s\n", result
);
129 /* log level macros */
130 #define info(message, vargs...) \
132 if (_verbose >= VINFO) \
133 fprintf(stderr, "\t%s: "message, INFO, ##vargs); \
136 #define error(message, err, args...) \
138 if (_verbose >= VCRITICAL) {\
140 fprintf(stderr, "\t%s: %s: "message, \
141 ERROR, strerror(err), ##args); \
143 fprintf(stderr, "\t%s: "message, ERROR, ##args); \
147 #define fail(message, args...) \
149 if (_verbose >= VCRITICAL) \
150 fprintf(stderr, "\t%s: "message, FAIL, ##args); \