Commit f2662ec2 authored by André Almeida's avatar André Almeida Committed by Thomas Gleixner
Browse files

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: default avatarAndré Almeida <andrealmeid@igalia.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 6b54082c
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <sys/utsname.h>
@@ -104,6 +105,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 +177,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);
+9 −4
Original line number Diff line number Diff line
@@ -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,7 +1146,8 @@ 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) {
	while ((opt = getopt(argc, argv, "dF:f:V:v:t:T:r:")) != -1) {
		if (opt != 'd')
			has_positive |= islower(opt);

		switch (tolower(opt)) {