[LTP] [PATCH v3 1/3] lib/tests: Add test for testing tst_res() flags

Petr Vorel pvorel@suse.cz
Mon Dec 11 17:18:05 CET 2023


Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 lib/newlib_tests/tst_res_flags.c | 45 ++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 lib/newlib_tests/tst_res_flags.c

diff --git a/lib/newlib_tests/tst_res_flags.c b/lib/newlib_tests/tst_res_flags.c
new file mode 100644
index 000000000..dc8f27e74
--- /dev/null
+++ b/lib/newlib_tests/tst_res_flags.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 Petr Vorel <pvorel@suse.cz>
+ */
+
+/*
+ * Test tst_res() flags.
+ */
+
+#include "tst_test.h"
+
+#define FLAG(x) .flag = x, .str = #x
+static struct tcase {
+	int flag;
+	const char *str;
+} tcases[] = {
+	{FLAG(TPASS)},
+	{FLAG(TFAIL)},
+	{FLAG(TBROK)},
+	{FLAG(TCONF)},
+	{FLAG(TWARN)},
+	{FLAG(TINFO)},
+};
+
+static void do_cleanup(void)
+{
+	tst_brk(TBROK, "TBROK message should be TWARN in cleanup");
+}
+
+static void do_test(unsigned int n)
+{
+	int flag = tcases[n].flag;
+	const char *str = tcases[n].str;
+
+	tst_res(flag, "%s message", str);
+
+	if (flag == TWARN || flag == TINFO)
+		tst_res(TPASS, "%s message is not a result", str);
+}
+
+static struct tst_test test = {
+	.test = do_test,
+	.tcnt = ARRAY_SIZE(tcases),
+	.cleanup = do_cleanup,
+};
-- 
2.43.0



More information about the ltp mailing list