[LTP] [PATCH 1/2] lib: Add TINFO_WARN

Petr Vorel pvorel@suse.cz
Tue May 28 14:05:53 CEST 2024


When replaced tst_res(TINFO, "WARNING: ...") with tst_res(TINFO_WARN,
"..."), then:

- output message is magenta (the same as for TWARN => more visible),
- "WARNING" is printed by the library (unification),

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 include/tst_res_flags.h          |  6 +++++-
 include/tst_test.h               |  2 +-
 lib/newlib_tests/tst_res_flags.c |  1 +
 lib/tst_ansi_color.c             |  1 +
 lib/tst_res.c                    | 12 ++++++++----
 lib/tst_test.c                   |  3 +++
 6 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/include/tst_res_flags.h b/include/tst_res_flags.h
index 806940e0d..bb2f38c93 100644
--- a/include/tst_res_flags.h
+++ b/include/tst_res_flags.h
@@ -22,6 +22,9 @@
  * @TINFO: Prints an additional information, it does not change the test result
  *         counters but unlike TDEBUG the message is always displayed.
  *
+ * @TINFO_WARN: Reports a single warning, but it does not change the test result
+ *              counters like TINFO.
+ *
  * @TCONF: Reports unsupported configuration. When tests produce this result at
  *         least a subset of test was skipped, because it couldn't run. The
  *         usual reasons are, missing kernel modules or CONFIG options.
@@ -55,12 +58,13 @@ enum tst_res_flags {
 	TDEBUG = 8,
 	TINFO = 16,
 	TCONF = 32,
+	TINFO_WARN = 64,
 	TERRNO = 0x100,
 	TTERRNO = 0x200,
 	TRERRNO	= 0x400,
 };
 
 #define TTYPE_RESULT(ttype)	((ttype) & TTYPE_MASK)
-#define TTYPE_MASK 0x3f
+#define TTYPE_MASK 0x7f
 
 #endif /* TST_RES_FLAGS_H */
diff --git a/include/tst_test.h b/include/tst_test.h
index 8dc20d110..6c1f7bce1 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -69,7 +69,7 @@ void tst_res_(const char *file, const int lineno, int ttype,
 	({									\
 		TST_RES_SUPPORTS_TCONF_TDEBUG_TFAIL_TINFO_TPASS_TWARN(\
 			!((TTYPE_RESULT(ttype) ?: TCONF) & \
-			(TCONF | TDEBUG | TFAIL | TINFO | TPASS | TWARN)));				\
+			(TCONF | TDEBUG | TFAIL | TINFO | TPASS | TWARN | TINFO_WARN)));	\
 		tst_res_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__);\
 	})
 
diff --git a/lib/newlib_tests/tst_res_flags.c b/lib/newlib_tests/tst_res_flags.c
index a14f0df2c..7d3bc3785 100644
--- a/lib/newlib_tests/tst_res_flags.c
+++ b/lib/newlib_tests/tst_res_flags.c
@@ -20,6 +20,7 @@ static struct tcase {
 	{FLAG(TBROK)},
 	{FLAG(TCONF)},
 	{FLAG(TWARN)},
+	{FLAG(TINFO_WARN)},
 	{FLAG(TINFO)},
 	{FLAG(TDEBUG), " (printed only with -D or LTP_ENABLE_DEBUG=1)"},
 };
diff --git a/lib/tst_ansi_color.c b/lib/tst_ansi_color.c
index 98041c0af..7d1dca516 100644
--- a/lib/tst_ansi_color.c
+++ b/lib/tst_ansi_color.c
@@ -26,6 +26,7 @@ char* tst_ttype2color(int ttype)
 		return ANSI_COLOR_YELLOW;
 	break;
 	case TWARN:
+	case TINFO_WARN:
 		return ANSI_COLOR_MAGENTA;
 	break;
 	case TINFO:
diff --git a/lib/tst_res.c b/lib/tst_res.c
index 7c66d2f6c..d28c0b4f4 100644
--- a/lib/tst_res.c
+++ b/lib/tst_res.c
@@ -174,13 +174,16 @@ static void tst_res__(const char *file, const int lineno, int ttype,
 	int len = 0;
 	int ttype_result = TTYPE_RESULT(ttype);
 
-	if (ttype_result == TDEBUG) {
-		printf("%s: %i: TDEBUG is not supported\n", __func__, __LINE__);
+	if (ttype_result == TDEBUG || ttype_result == TINFO_WARN) {
+		printf("%s: %i: %s is not supported\n", __func__, __LINE__,
+		       strttype(ttype));
 		abort();
 	}
 
-	if (file && (ttype_result != TPASS && ttype_result != TINFO))
+	if (file && (ttype_result != TPASS && ttype_result != TINFO
+		     && ttype_result != TINFO_WARN)) {
 		len = sprintf(tmesg, "%s:%d: ", file, lineno);
+	}
 	EXPAND_VAR_ARGS(tmesg + len, arg_fmt, USERMESG - len);
 
 	/*
@@ -198,7 +201,8 @@ static void tst_res__(const char *file, const int lineno, int ttype,
 	 * Set the test case number and print the results, depending on the
 	 * display type.
 	 */
-	if (ttype_result == TWARN || ttype_result == TINFO) {
+	if (ttype_result == TWARN || ttype_result == TINFO ||
+	    ttype_result == TINFO_WARN) {
 		tst_print(TCID, 0, ttype, tmesg);
 	} else {
 		if (tst_count < 0)
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 8c212c983..ef5148c0f 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -225,6 +225,9 @@ static void print_result(const char *file, const int lineno, int ttype,
 	case TINFO:
 		res = "TINFO";
 	break;
+	case TINFO_WARN:
+		res = "TINFO WARNING";
+	break;
 	case TDEBUG:
 		res = "TDEBUG";
 	break;
-- 
2.43.0



More information about the ltp mailing list