Re: [LTP] [PATCH] tst_supported_fs: Implement checking paths against skiplist

Li Wang
2022-09-22T04:17:28Z

[-- Attachment #1.1: Type: text/plain, Size: 5460 bytes --]

On Wed, Sep 21, 2022 at 11:50 PM Martin Doucha <mdoucha@suse.cz> wrote:

> Signed-off-by: Martin Doucha <mdoucha@suse.cz>
> ---
>
> Implement tst_supported_fs feature suggested by pvorel in his patch:
> tst_test.sh: Fix filesystem support detection
>
> Although the tst_fs_type_name() functions could use some improvements,
> e.g. ext4 must be specified in skiplist as "ext2/ext3/ext4" to get properly
>

Yes, that's true, we need to make it keep consistent with two
skipping ways. Otherwise below test output "ext2/ext3/ext4"
looks like a bit mess to remember.

Better going with a single FS for matching (i.e. "ext4" for both fs_type
and '-d path').
But we can solve this in a separate patch later.

$ df -T . | tail -1 | awk '{print $2}'
ext4

$ ./tst_supported_fs -s "ext4" ext4
tst_supported_fs.c:135: TCONF: ext4 is skipped
$ echo $?
32

$ ./tst_supported_fs -s "ext4" -d .
tst_supported_fs.c:137: TINFO: ext2/ext3/ext4 is not skipped
$ echo $?
0

$ ./tst_supported_fs -s "ext2/ext3/ext4" -d .
tst_supported_fs.c:135: TCONF: ext2/ext3/ext4 is skipped
$ echo $?
32

> skipped and vfat is missing from the list of known filesystems.
>
> testcases/lib/tst_supported_fs.c | 49 ++++++++++++++++++++++++++------
> 1 file changed, 41 insertions(+), 8 deletions(-)
>
> diff --git a/testcases/lib/tst_supported_fs.c
> b/testcases/lib/tst_supported_fs.c
> index 70d4d38c7..5873d0ba1 100644
> --- a/testcases/lib/tst_supported_fs.c
> +++ b/testcases/lib/tst_supported_fs.c
> @@ -32,9 +32,13 @@ static void usage(void)
> fprintf(stderr, "tst_supported_fs -s skip_list fs_type\n");
> fprintf(stderr, " if fs_type is in skip_list, return 1 otherwise
> return 0\n\n");
>
> + fprintf(stderr, "tst_supported_fs -s skip_list -d path\n");
> + fprintf(stderr, " if filesystem mounted on path is in skip_list,
> return 1 otherwise return 0\n\n");

+
> fprintf(stderr, "fs_type - a specified filesystem type\n");
> fprintf(stderr, "skip_list - filesystems to skip, delimiter:
> '%c'\n",
> SKIP_DELIMITER);
> + fprintf(stderr, "path - any valid file or directory\n");
> }
>
> static char **parse_skiplist(char *fs)
> @@ -62,10 +66,11 @@ static char **parse_skiplist(char *fs)
> int main(int argc, char *argv[])
> {
> const char *const *filesystems;
> + const char *fsname = NULL;
> int i, ret;
> char **skiplist = NULL;
>
> - while ((ret = getopt(argc, argv, "hs:"))) {
> + while ((ret = getopt(argc, argv, "hs:d:"))) {
> if (ret < 0)
> break;
>
> @@ -83,9 +88,26 @@ int main(int argc, char *argv[])
> if (!skiplist)
> return 1;
> break;
> +
> + case 'd':
> + if (fsname) {
> + fprintf(stderr,
> + "Can't specify multiple paths\n");
> + usage();
> + return 2;
> + }
> +
> + fsname = tst_fs_type_name(tst_fs_type(optarg));
> + break;
> }
> }
>
> + if (fsname && !skiplist) {
> + fprintf(stderr, "Parameter -d requires skiplist\n");
> + usage();
> + return 2;
> + }
> +
> if (argc - optind > 1) {
> fprintf(stderr, "Can't specify multiple fs_type\n");
> usage();
> @@ -94,22 +116,33 @@ int main(int argc, char *argv[])
>
> /* fs_type */
> if (optind < argc) {
> - if (argv[optind][0] == '\0')
> + if (fsname) {
> + fprintf(stderr, "Can't specify fs_type and -d
> together\n");
> + usage();
> + return 2;
> +
> + }
> +
> + fsname = argv[optind];
> + }
> +
> + if (fsname) {
> + if (fsname[0] == '\0')
> tst_brk(TCONF, "fs_type is empty");
>
> if (skiplist) {
> - if (tst_fs_in_skiplist(argv[optind], (const char *
> const*)skiplist))
> - tst_brk(TCONF, "%s is skipped",
> argv[optind]);
> + if (tst_fs_in_skiplist(fsname, (const char *
> const*)skiplist))
> + tst_brk(TCONF, "%s is skipped", fsname);
>

TCONF does not means return 1, we might need explicitly 'return 1' here.

else
> - tst_res(TINFO, "%s is not skipped",
> argv[optind]);
> + tst_res(TINFO, "%s is not skipped",
> fsname);
>
> return 0;
> }
>
> - if (tst_fs_is_supported(argv[optind]) ==
> TST_FS_UNSUPPORTED)
> - tst_brk(TCONF, "%s is not supported",
> argv[optind]);
> + if (tst_fs_is_supported(fsname) == TST_FS_UNSUPPORTED)
> + tst_brk(TCONF, "%s is not supported", fsname);
>

Same here.

> else
> - tst_res(TINFO, "%s is supported", argv[optind]);
> + tst_res(TINFO, "%s is supported", fsname);
>
> return 0;
> }
> --
> 2.37.3
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>

--
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 9370 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]