[LTP] [PATCH v1] Add more testcases in mkdir03

Andrea Cervesato andrea.cervesato@suse.com
Tue Feb 20 13:46:22 CET 2024


Hi!

On 2/20/24 13:37, Andrea Cervesato wrote:
> From: Andrea Cervesato <andrea.cervesato@suse.com>
>
> We add more test cases in mkdir03 in order to check that mkdir()
> can't overwrite certain types of files, such as simlinks, directories,
> pipes, devices, etc.
> These test cases come from symlink01 refactoring.
>
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>   runtest/syscalls                           |  2 +-
>   testcases/kernel/syscalls/mkdir/.gitignore |  1 +
>   testcases/kernel/syscalls/mkdir/mkdir03.c  | 10 ++++
>   testcases/kernel/syscalls/mkdir/mkdir10.c  | 57 ++++++++++++++++++++++
>   4 files changed, 69 insertions(+), 1 deletion(-)
>   create mode 100644 testcases/kernel/syscalls/mkdir/mkdir10.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index ef90076e4..aabc37519 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -757,8 +757,8 @@ mkdir02 mkdir02
>   mkdir03 mkdir03
>   mkdir04 mkdir04
>   mkdir05 mkdir05
> -mkdir05A symlink01 -T mkdir05
>   mkdir09 mkdir09
> +mkdir10 mkdir10
Please remove the runtest files modifications before merge. It's an 
error due to --amend.
Thanks
>   
>   #mkdirat test cases
>   mkdirat01 mkdirat01
> diff --git a/testcases/kernel/syscalls/mkdir/.gitignore b/testcases/kernel/syscalls/mkdir/.gitignore
> index 880ff50c0..416fbbd7c 100644
> --- a/testcases/kernel/syscalls/mkdir/.gitignore
> +++ b/testcases/kernel/syscalls/mkdir/.gitignore
> @@ -3,3 +3,4 @@
>   /mkdir04
>   /mkdir05
>   /mkdir09
> +/mkdir10
> diff --git a/testcases/kernel/syscalls/mkdir/mkdir03.c b/testcases/kernel/syscalls/mkdir/mkdir03.c
> index d5141bb64..42dfdb9f0 100644
> --- a/testcases/kernel/syscalls/mkdir/mkdir03.c
> +++ b/testcases/kernel/syscalls/mkdir/mkdir03.c
> @@ -19,6 +19,9 @@
>   #include "tst_test.h"
>   
>   #define TST_EEXIST	"tst_eexist"
> +#define TST_PIPE	"tst_pipe"
> +#define TST_FOLDER	"tst_folder"
> +#define TST_SYMLINK "tst_symlink"
>   #define TST_ENOENT	"tst_enoent/tst"
>   #define TST_ENOTDIR_FILE "tst_enotdir"
>   #define TST_ENOTDIR_DIR	"tst_enotdir/tst"
> @@ -41,6 +44,9 @@ static struct tcase {
>   	{NULL, EFAULT},
>   	{long_dir, ENAMETOOLONG},
>   	{TST_EEXIST, EEXIST},
> +	{TST_FOLDER, EEXIST},
> +	{TST_PIPE, EEXIST},
> +	{TST_SYMLINK, EEXIST},
>   	{TST_ENOENT, ENOENT},
>   	{TST_ENOTDIR_DIR, ENOTDIR},
>   	{loop_dir, ELOOP},
> @@ -70,7 +76,11 @@ static void verify_mkdir(unsigned int n)
>   static void setup(void)
>   {
>   	unsigned int i;
> +	char *tmpdir = tst_get_tmpdir();
>   
> +	SAFE_SYMLINK(tmpdir, TST_SYMLINK);
> +	SAFE_MKFIFO(TST_PIPE, 0777);
> +	SAFE_MKDIR(TST_FOLDER, 0777);
>   	SAFE_TOUCH(TST_EEXIST, MODE, NULL);
>   	SAFE_TOUCH(TST_ENOTDIR_FILE, MODE, NULL);
>   
> diff --git a/testcases/kernel/syscalls/mkdir/mkdir10.c b/testcases/kernel/syscalls/mkdir/mkdir10.c
> new file mode 100644
> index 000000000..87f419916
> --- /dev/null
> +++ b/testcases/kernel/syscalls/mkdir/mkdir10.c
> @@ -0,0 +1,57 @@
> +// 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 mkdir() can't overwrite certain generated files, such
> + * as symlinks, pipes, devices, folders, etc.
> + */
> +
> +#include "tst_test.h"
> +
> +#define FILE_FOLDER "myfolder"
> +#define FILE_MYFILE "myfile"
> +#define FILE_FIFO "mypipe"
> +#define FILE_SYMLINK "mylink"
> +#define FILE_DEVICE "/dev/null"
> +
> +struct tcase {
> +	char *file;
> +	char *msg;
> +};
> +
> +static struct tcase tcases[] = {
> +	{FILE_FOLDER,	"folder already exists"},
> +	{FILE_MYFILE,	"file already exists"},
> +	{FILE_FIFO,		"fifo already exists"},
> +	{FILE_SYMLINK,	"symlink already exists"},
> +	{FILE_DEVICE,	"device already exists"},
> +};
> +
> +static void run(unsigned int i)
> +{
> +	struct tcase *tc = &tcases[i];
> +
> +	TST_EXP_FAIL(mkdir(tc->file, 0777), EEXIST, "%s", tc->msg);
> +}
> +
> +static void setup(void)
> +{
> +	SAFE_SYMLINK(tst_get_tmpdir(), FILE_SYMLINK);
> +	SAFE_MKFIFO(FILE_FIFO, 0777);
> +	SAFE_MKDIR(FILE_FOLDER, 0777);
> +	SAFE_TOUCH(FILE_MYFILE, 0777, NULL);
> +}
> +
> +static struct tst_test test = {
> +	.test = run,
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.setup = setup,
> +	.needs_tmpdir = 1,
> +};




More information about the ltp mailing list