[LTP] [PATCH 5/8] shell: Add tst_clear_device

Petr Vorel pvorel@suse.cz
Thu May 12 21:45:54 CEST 2022


Binary required for shell $TST_ALL_FILESYSTEMS implementation
(C .all_filesystems uses it).

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/.gitignore         |  1 +
 testcases/lib/Makefile           |  2 +-
 testcases/lib/tst_clear_device.c | 47 ++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
 create mode 100644 testcases/lib/tst_clear_device.c

diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
index c0d4dc851..579f84250 100644
--- a/testcases/lib/.gitignore
+++ b/testcases/lib/.gitignore
@@ -1,6 +1,7 @@
 /tst_check_drivers
 /tst_check_kconfigs
 /tst_checkpoint
+/tst_clear_device
 /tst_device
 /tst_getconf
 /tst_get_free_pids
diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
index f2de0c832..d5a8b08ac 100644
--- a/testcases/lib/Makefile
+++ b/testcases/lib/Makefile
@@ -12,6 +12,6 @@ MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
 			   tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\
 			   tst_getconf tst_supported_fs tst_check_drivers tst_get_unused_port\
 			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill\
-			   tst_check_kconfigs
+			   tst_check_kconfigs tst_clear_device
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/lib/tst_clear_device.c b/testcases/lib/tst_clear_device.c
new file mode 100644
index 000000000..4111c7248
--- /dev/null
+++ b/testcases/lib/tst_clear_device.c
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#include <stdio.h>
+#include <sys/stat.h>
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "old/old_device.h"
+
+extern struct tst_test *tst_test;
+
+static struct tst_test test = {
+};
+
+static void print_help(void)
+{
+	fprintf(stderr, "\nUsage: tst_clear_device block_device\n");
+}
+
+int main(int argc, char *argv[])
+{
+	/*
+	 * Force messages to be printed from the new library i.e. tst_test.c
+	 *
+	 * The new library prints messages into stderr while the old one prints
+	 * them into stdout. When messages are printed into stderr we can
+	 * safely do:
+	 *
+	 * DEV=$(tst_device acquire)
+	 */
+	tst_test = &test;
+	struct stat st;
+
+	if (argc < 2)
+		goto help;
+
+	if (stat(argv[1], &st) < 0 || !S_ISBLK(st.st_mode))
+		goto help;
+
+	return tst_clear_device(argv[1]);
+help:
+	print_help();
+	return 1;
+}
-- 
2.36.0



More information about the ltp mailing list