[LTP] [PATCH v4 01/10] lib/tests: Add test for testing tst_res() flags

Petr Vorel pvorel@suse.cz
Thu Dec 14 16:19:45 CET 2023


Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 lib/newlib_tests/shell/tst_res_flags.sh | 24 +++++++++++++++
 lib/newlib_tests/tst_res_flags.c        | 41 +++++++++++++++++++++++++
 2 files changed, 65 insertions(+)
 create mode 100755 lib/newlib_tests/shell/tst_res_flags.sh
 create mode 100644 lib/newlib_tests/tst_res_flags.c

diff --git a/lib/newlib_tests/shell/tst_res_flags.sh b/lib/newlib_tests/shell/tst_res_flags.sh
new file mode 100755
index 000000000..bca3d26c0
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_res_flags.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2023 Petr Vorel <pvorel@suse.cz>
+
+TST_TESTFUNC=test
+TST_CLEANUP=cleanup
+
+test()
+{
+	tst_res TPASS "TPASS message"
+	tst_res TFAIL "TFAIL message"
+	tst_res TBROK "TBROK message"
+	tst_res TCONF "TCONF message"
+	tst_res TWARN "TWARN message"
+	tst_res TINFO "TINFO message"
+}
+
+cleanup()
+{
+	tst_brk TBROK "TBROK message should be TWARN in cleanup"
+}
+
+. tst_test.sh
+tst_run
diff --git a/lib/newlib_tests/tst_res_flags.c b/lib/newlib_tests/tst_res_flags.c
new file mode 100644
index 000000000..85eee09a6
--- /dev/null
+++ b/lib/newlib_tests/tst_res_flags.c
@@ -0,0 +1,41 @@
+// 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(void)
+{
+	size_t i;
+
+	for (i = 0; i < ARRAY_SIZE(tcases); i++)
+		tst_res(tcases[i].flag, "%s message", tcases[i].str);
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.cleanup = do_cleanup,
+};
-- 
2.43.0



More information about the ltp mailing list