[PATCH 01/15] selftests: kselftest: Create ksft_print_dbg_msg()

André Almeida posted 15 patches 3 months ago
There is a newer version of this series
[PATCH 01/15] selftests: kselftest: Create ksft_print_dbg_msg()
Posted by André Almeida 3 months ago
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>
---
 tools/testing/selftests/kselftest.h         | 13 +++++++++++++
 tools/testing/selftests/kselftest_harness.h | 13 +++++++++----
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
index c3b6d2604b1e486af5a224a11386f75fe0a83495..c1851125de9cfdcdf3b11249572ebfb0751727f6 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -104,6 +104,7 @@ struct ksft_count {
 
 static struct ksft_count ksft_cnt;
 static unsigned int ksft_plan;
+static bool ksft_debug_enabled;
 
 static inline unsigned int ksft_test_num(void)
 {
@@ -175,6 +176,18 @@ static inline __printf(1, 2) void ksft_print_msg(const char *msg, ...)
 	va_end(args);
 }
 
+static inline void ksft_print_dbg_msg(const char *msg, ...)
+{
+	va_list args;
+
+	if (!ksft_debug_enabled)
+		return;
+
+	va_start(args, msg);
+	ksft_print_msg(msg, args);
+	va_end(args);
+}
+
 static inline void ksft_perror(const char *msg)
 {
 	ksft_print_msg("%s: %s (%d)\n", msg, strerror(errno), errno);
diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 2925e47db995d7197ed1f55bd9cc657669df9bd3..ffefd2704ca8f60f329b5d85870253fe26c61b52 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -1091,7 +1091,7 @@ static int test_harness_argv_check(int argc, char **argv)
 {
 	int opt;
 
-	while ((opt = getopt(argc, argv, "hlF:f:V:v:t:T:r:")) != -1) {
+	while ((opt = getopt(argc, argv, "dhlF:f:V:v:t:T:r:")) != -1) {
 		switch (opt) {
 		case 'f':
 		case 'F':
@@ -1104,12 +1104,16 @@ static int test_harness_argv_check(int argc, char **argv)
 		case 'l':
 			test_harness_list_tests();
 			return KSFT_SKIP;
+		case 'd':
+			ksft_debug_enabled = true;
+			break;
 		case 'h':
 		default:
 			fprintf(stderr,
-				"Usage: %s [-h|-l] [-t|-T|-v|-V|-f|-F|-r name]\n"
+				"Usage: %s [-h|-l|-d] [-t|-T|-v|-V|-f|-F|-r name]\n"
 				"\t-h       print help\n"
 				"\t-l       list all tests\n"
+				"\t-d       enable debug prints\n"
 				"\n"
 				"\t-t name  include test\n"
 				"\t-T name  exclude test\n"
@@ -1142,8 +1146,9 @@ static bool test_enabled(int argc, char **argv,
 	int opt;
 
 	optind = 1;
-	while ((opt = getopt(argc, argv, "F:f:V:v:t:T:r:")) != -1) {
-		has_positive |= islower(opt);
+	while ((opt = getopt(argc, argv, "dF:f:V:v:t:T:r:")) != -1) {
+		if (opt != 'd')
+			has_positive |= islower(opt);
 
 		switch (tolower(opt)) {
 		case 't':

-- 
2.49.0

Re: [PATCH 01/15] selftests: kselftest: Create ksft_print_dbg_msg()
Posted by kernel test robot 2 months, 3 weeks ago

Hello,

kernel test robot noticed "kernel-selftests.rseq.make.fail" on:

commit: 58bb4c1e4faa0f315b7eb3f2766052f0c3887981 ("[PATCH 01/15] selftests: kselftest: Create ksft_print_dbg_msg()")
url: https://github.com/intel-lab-lkp/linux/commits/Andr-Almeida/selftests-kselftest-Create-ksft_print_dbg_msg/20250704-231034
patch link: https://lore.kernel.org/all/20250704-tonyk-robust_test_cleanup-v1-1-c0ff4f24c4e1@igalia.com/
patch subject: [PATCH 01/15] selftests: kselftest: Create ksft_print_dbg_msg()

in testcase: kernel-selftests
version: kernel-selftests-x86_64-7ff71e6d9239-1_20250215
with following parameters:

	group: rseq



config: x86_64-rhel-9.4-kselftests
compiler: gcc-12
test machine: 36 threads 1 sockets Intel(R) Core(TM) i9-9980XE CPU @ 3.00GHz (Skylake) with 32G memory

(please refer to attached dmesg/kmsg for entire log/backtrace)


If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <oliver.sang@intel.com>
| Closes: https://lore.kernel.org/oe-lkp/202507150850.fcfc5ecc-lkp@intel.com

KERNEL SELFTESTS: linux_headers_dir is /usr/src/linux-headers-x86_64-rhel-9.4-kselftests-58bb4c1e4faa0f315b7eb3f2766052f0c3887981
2025-07-10 10:39:20 sed -i s/default_timeout=45/default_timeout=300/ kselftest/runner.sh
2025-07-10 10:39:20 make -j36 TARGETS=rseq

....

gcc -O2 -Wall -g -I./ -isystem /usr/src/perf_selftests-x86_64-rhel-9.4-kselftests-58bb4c1e4faa0f315b7eb3f2766052f0c3887981/usr/include -L/usr/src/perf_selftests-x86_64-rhel-9.4-kselftests-58bb4c1e4faa0f315b7eb3f2766052f0c3887981/tools/testing/selftests/rseq -Wl,-rpath=./  -I/usr/src/perf_selftests-x86_64-rhel-9.4-kselftests-58bb4c1e4faa0f315b7eb3f2766052f0c3887981/tools/testing/selftests/../../../tools/include -D_GNU_SOURCE=  -DBUILDOPT_RSEQ_PERCPU_MM_CID -DRSEQ_COMPARE_TWICE param_test.c -lpthread -ldl -lrseq -o /usr/src/perf_selftests-x86_64-rhel-9.4-kselftests-58bb4c1e4faa0f315b7eb3f2766052f0c3887981/tools/testing/selftests/rseq/param_test_mm_cid_compare_twice
gcc -O2 -Wall -g -I./ -isystem /usr/src/perf_selftests-x86_64-rhel-9.4-kselftests-58bb4c1e4faa0f315b7eb3f2766052f0c3887981/usr/include -L/usr/src/perf_selftests-x86_64-rhel-9.4-kselftests-58bb4c1e4faa0f315b7eb3f2766052f0c3887981/tools/testing/selftests/rseq -Wl,-rpath=./  -I/usr/src/perf_selftests-x86_64-rhel-9.4-kselftests-58bb4c1e4faa0f315b7eb3f2766052f0c3887981/tools/testing/selftests/../../../tools/include -D_GNU_SOURCE=  syscall_errors_test.c -lpthread -ldl -lrseq -o /usr/src/perf_selftests-x86_64-rhel-9.4-kselftests-58bb4c1e4faa0f315b7eb3f2766052f0c3887981/tools/testing/selftests/rseq/syscall_errors_test
In file included from basic_percpu_ops_test.c:12:
../kselftest.h:107:8: error: unknown type name ‘bool’
  107 | static bool ksft_debug_enabled;
      |        ^~~~
In file included from basic_percpu_ops_test.c:12:
../kselftest.h:107:8: error: unknown type name ‘bool’
  107 | static bool ksft_debug_enabled;
      |        ^~~~
make[1]: *** [Makefile:34: /usr/src/perf_selftests-x86_64-rhel-9.4-kselftests-58bb4c1e4faa0f315b7eb3f2766052f0c3887981/tools/testing/selftests/rseq/basic_percpu_ops_test] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: *** [Makefile:37: /usr/src/perf_selftests-x86_64-rhel-9.4-kselftests-58bb4c1e4faa0f315b7eb3f2766052f0c3887981/tools/testing/selftests/rseq/basic_percpu_ops_mm_cid_test] Error 1
make[1]: Leaving directory '/usr/src/perf_selftests-x86_64-rhel-9.4-kselftests-58bb4c1e4faa0f315b7eb3f2766052f0c3887981/tools/testing/selftests/rseq'
make: *** [Makefile:207: all] Error 2



The kernel config and materials to reproduce are available at:
https://download.01.org/0day-ci/archive/20250715/202507150850.fcfc5ecc-lkp@intel.com



-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

Re: [PATCH 01/15] selftests: kselftest: Create ksft_print_dbg_msg()
Posted by kernel test robot 3 months ago
Hi André,

kernel test robot noticed the following build errors:

[auto build test ERROR on a24cc6ce1933eade12aa2b9859de0fcd2dac2c06]

url:    https://github.com/intel-lab-lkp/linux/commits/Andr-Almeida/selftests-kselftest-Create-ksft_print_dbg_msg/20250704-231034
base:   a24cc6ce1933eade12aa2b9859de0fcd2dac2c06
patch link:    https://lore.kernel.org/r/20250704-tonyk-robust_test_cleanup-v1-1-c0ff4f24c4e1%40igalia.com
patch subject: [PATCH 01/15] selftests: kselftest: Create ksft_print_dbg_msg()
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20250706/202507061039.0ZKQCW5y-lkp@intel.com/config)
compiler: clang version 20.1.7 (https://github.com/llvm/llvm-project 6146a88f60492b520a36f8f8f3231e15f3cc6082)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250706/202507061039.0ZKQCW5y-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202507061039.0ZKQCW5y-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from samples/vfs/test-list-all-mounts.c:11:
   In file included from samples/vfs/../../tools/testing/selftests/pidfd/pidfd.h:19:
>> samples/vfs/../../tools/testing/selftests/pidfd/../kselftest.h:107:8: error: unknown type name 'bool'
     107 | static bool ksft_debug_enabled;
         |        ^
   1 error generated.


vim +/bool +107 samples/vfs/../../tools/testing/selftests/pidfd/../kselftest.h

   104	
   105	static struct ksft_count ksft_cnt;
   106	static unsigned int ksft_plan;
 > 107	static bool ksft_debug_enabled;
   108	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki