[LTP] [PATCH v2] syscalls/mmap15: Rewrite test using new LTP API

Cyril Hrubis chrubis@suse.cz
Tue Oct 31 16:31:59 CET 2023


Hi!
> +	if (TST_RET_PTR != MAP_FAILED) {
> +		tst_res(TFAIL, "mmap() into high mem region succeeded unexpectedly");
> +		SAFE_MUNMAP(TST_RET_PTR, page_size);
> +		return;
> +	} else if (TST_RET_PTR == MAP_FAILED && (TST_ERR == ENOMEM || TST_ERR == EINVAL)) {

There is no reason for an else branch if we do return in the previous
one.

Also we do return so TST_RET_PTR is always MAP_FAILED here, no need to
test it again.

> +		tst_res(TPASS | TERRNO, "mmap() failed with expected errno");
> +	} else {
> +		tst_res(TFAIL | TERRNO, "mmap() failed with unexpected errno");
>  	}
>  
> -	cleanup();
> -	tst_exit();
> +	SAFE_CLOSE(fd);
>  }
>  
>  static void setup(void)
>  {
> -	tst_require_root();
> -
> -	tst_tmpdir();
> -
>  	page_size = getpagesize();
> -
> -	TEST_PAUSE;
>  }
>  
>  static void cleanup(void)
>  {
> -	tst_rmdir();
> +	if (fd > 0)
> +		SAFE_CLOSE(fd);
>  }
> +
> +static struct tst_test test = {
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_all = run,
> +	.needs_root = 1,

Do we really need root?

> +	.needs_tmpdir = 1
> +};
> -- 
> 2.41.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list