[LTP] [PATCH v3 4/4] Add open15 test

Li Wang liwang@redhat.com
Wed Jul 10 11:37:28 CEST 2024


On Wed, Jul 10, 2024 at 4:56 PM Andrea Cervesato <andrea.cervesato@suse.de>
wrote:

> From: Andrea Cervesato <andrea.cervesato@suse.com>
>
> This test has been extracted from symlink01 and it verifies that
> open() is working correctly on symlink() generated files.
>
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
>

It is a bit different from something in my imagination, but anyway
this also looks good.

Reviewed-by: Li Wang <liwang@redhat.com>

---
>  runtest/syscalls                          |  2 +-
>  testcases/kernel/syscalls/open/.gitignore |  1 +
>  testcases/kernel/syscalls/open/open15.c   | 75
> +++++++++++++++++++++++++++++++
>  3 files changed, 77 insertions(+), 1 deletion(-)
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 40c0dd070..4dfdf3782 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -923,7 +923,6 @@ nice04 nice04
>  nice05 nice05
>
>  open01 open01
> -open01A symlink01 -T open01
>  open02 open02
>  open03 open03
>  open04 open04
> @@ -936,6 +935,7 @@ open11 open11
>  open12 open12
>  open13 open13
>  open14 open14
> +open15 open15
>
>  openat01 openat01
>  openat02 openat02
> diff --git a/testcases/kernel/syscalls/open/.gitignore
> b/testcases/kernel/syscalls/open/.gitignore
> index 001d874d6..af5997572 100644
> --- a/testcases/kernel/syscalls/open/.gitignore
> +++ b/testcases/kernel/syscalls/open/.gitignore
> @@ -12,3 +12,4 @@
>  /open12_child
>  /open13
>  /open14
> +/open15
> diff --git a/testcases/kernel/syscalls/open/open15.c
> b/testcases/kernel/syscalls/open/open15.c
> new file mode 100644
> index 000000000..09d7a1f3b
> --- /dev/null
> +++ b/testcases/kernel/syscalls/open/open15.c
> @@ -0,0 +1,75 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
> + *    Author: David Fenner
> + *    Copilot: Jon Hendrickson
> + * Copyright (C) 2024 Andrea Cervesato andrea.cervesato@suse.com
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This test verifies that open() is working correctly on symlink()
> + * generated files. We generate a file via symlink, then we read both
> from file
> + * and symlink, comparing that data has been correctly written.
> + */
> +
> +#include "tst_test.h"
> +
> +#define FILENAME "myfile.txt"
> +#define SYMBNAME "myfile_symlink"
> +#define BIG_STRING "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
> +
> +static char buff_file[128];
> +static char buff_symb[128];
> +static int str_size;
> +
> +static void run(void)
> +{
> +       int fd_file, fd_symb;
> +
> +       memset(buff_file, 0, sizeof(buff_file));
> +       memset(buff_symb, 0, sizeof(buff_symb));
> +
> +       tst_res(TINFO, "Create symlink");
> +       SAFE_TOUCH(FILENAME, 0777, NULL);
> +       SAFE_SYMLINK(FILENAME, SYMBNAME);
> +
> +       fd_file = SAFE_OPEN(FILENAME, O_RDONLY, 0777);
> +       fd_symb = SAFE_OPEN(SYMBNAME, O_RDWR, 0777);
> +
> +       tst_res(TINFO, "Write data via symlink");
> +       SAFE_WRITE(SAFE_WRITE_ALL, fd_symb, BIG_STRING, str_size);
> +       SAFE_LSEEK(fd_symb, 0, 0);
> +
> +       tst_res(TINFO, "Read data via file");
> +       SAFE_READ(1, fd_file, buff_file, str_size);
> +       SAFE_LSEEK(fd_file, 0, 0);
> +
> +       tst_res(TINFO, "Read data via symlink");
> +       SAFE_READ(1, fd_symb, buff_symb, str_size);
> +       SAFE_LSEEK(fd_symb, 0, 0);
> +
> +       TST_EXP_EXPR(!strncmp(buff_file, BIG_STRING, str_size),
> +               "file data has been correctly written");
> +
> +       TST_EXP_EXPR(!strncmp(buff_file, buff_symb, str_size),
> +               "file data is the equivalent to symlink generated file
> data");
> +
> +       SAFE_CLOSE(fd_file);
> +       SAFE_CLOSE(fd_symb);
> +
> +       SAFE_UNLINK(SYMBNAME);
> +       SAFE_UNLINK(FILENAME);
> +}
> +
> +static void setup(void)
> +{
> +       str_size = strlen(BIG_STRING);
> +}
> +
> +static struct tst_test test = {
> +       .test_all = run,
> +       .setup = setup,
> +       .needs_tmpdir = 1,
> +};
>
> --
> 2.43.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>

-- 
Regards,
Li Wang


More information about the ltp mailing list