All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] kernel/input: fix failure on an old kernel
Date: Thu, 9 Nov 2017 14:45:23 +0100	[thread overview]
Message-ID: <20171109134523.GA23734@rei> (raw)
In-Reply-To: <1510137430-25555-1-git-send-email-yangx.jy@cn.fujitsu.com>

Hi!
> +/*
> + * the value of sync_events_ignored:
> + * 0: cannot ignore EV_SYN/SYN_REPORT events received in /dev/input/eventX
> + * 1: ignore EV_SYN/SYN_REPORT events received in /dev/input/eventX
> + * On an old kernel(before v3.7.0), EV_SYN/SYN_REPORT events are always
> + * received even though we send empty moves.
> + */
> +int no_events_queued(int fd, int sync_events_ignored)
>  {
>  	struct pollfd fds = {.fd = fd, .events = POLLIN};
>  	int ret, res;
> @@ -241,9 +248,14 @@ int no_events_queued(int fd)
>  		res = read(fd, &ev, sizeof(ev));
>  
>  		if (res == sizeof(ev)) {
> -			tst_resm(TINFO,
> -			         "Unexpected ev type=%i code=%i value=%i",
> -			         ev.type, ev.code, ev.value);
> +			if (sync_events_ignored && !ev.type &&
> +			    !ev.code && !ev.value) {

The ev.value is undefined for sync events, it's 0 most of the time but I
remember that we had to fix the input06.c because it was failing for
somebody, see check_sync_event() there. Maybe we should just move the
check_event* and check_sync_event() helpers to the library so that we
can use them here as well.

> +				ret = 0;
> +			} else {
> +				tst_resm(TINFO,
> +					 "Unexpected ev type=%i code=%i value=%i",
> +					 ev.type, ev.code, ev.value);
> +			}
>  		}
>  	}
>  
> @@ -264,7 +276,40 @@ static int check_device(void)
>  			return 1;
>  	}
>  
> +
  ^
  Please do not add useless empty lines.

>  	fclose(file);
>  
>  	return 0;
>  }
> +
> +/*
> + * Use this function to check if the current kernel can get single
> + * EV_SYN/SYN_REPORT events.
> + */
> +int check_single_sync_event(int fd1, int fd2)
> +{
> +	pid_t pid;
> +	struct pollfd fds = {.fd = fd2, .events = POLLIN};
> +	struct input_event ev;
> +	int ret, ignored;
> +
> +	pid = tst_fork();
> +
> +	if (pid == -1)
> +		tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
> +
> +	if (!pid) {
> +		send_event(fd1, EV_SYN, 0, 0);
> +		exit(0);
> +	}
> +
> +	ret = poll(&fds, 1, 30);
> +	if (ret > 0 && SAFE_READ(NULL, 1, fd2, &ev, sizeof(ev)) == sizeof(ev)) {
> +		if (!ev.type && !ev.code && !ev.value)
> +			ignored = 1;
> +	}
> +
> +	SAFE_WAITPID(NULL, pid, NULL, 0);
> +
> +	return ignored;
> +}

This still does not fix the problem. Even if new kernel started to
produce stray sync events these testcases will still pass. What I think
is a good solution is simply to define first fixed kernel version and
expect that no stray sync events are produced on newer kernels.

> diff --git a/testcases/kernel/input/input_helper.h b/testcases/kernel/input/input_helper.h
> index 9b85dc9..1ef4d32 100644
> --- a/testcases/kernel/input/input_helper.h
> +++ b/testcases/kernel/input/input_helper.h
> @@ -29,6 +29,7 @@ int open_uinput(void);
>  void create_device(int fd);
>  void setup_mouse_events(int fd);
>  void destroy_device(int fd);
> -int no_events_queued(int fd);
> +int no_events_queued(int fd, int sync_events_ignored);
> +int check_single_sync_event(int fd1, int fd2);
>  
>  #endif /* INPUT_HELPER_H */
> -- 
> 1.8.3.1
> 
> 
> 

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2017-11-09 13:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-09  9:57 [LTP] [PATCH] kernel/input: fix failure on an old kernel Xiao Yang
2017-11-06  7:52 ` Xiao Yang
2017-11-07 14:20 ` Cyril Hrubis
2017-11-08 10:37   ` [LTP] [PATCH v2] " Xiao Yang
2017-11-09 13:45     ` Cyril Hrubis [this message]
2017-11-13  6:45       ` [LTP] [PATCH v3] " Xiao Yang
2017-12-04  7:45         ` Xiao Yang
2017-12-04 15:33         ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171109134523.GA23734@rei \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.