[LTP] [PATCH v2 1/7] Refactor input01 test

Petr Vorel pvorel@suse.cz
Mon Dec 2 16:15:21 CET 2024


Hi Andrea,

I would mention adding a check of the device name in /sys/devices
create_input_device(), because that modifies also a different test
(../uevents/uevent03.c).

> ---
>  libs/uinput/tst_uinput.c              |  26 ++++-
>  testcases/kernel/input/Makefile       |   5 +-
>  testcases/kernel/input/input01.c      | 205 ++++++++--------------------------
>  testcases/kernel/input/input_common.h |  97 ++++++++++++++++
>  4 files changed, 173 insertions(+), 160 deletions(-)

...
> +static void check_ui_get_sysname_ioctl(int fd)
> +{
> +	char sys_name[256];
> +	char dev_name[256];
> +	char *path;
> +
> +	SAFE_IOCTL(fd, UI_GET_SYSNAME(sizeof(sys_name)), sys_name, NULL);
> +	SAFE_ASPRINTF(&path, "/sys/devices/virtual/input/%s/name", sys_name);
> +
> +	if (FILE_SCANF(path, "%s", dev_name)) {
> +		tst_brk(TBROK|TERRNO, "Failed to read '%s'", path);
> +		free(path);
I guess free(path) here is not needed due exit() via tst_brk() right?
And if it's needed, you meant to first free and then tst_brk().

> +		return;
> +	}
> +
> +	if (strcmp(VIRTUAL_DEVICE, dev_name))
And if I'm wrong, then free(path) should be also here.
> +		tst_brk(TBROK, "ioctl UI_GET_SYSNAME returned wrong name");

The rest LGTM, nice cleanup (free can be fixed before merge).

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr


More information about the ltp mailing list