Message ID | 20220512194557.30911-6-pvorel@suse.cz |
---|---|
State | Changes Requested |
Headers | show |
Series | shell: $TST_ALL_FILESYSTEMS (.all_filesystems) | expand |
Hi! Can't we just add clear command to the tst_device.c instead?
Hi Cyril, > Hi! > Can't we just add clear command to the tst_device.c instead? Not sure what you mean, can you be more specific? I wasn't clear in git commit message that shell API also needs call tst_clear_device(), but we use mkfs.* binary directly, instead of tst_mkfs_() via SAFE_MKFS(), but this is obvious to you. Alternatively we could create binary testcases/lib/tst_mkfs.c which would run SAFE_MKFS(). We already have all code in C and both C and shell API would be even more consistent. Kind regards, Petr
Hi all, > --- /dev/null > +++ b/testcases/lib/tst_clear_device.c ... > +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; I guess this whole workaround is not needed for binary being used only in new shell API (note for myself in case we decided to introduce new binary wrapper). Kind regards, Petr > + 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; > +}
Hi! > > Can't we just add clear command to the tst_device.c instead? > Not sure what you mean, can you be more specific? We do have tst_device binary that has two commands acquire and release, why can't we add clear command for that binary instead?
> Hi! > > > Can't we just add clear command to the tst_device.c instead? > > Not sure what you mean, can you be more specific? > We do have tst_device binary that has two commands acquire and release, > why can't we add clear command for that binary instead? Ah, you mean testcases/lib/tst_device.c. I forget on this one, I was looking just into lib/tst_device.c. Makes sense, thx! Kind regards, Petr
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; +}
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