Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: kselftest: Create ksft_print_dbg_msg()

Create ksft_print_dbg_msg() so testers can enable extra debug messages
when running a test with the flag -d.

Signed-off-by: André Almeida <andrealmeid@igalia.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

authored by

André Almeida and committed by
Thomas Gleixner
f2662ec2 6b54082c

+23 -4
+14
tools/testing/selftests/kselftest.h
··· 54 54 #include <stdlib.h> 55 55 #include <unistd.h> 56 56 #include <stdarg.h> 57 + #include <stdbool.h> 57 58 #include <string.h> 58 59 #include <stdio.h> 59 60 #include <sys/utsname.h> ··· 105 104 106 105 static struct ksft_count ksft_cnt; 107 106 static unsigned int ksft_plan; 107 + static bool ksft_debug_enabled; 108 108 109 109 static inline unsigned int ksft_test_num(void) 110 110 { ··· 174 172 printf("# "); 175 173 errno = saved_errno; 176 174 vprintf(msg, args); 175 + va_end(args); 176 + } 177 + 178 + static inline void ksft_print_dbg_msg(const char *msg, ...) 179 + { 180 + va_list args; 181 + 182 + if (!ksft_debug_enabled) 183 + return; 184 + 185 + va_start(args, msg); 186 + ksft_print_msg(msg, args); 177 187 va_end(args); 178 188 } 179 189
+9 -4
tools/testing/selftests/kselftest_harness.h
··· 1091 1091 { 1092 1092 int opt; 1093 1093 1094 - while ((opt = getopt(argc, argv, "hlF:f:V:v:t:T:r:")) != -1) { 1094 + while ((opt = getopt(argc, argv, "dhlF:f:V:v:t:T:r:")) != -1) { 1095 1095 switch (opt) { 1096 1096 case 'f': 1097 1097 case 'F': ··· 1104 1104 case 'l': 1105 1105 test_harness_list_tests(); 1106 1106 return KSFT_SKIP; 1107 + case 'd': 1108 + ksft_debug_enabled = true; 1109 + break; 1107 1110 case 'h': 1108 1111 default: 1109 1112 fprintf(stderr, 1110 - "Usage: %s [-h|-l] [-t|-T|-v|-V|-f|-F|-r name]\n" 1113 + "Usage: %s [-h|-l|-d] [-t|-T|-v|-V|-f|-F|-r name]\n" 1111 1114 "\t-h print help\n" 1112 1115 "\t-l list all tests\n" 1116 + "\t-d enable debug prints\n" 1113 1117 "\n" 1114 1118 "\t-t name include test\n" 1115 1119 "\t-T name exclude test\n" ··· 1146 1142 int opt; 1147 1143 1148 1144 optind = 1; 1149 - while ((opt = getopt(argc, argv, "F:f:V:v:t:T:r:")) != -1) { 1150 - has_positive |= islower(opt); 1145 + while ((opt = getopt(argc, argv, "dF:f:V:v:t:T:r:")) != -1) { 1146 + if (opt != 'd') 1147 + has_positive |= islower(opt); 1151 1148 1152 1149 switch (tolower(opt)) { 1153 1150 case 't':