diff mbox series

[v3,02/10] tst_device: Add clear command

Message ID 20220804121946.19564-3-pvorel@suse.cz
State Accepted
Headers show
Series [v3,01/10] tst_test.sh: Fix tst_mkfs() for tmpfs | expand

Commit Message

Petr Vorel Aug. 4, 2022, 12:19 p.m. UTC
clearing block device will be needed for TST_ALL_FILESYSTEMS
implementation in shell API. Now we clear device during acquire,
but we will reuse this device for each tested filesystem, thus we need a
separate command for it.

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/tst_device.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/testcases/lib/tst_device.c b/testcases/lib/tst_device.c
index d6b74a5ff..45f77a38b 100644
--- a/testcases/lib/tst_device.c
+++ b/testcases/lib/tst_device.c
@@ -18,8 +18,10 @@  static struct tst_test test = {
 
 static void print_help(void)
 {
-	fprintf(stderr, "\nUsage: tst_device acquire [size [filename]]\n");
-	fprintf(stderr, "   or: tst_device release /path/to/device\n\n");
+	fprintf(stderr, "\nUsage:\n");
+	fprintf(stderr, "tst_device acquire [size [filename]]\n");
+	fprintf(stderr, "tst_device release /path/to/device\n");
+	fprintf(stderr, "tst_device clear /path/to/device\n\n");
 }
 
 static int acquire_device(int argc, char *argv[])
@@ -72,6 +74,17 @@  static int release_device(int argc, char *argv[])
 	return tst_detach_device(argv[2]);
 }
 
+static int clear_device(int argc, char *argv[])
+{
+	if (argc != 3)
+		return 1;
+
+	if (tst_clear_device(argv[2]))
+		return 1;
+
+	return 0;
+}
+
 int main(int argc, char *argv[])
 {
 	/*
@@ -94,6 +107,9 @@  int main(int argc, char *argv[])
 	} else if (!strcmp(argv[1], "release")) {
 		if (release_device(argc, argv))
 			goto help;
+	} else if (!strcmp(argv[1], "clear")) {
+		if (clear_device(argc, argv))
+			goto help;
 	} else {
 		fprintf(stderr, "ERROR: Invalid COMMAND '%s'\n", argv[1]);
 		goto help;