[LTP] [PATCH v2 5/6] lib/tst_res_.c: Add TBROK handler + more verbose errors

Cyril Hrubis chrubis@suse.cz
Mon Jan 6 14:26:06 CET 2025


We use the tst_res_ helper for tst_brk_ as well so we need to be able to
handle TBROK type as well.

Note that we pass TBROK to the tst_res() here deliberately here because
we want to return back to the shell library, which is the process that
reports the TBROK to the test library by doing 'exit 2'. This works
because we pass the value by a variable as compiler cannot evaluate it's
value at a compile time.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/tst_res_.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/testcases/lib/tst_res_.c b/testcases/lib/tst_res_.c
index a43920f36..fd9b8e841 100644
--- a/testcases/lib/tst_res_.c
+++ b/testcases/lib/tst_res_.c
@@ -8,28 +8,34 @@
 
 static void print_help(void)
 {
-	printf("Usage: tst_res_ filename lineno [TPASS|TFAIL|TCONF|TINFO|TDEBUG] 'A short description'\n");
+	printf("Usage: tst_{res,brk} filename lineno [TPASS|TBROK|TFAIL|TCONF|TINFO|TDEBUG] 'A short description'\n");
 }
 
 int main(int argc, char *argv[])
 {
 	int type, i;
 
-	if (argc < 5)
+	if (argc < 5) {
+		printf("argc = %i expected 5\n", argc);
 		goto help;
+	}
 
-	if (!strcmp(argv[3], "TPASS"))
+	if (!strcmp(argv[3], "TPASS")) {
 		type = TPASS;
-	else if (!strcmp(argv[3], "TFAIL"))
+	} else if (!strcmp(argv[3], "TFAIL")) {
 		type = TFAIL;
-	else if (!strcmp(argv[3], "TCONF"))
+	} else if (!strcmp(argv[3], "TCONF")) {
 		type = TCONF;
-	else if (!strcmp(argv[3], "TINFO"))
+	} else if (!strcmp(argv[3], "TINFO")) {
 		type = TINFO;
-	else if (!strcmp(argv[3], "TDEBUG"))
+	} else if (!strcmp(argv[3], "TDEBUG")) {
 		type = TDEBUG;
-	else
+	} else if (!strcmp(argv[3], "TBROK")) {
+		type = TBROK;
+	} else {
+		printf("Wrong type '%s'\n", argv[3]);
 		goto help;
+	}
 
 	size_t len = 0;
 
-- 
2.45.2



More information about the ltp mailing list