[LTP] [PATCH] open: fix directory verification and misleading test description

Cyril Hrubis chrubis@suse.cz
Thu Feb 19 11:31:27 CET 2026


Hi!
> diff --git a/testcases/kernel/syscalls/open/open01.c b/testcases/kernel/syscalls/open/open01.c
> index baf73ab11..1355592e1 100644
> --- a/testcases/kernel/syscalls/open/open01.c
> +++ b/testcases/kernel/syscalls/open/open01.c
> @@ -37,7 +37,7 @@ static struct tcase {
>  	char *desc;
>  } tcases[] = {
>  	{TEST_FILE, O_RDWR | O_CREAT, 01444, S_ISVTX, "sticky bit"},
> -	{TEST_DIR, O_DIRECTORY, 0, S_IFDIR, "sirectory bit"}
> +	{TEST_DIR, O_DIRECTORY, 0, S_IFDIR, "directory"}
>  };
> 
>  static void verify_open(unsigned int n)
> @@ -53,11 +53,17 @@ static void verify_open(unsigned int n)
>  	fd = TST_RET;
> 
>  	SAFE_FSTAT(fd, &buf);
> -	if (!(buf.st_mode & tc->tst_bit))
> -		tst_res(TFAIL, "%s is cleared unexpectedly", tc->desc);
> -	else
> -		tst_res(TPASS, "%s is set as expected", tc->desc);
> -
> +	if (tc->tst_bit == S_ISVTX) {
> +		if (!(buf.st_mode & S_ISVTX))
> +			tst_res(TFAIL, "%s is cleared unexpectedly", tc->desc);
> +		else
> +			tst_res(TPASS, "%s is set as expected", tc->desc);
> +	} else if (tc->tst_bit == S_IFDIR) {
> +		if (!S_ISDIR(buf.st_mode))
> +			tst_res(TFAIL, "%s is not a directory", tc->desc);
> +		else
> +			tst_res(TPASS, "%s is a directory", tc->desc);
> +	}

Hmm, I guess that the check for S_ISDIR() is technically testing fstat()
since unlike the sticky bit case the directory is created in the test
setup.

I guess the cleaniest solutiont may be to add fstat test that would
check all kinds of modes. Looking at the headers there are at least:

- S_ISDIR
- S_ISCHR
- S_ISBLK
- S_ISREG
- S_ISFIFO
- S_ISLNK

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list