[LTP] [PATCH v2 5/5] Add open15 test

Andrea Cervesato andrea.cervesato@suse.com
Wed Jul 10 09:29:47 CEST 2024


On 7/9/24 14:14, Li Wang wrote:
> Hi Andrea,
>
> On Tue, Jul 9, 2024 at 6:47 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>
>     ---
>      runtest/syscalls                          |  2 +-
>      testcases/kernel/syscalls/open/.gitignore |  1 +
>      testcases/kernel/syscalls/open/open15.c   | 64
>     +++++++++++++++++++++++++++++++
>      3 files changed, 66 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..4ad7292ae
>     --- /dev/null
>     +++ b/testcases/kernel/syscalls/open/open15.c
>     @@ -0,0 +1,64 @@
>     +// 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.
>     + */
>     +
>     +#include "tst_test.h"
>     +
>     +#define FILENAME "myfile.txt"
>     +#define SYMBNAME "myfile_symlink"
>     +#define BIG_STRING
>     "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
>     +
>     +static char buff_file[128];
>     +static char buff_symlink[128];
>     +static int str_size;
>     +
>     +static void run(void)
>     +{
>     +       int fd_file, fd_symlink;
>     +
>     +       memset(buff_file, 0, sizeof(buff_file));
>     +       memset(buff_symlink, 0, sizeof(buff_symlink));
>     +
>     +       fd_file = SAFE_OPEN(FILENAME, O_CREAT | O_RDWR, 0777);
>
>
> My initial suggestion in the last email was to generate file data by
> symlink, which matches the description in code comments.
>
> fd_symlink = SAFE_OPEN(symname, O_CREAT | O_RDWR, 0777);
>     SAFE_WRITE(SAFE_WRITE_ALL, fd_symlink, BIG_STRING, str_size);
>
> But not to create&write files via fd_file. Otherwise it deviates from 
> the test goal.
>
Ah right, gonna fix that. Thanks
>
>     +       SAFE_WRITE(SAFE_WRITE_ALL, fd_file, BIG_STRING, str_size);
>     +
>     +       SAFE_SYMLINK(FILENAME, SYMBNAME);
>     +
>     +       SAFE_LSEEK(fd_file, 0, 0);
>     +       SAFE_READ(1, fd_file, buff_file, str_size);
>     +
>     +       fd_symlink = SAFE_OPEN(SYMBNAME, O_RDWR, 0777);
>     +       SAFE_LSEEK(fd_symlink, 0, 0);
>     +       SAFE_READ(1, fd_symlink, buff_symlink, str_size);
>     +
>     +       TST_EXP_EXPR(!strncmp(buff_file, buff_symlink, str_size),
>     +               "file data is the equivalent to symlink generated
>     file data");
>     +
>     +       SAFE_CLOSE(fd_file);
>     +       SAFE_CLOSE(fd_symlink);
>     +
>     +       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