public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] epoll_pwait/epoll_pwait01.c: add new testcase
Date: Thu, 3 Mar 2016 15:37:04 +0800	[thread overview]
Message-ID: <56D7E9A0.4060701@cn.fujitsu.com> (raw)
In-Reply-To: <20160302153222.GD25763@rei>

Hi!

Thanks for your review!

OK, I will modify the test case according to your suggestion.

Best Regards,
Guangwen Feng

On 03/02/2016 11:32 PM, Cyril Hrubis wrote:
> Hi!
>> +/*
>> + * Description:
>> + *  Basic test for epoll_pwait(2).
>> + *  1) epoll_pwait(2) with sigmask argument allows the caller to
>> + *     safely wait until either a file descriptor becomes ready
>> + *     or the timeout expires.
>> + *  2) epoll_pwait(2) with NULL sigmask argument fails if
>> + *     interrupted by a signal handler, epoll_pwait(2) should
>> + *     return -1 and set errno to EINTR.
>> + */
>> +
>> +#include <sys/epoll.h>
>> +#include <sys/types.h>
>> +#include <unistd.h>
>> +#include <string.h>
>> +#include <errno.h>
>> +
>> +#include "test.h"
>> +#include "epoll_pwait.h"
>> +#include "safe_macros.h"
>> +
>> +char *TCID = "epoll_pwait01";
>> +int TST_TOTAL = 2;
>> +
>> +static int epfd, fds[2];
>> +static const char buf[] = "Testing";
>> +static sigset_t sigset;
>> +static struct epoll_event epevs;
>> +static struct sigaction sa;
>> +
>> +static void setup(void);
>> +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED);
>> +static void do_test(sigset_t *);
>> +static void do_child(void);
>> +static void cleanup(void);
>> +
>> +int main(int ac, char **av)
>> +{
>> +	int lc;
>> +
>> +	tst_parse_opts(ac, av, NULL, NULL);
>> +
>> +	setup();
>> +
>> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
>> +		tst_count = 0;
>> +
>> +		do_test(&sigset);
>> +		do_test(NULL);
>> +	}
>> +
>> +	cleanup();
>> +	tst_exit();
>> +}
>> +
>> +static void setup(void)
>> +{
>> +	if ((tst_kvercmp(2, 6, 19)) < 0) {
>> +		tst_brkm(TCONF, NULL, "This test can only run on kernels "
>> +			 "that are 2.6.19 or higher");
>> +	}
>> +
>> +	tst_sig(FORK, DEF_HANDLER, cleanup);
>> +
>> +	TEST_PAUSE;
>> +
>> +	if (sigemptyset(&sigset) == -1)
>> +		tst_brkm(TFAIL | TERRNO, NULL, "sigemptyset() failed");
>> +
>> +	if (sigaddset(&sigset, SIGUSR1) == -1)
>> +		tst_brkm(TFAIL | TERRNO, NULL, "sigaddset() failed");
>> +
>> +	sa.sa_flags = 0;
>> +	sa.sa_handler = sighandler;
>> +	if (sigemptyset(&sa.sa_mask) == -1)
>> +		tst_brkm(TFAIL | TERRNO, NULL, "sigemptyset() failed");
>> +
>> +	if (sigaction(SIGUSR1, &sa, NULL) == -1)
>> +		tst_brkm(TFAIL | TERRNO, NULL, "sigaction() failed");
>> +
>> +	SAFE_PIPE(NULL, fds);
>> +
>> +	epfd = epoll_create(1);
>> +	if (epfd == -1) {
>> +		tst_brkm(TBROK | TERRNO, cleanup,
>> +			 "failed to create epoll instance");
>> +	}
>> +
>> +	epevs.events = EPOLLIN;
>> +	epevs.data.fd = fds[0];
>> +
>> +	if (epoll_ctl(epfd, EPOLL_CTL_ADD, fds[0], &epevs) == -1) {
>> +		tst_brkm(TBROK | TERRNO, cleanup,
>> +			 "failed to register epoll target");
>> +	}
>> +}
>> +
>> +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
>> +{
>> +
>> +}
>> +
>> +static void do_test(sigset_t *sigmask)
>> +{
>> +	char read_buf[sizeof(buf)];
>> +	pid_t cpid;
>> +
>> +	cpid = tst_fork();
>> +	if (cpid < 0)
>> +		tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
>> +
>> +	if (cpid == 0)
>> +		do_child();
>> +
>> +	TEST(epoll_pwait(epfd, &epevs, 1, -1, sigmask));
>> +
>> +	if (sigmask != NULL) {
>> +		if (TEST_RETURN == -1) {
>> +			tst_resm(TFAIL | TTERRNO, "epoll_pwait() failed");
>> +		} else if (TEST_RETURN != 1) {
>> +			tst_resm(TFAIL, "epoll_pwait() returned %li, "
>> +				 "expected 1", TEST_RETURN);
>> +		} else {
>> +			tst_resm(TPASS, "epoll_pwait(sigmask) blocked signal");
>> +		}
>> +	} else {
>> +		if (TEST_RETURN != -1) {
>> +			tst_resm(TFAIL, "epoll_wait() succeeded unexpectedly");
>> +		} else {
>> +			if (TEST_ERRNO == EINTR) {
>> +				tst_resm(TPASS | TTERRNO,
>> +					 "epoll_wait() failed as expected");
>> +			} else {
>> +				tst_resm(TFAIL | TTERRNO,
>> +					 "epoll_wait() failed unexpectedly, "
>> +					 "expected errno is EINTR");
>> +			}
>> +		}
>> +	}
> 
> 
> Can we put the checks in a separate functions and call them from here?
> 
>> +	tst_record_childstatus(cleanup, cpid);
>> +
>> +	SAFE_READ(cleanup, 1, fds[0], read_buf, sizeof(buf));
>> +}
>> +
>> +static void do_child(void)
>> +{
>> +	if (tst_process_state_wait2(getppid(), 'S') != 0) {
>> +		tst_brkm(TBROK | TERRNO, cleanup,
>> +			 "failed to wait for parent process's state");
>> +	}
>> +
>> +	SAFE_KILL(cleanup, getppid(), SIGUSR1);
>> +
>> +	sleep(1);
> 
> One second is too much, 0.1 second should be more than enough for the
> test.
> 
>> +	SAFE_WRITE(cleanup, 1, fds[1], buf, sizeof(buf));
> 
> Technically we don't have to write anything here (and we could exit the
> child without sleeping as well) if we passed a timeout to the
> epoll_pwait() instead in the parent (we would have to check for timeout
> instead of success but that shouldn't matter in this test).
> 
>> +	cleanup();
>> +	tst_exit();
>> +}
> 
> Otherwise it looks good.
> 



  reply	other threads:[~2016-03-03  7:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-20 11:09 [LTP] [PATCH 1/2] epoll_pwait/epoll_pwait01.c: add new testcase Guangwen Feng
2016-01-20 11:10 ` [LTP] [PATCH 2/2] epoll_pwait/epoll_pwait02.c: " Guangwen Feng
2016-02-09 14:02   ` Cyril Hrubis
2016-02-19  8:33     ` [LTP] [PATCH v2] epoll_pwait/epoll_pwait01.c: " Guangwen Feng
2016-03-02 15:32       ` Cyril Hrubis
2016-03-03  7:37         ` Guangwen Feng [this message]
2016-03-03  8:24           ` [LTP] [PATCH v3] " Guangwen Feng
2016-03-03 15:13             ` 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=56D7E9A0.4060701@cn.fujitsu.com \
    --to=fenggw-fnst@cn.fujitsu.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox