Skip to content

Commit

Permalink
Add more testcases in mkdir03
Browse files Browse the repository at this point in the history
We add more test cases in mkdir03 in order to check that mkdir()
can't overwrite certain types of files, such as symlinks, directories,
pipes, devices, etc.
These test cases come from symlink01 refactoring.

Link: https://lore.kernel.org/ltp/[email protected]/
Reviewed-by: Cyril Hrubis <[email protected]>
Reviewed-by: Petr Vorel <[email protected]>
Signed-off-by: Andrea Cervesato <[email protected]>
  • Loading branch information
acerv authored and pevik committed Mar 7, 2024
1 parent 754c518 commit d824f59
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 0 additions & 1 deletion runtest/syscalls
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,6 @@ mkdir02 mkdir02
mkdir03 mkdir03
mkdir04 mkdir04
mkdir05 mkdir05
mkdir05A symlink01 -T mkdir05
mkdir09 mkdir09

#mkdirat test cases
Expand Down
16 changes: 16 additions & 0 deletions testcases/kernel/syscalls/mkdir/mkdir03.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* EFAULT, ENAMETOOLONG, EEXIST, ENOENT, ENOTDIR, ELOOP and EROFS
*/

#include <paths.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand All @@ -19,6 +21,10 @@
#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_NULLDEV _PATH_DEVNULL
#define TST_ENOENT "tst_enoent/tst"
#define TST_ENOTDIR_FILE "tst_enotdir"
#define TST_ENOTDIR_DIR "tst_enotdir/tst"
Expand All @@ -41,6 +47,10 @@ static struct tcase {
{NULL, EFAULT},
{long_dir, ENAMETOOLONG},
{TST_EEXIST, EEXIST},
{TST_FOLDER, EEXIST},
{TST_PIPE, EEXIST},
{TST_SYMLINK, EEXIST},
{TST_NULLDEV, EEXIST},
{TST_ENOENT, ENOENT},
{TST_ENOTDIR_DIR, ENOTDIR},
{loop_dir, ELOOP},
Expand Down Expand Up @@ -70,7 +80,13 @@ static void verify_mkdir(unsigned int n)
static void setup(void)
{
unsigned int i;
char *tmpdir = tst_get_tmpdir();

SAFE_SYMLINK(tmpdir, TST_SYMLINK);
free(tmpdir);

SAFE_MKFIFO(TST_PIPE, 0777);
SAFE_MKDIR(TST_FOLDER, 0777);
SAFE_TOUCH(TST_EEXIST, MODE, NULL);
SAFE_TOUCH(TST_ENOTDIR_FILE, MODE, NULL);

Expand Down

0 comments on commit d824f59

Please sign in to comment.