[LTP] [PATCH 1/2] Add TST_ASSERT_SYSCALL*() macros

Cyril Hrubis chrubis@suse.cz
Thu Mar 5 15:46:06 CET 2020


Hi!
> +/* assert that syscall returned only 0 and nothing else */
> +#define TST_ASSERT_SYSCALL(SCALL) \
> +	TST_ASSERT_SYSCALL_IMPL(SCALL, __FILE__, __LINE__)
> +
> +#define TST_ASSERT_SYSCALL_IMPL(SCALL, FILENAME, LINENO) \
> +	({ \
> +		int _tst_ret; \
> +		errno = 0; \
> +		_tst_ret = SCALL; \
> +		if (_tst_ret == -1) { \
> +			int _tst_ttype = errno == ENOTSUP ? TCONF : TBROK; \
> +			tst_brk(_tst_ttype | TERRNO, "%s:%d " # SCALL \
                                                              ^
				I do not think that is reasonable to
				simply stringify the syscall, we are
				adding pretty printers for the syscall
				parameters and this change is backward.

These two patches are actually removing the pretty printer for the clock
id for the timerfd_create(). I do not like that.

> +				" failed", FILENAME, LINENO); \
> +		} \
> +		if (_tst_ret != 0) { \
> +			tst_brk(TBROK | TERRNO, "%s:%d " # SCALL \
> +				" returned invalid value %d", FILENAME, \
> +				LINENO, _tst_ret); \
> +		} \
> +		_tst_ret; \
> +	})
> +
> +/*
> + * assert that syscall returned any non-negative value (e.g. valid file
> + * descriptor)
> + */
> +#define TST_ASSERT_SYSCALL_FD(SCALL) \
> +	TST_ASSERT_SYSCALL_FD_IMPL(SCALL, __FILE__, __LINE__)
> +
> +#define TST_ASSERT_SYSCALL_FD_IMPL(SCALL, FILENAME, LINENO) \
> +	({ \
> +		int _tst_ret; \
> +		errno = 0; \
> +		_tst_ret = SCALL; \
> +		if (_tst_ret == -1) { \
> +			int _tst_ttype = errno == ENOTSUP ? TCONF : TBROK; \
> +			tst_brk(_tst_ttype | TERRNO, "%s:%d " # SCALL \
> +				" failed", FILENAME, LINENO); \
> +		} \
> +		if (_tst_ret < 0) { \
> +			tst_brk(TBROK | TERRNO, "%s:%d " # SCALL \
> +				" returned invalid value %d", FILENAME, \
> +				LINENO, _tst_ret); \
> +		} \
> +		_tst_ret; \
> +	})
> +
>  /*
>   * Functions to convert ERRNO to its name and SIGNAL to its name.
>   */
> -- 
> 2.25.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list