[LTP] [PATCH 2/2] Make use of SAFE_ACCESS

xuyang2018.jy@fujitsu.com xuyang2018.jy@fujitsu.com
Mon Mar 14 07:43:20 CET 2022


Hi Dai

Since only umount2_02 uses old ltp api, I think we can convert it into 
ltp new api. Then we can just add this safe_macro to tst_safe_macro.c 
instead of safe_macro.c.

Best Regards
Yang Xu
> Signed-off-by: Dai Shili<daisl.fnst@fujitsu.com>
> ---
>   testcases/kernel/mem/tunable/max_map_count.c    | 4 +---
>   testcases/kernel/syscalls/fanotify/fanotify17.c | 3 +--
>   testcases/kernel/syscalls/getxattr/getxattr05.c | 3 +--
>   testcases/kernel/syscalls/madvise/madvise08.c   | 3 +--
>   testcases/kernel/syscalls/quotactl/quotactl01.c | 6 ++----
>   testcases/kernel/syscalls/quotactl/quotactl06.c | 3 +--
>   testcases/kernel/syscalls/umount2/umount2_02.c  | 6 ++----
>   7 files changed, 9 insertions(+), 19 deletions(-)
>
> diff --git a/testcases/kernel/mem/tunable/max_map_count.c b/testcases/kernel/mem/tunable/max_map_count.c
> index a4c3dbf..caf8972 100644
> --- a/testcases/kernel/mem/tunable/max_map_count.c
> +++ b/testcases/kernel/mem/tunable/max_map_count.c
> @@ -58,9 +58,7 @@ static long old_overcommit = -1;
>
>   static void setup(void)
>   {
> -	if (access(PATH_SYSVM "max_map_count", F_OK) != 0)
> -		tst_brk(TBROK | TERRNO,
> -			 "Can't support to test max_map_count");
> +	SAFE_ACCESS(PATH_SYSVM "max_map_count", F_OK);
>
>   	old_max_map_count = get_sys_tune("max_map_count");
>   	old_overcommit = get_sys_tune("overcommit_memory");
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify17.c b/testcases/kernel/syscalls/fanotify/fanotify17.c
> index 35beb53..7d74b25 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify17.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify17.c
> @@ -159,8 +159,7 @@ static void do_unshare(int map_root)
>   		 * uid_map file should exist since Linux 3.8 because
>   		 * it is available on Linux 3.5
>   		 */
> -		if (access(UID_MAP, F_OK))
> -			tst_brk(TBROK, "file %s didn't exist", UID_MAP);
> +		SAFE_ACCESS(UID_MAP, F_OK);
>
>   		SAFE_FILE_PRINTF(UID_MAP, "%d %d %d", 0, 0, 1);
>   	}
> diff --git a/testcases/kernel/syscalls/getxattr/getxattr05.c b/testcases/kernel/syscalls/getxattr/getxattr05.c
> index c0d339f..3e73cc5 100644
> --- a/testcases/kernel/syscalls/getxattr/getxattr05.c
> +++ b/testcases/kernel/syscalls/getxattr/getxattr05.c
> @@ -100,8 +100,7 @@ static void do_unshare(int map_root)
>   		/* uid_map file should exist since Linux 3.8 because
>   		 * it is available on Linux 3.5
>   		 */
> -		if (access(UID_MAP, F_OK))
> -			tst_brk(TBROK, "file %s didn't exist", UID_MAP);
> +		SAFE_ACCESS(UID_MAP, F_OK);
>
>   		SAFE_FILE_PRINTF(UID_MAP, "%d %d %d", 0, 0, 1);
>   	}
> diff --git a/testcases/kernel/syscalls/madvise/madvise08.c b/testcases/kernel/syscalls/madvise/madvise08.c
> index 30f3604..10549f4 100644
> --- a/testcases/kernel/syscalls/madvise/madvise08.c
> +++ b/testcases/kernel/syscalls/madvise/madvise08.c
> @@ -110,8 +110,7 @@ static int find_sequence(int pid)
>
>   	snprintf(dumpname, 256, "dump-%d", pid);
>   	tst_res(TINFO, "Dump file should be %s", dumpname);
> -	if (access(dumpname, F_OK))
> -		tst_brk(TBROK | TERRNO, "Dump file was not found.");
> +	SAFE_ACCESS(dumpname, F_OK);
>
>   	dfd = SAFE_OPEN(dumpname, O_RDONLY);
>
> diff --git a/testcases/kernel/syscalls/quotactl/quotactl01.c b/testcases/kernel/syscalls/quotactl/quotactl01.c
> index 561e503..3382d7b 100644
> --- a/testcases/kernel/syscalls/quotactl/quotactl01.c
> +++ b/testcases/kernel/syscalls/quotactl/quotactl01.c
> @@ -160,11 +160,9 @@ static void setup(void)
>   	SAFE_CMD(cmd, NULL, NULL);
>   	fmt_id = var->fmt_id;
>
> -	if (access(USRPATH, F_OK) == -1)
> -		tst_brk(TFAIL | TERRNO, "user quotafile didn't exist");
> +	SAFE_ACCESS(USRPATH, F_OK);
>
> -	if (access(GRPPATH, F_OK) == -1)
> -		tst_brk(TFAIL | TERRNO, "group quotafile didn't exist");
> +	SAFE_ACCESS(GRPPATH, F_OK);
>
>   	tst_require_quota_support(tst_device->dev, fmt_id, usrpath);
>
> diff --git a/testcases/kernel/syscalls/quotactl/quotactl06.c b/testcases/kernel/syscalls/quotactl/quotactl06.c
> index 8771523..839c6ed 100644
> --- a/testcases/kernel/syscalls/quotactl/quotactl06.c
> +++ b/testcases/kernel/syscalls/quotactl/quotactl06.c
> @@ -186,8 +186,7 @@ static void setup(void)
>   	/* vfsv0 block limit 2^42, vfsv1 block limit 2^63 - 1 */
>   	set_dqmax.dqb_bsoftlimit = tst_variant ? 0x20000000000000 : 0x100000000;
>
> -	if (access(USRPATH, F_OK) == -1)
> -		tst_brk(TBROK | TERRNO, "user quotafile didn't exist");
> +	SAFE_ACCESS(USRPATH, F_OK);
>
>   	tst_require_quota_support(tst_device->dev, fmt_id, usrpath);
>
> diff --git a/testcases/kernel/syscalls/umount2/umount2_02.c b/testcases/kernel/syscalls/umount2/umount2_02.c
> index 7d558fa..9dad4d5 100644
> --- a/testcases/kernel/syscalls/umount2/umount2_02.c
> +++ b/testcases/kernel/syscalls/umount2/umount2_02.c
> @@ -128,10 +128,8 @@ static void setup(void)
>   static void test_umount2(int i)
>   {
>   	/* a new access removes the expired mark of the mount point */
> -	if (test_cases[i].do_access) {
> -		if (access(MNTPOINT, F_OK) == -1)
> -			tst_brkm(TBROK | TERRNO, cleanup, "access(2) failed");
> -	}
> +	if (test_cases[i].do_access)
> +		SAFE_ACCESS(cleanup, MNTPOINT, F_OK);
>
>   	TEST(umount2_retry(MNTPOINT, test_cases[i].flag));
>


More information about the ltp mailing list