All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xie Ziyao <xieziyao@huawei.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 5/5 v2] epoll_pwait: Add test for epoll_pwait03
Date: Fri, 16 Jul 2021 18:22:57 +0800	[thread overview]
Message-ID: <20210716102257.20882-6-xieziyao@huawei.com> (raw)
In-Reply-To: <20210716102257.20882-1-xieziyao@huawei.com>

Check that epoll_pwait/epoll_pwait2 timeout correctly.

Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Xie Ziyao <xieziyao@huawei.com>
---
v1->v2:
1. Add test variants to switch between epoll_pwait and epoll_pwait2.

 runtest/syscalls                              |  1 +
 .../kernel/syscalls/epoll_pwait/.gitignore    |  1 +
 .../syscalls/epoll_pwait/epoll_pwait03.c      | 74 +++++++++++++++++++
 3 files changed, 76 insertions(+)
 create mode 100644 testcases/kernel/syscalls/epoll_pwait/epoll_pwait03.c

diff --git a/runtest/syscalls b/runtest/syscalls
index bed224809..1deb6118f 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -167,6 +167,7 @@ epoll_wait02 epoll_wait02
 epoll_wait03 epoll_wait03
 epoll_pwait01 epoll_pwait01
 epoll_pwait02 epoll_pwait02
+epoll_pwait03 epoll_pwait03

 eventfd01 eventfd01

diff --git a/testcases/kernel/syscalls/epoll_pwait/.gitignore b/testcases/kernel/syscalls/epoll_pwait/.gitignore
index ab049f173..1d16367e6 100644
--- a/testcases/kernel/syscalls/epoll_pwait/.gitignore
+++ b/testcases/kernel/syscalls/epoll_pwait/.gitignore
@@ -1,2 +1,3 @@
 epoll_pwait01
 epoll_pwait02
+epoll_pwait03
diff --git a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait03.c b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait03.c
new file mode 100644
index 000000000..ec3b9579d
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait03.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
+ * Author: Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Check that epoll_pwait and epoll_pwait2 timeout correctly.
+ */
+
+#include <sys/epoll.h>
+
+#include "tst_timer_test.h"
+#include "epoll_pwait_var.h"
+
+#define USEC_PER_MSEC (1000L)
+
+static int efd, sfd[2];
+static struct epoll_event e;
+
+int sample_fn(int clk_id, long long usec)
+{
+	unsigned int ms = usec / USEC_PER_MSEC;
+
+	tst_timer_start(clk_id);
+	TEST(do_epoll_pwait(efd, &e, 1, ms, NULL));
+	tst_timer_stop();
+	tst_timer_sample();
+
+	if (TST_RET != 0) {
+		tst_res(TFAIL | TTERRNO,
+			"do_epoll_pwait() returned %li, expected 0", TST_RET);
+		return 1;
+	}
+
+	return 0;
+}
+
+static void setup(void)
+{
+	epoll_pwait_info();
+
+	SAFE_SOCKETPAIR(AF_UNIX, SOCK_STREAM, 0, sfd);
+
+	efd = epoll_create(1);
+	if (efd == -1)
+		tst_brk(TBROK | TERRNO, "epoll_create()");
+
+	e.events = EPOLLIN;
+	if (epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], &e))
+		tst_brk(TBROK | TERRNO, "epoll_clt(..., EPOLL_CTL_ADD, ...)");
+}
+
+static void cleanup(void)
+{
+	if (efd > 0)
+		SAFE_CLOSE(efd);
+
+	if (sfd[0] > 0)
+		SAFE_CLOSE(sfd[0]);
+
+	if (sfd[1] > 0)
+		SAFE_CLOSE(sfd[1]);
+}
+
+static struct tst_test test = {
+	.scall = "do_epoll_pwait()",
+	.sample = sample_fn,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_variants = TEST_VARIANTS,
+};
--
2.17.1


  parent reply	other threads:[~2021-07-16 10:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28  8:04 [LTP] [PATCH 0/3] epoll_pwait2: Add test for epoll_pwait2 Xie Ziyao
2021-06-28  8:04 ` [LTP] [PATCH 1/3] lapi/syscalls: Add syscall number " Xie Ziyao
2021-06-28  8:04 ` [LTP] [PATCH 2/3] epoll_pwait2: Add test for epoll_pwait201 Xie Ziyao
2021-07-12 12:23   ` Cyril Hrubis
2021-07-16 10:22   ` [LTP] [PATCH 0/5 v2] epoll_pwait2: Add test for epoll_pwait2 Xie Ziyao
2021-07-16 10:22     ` [LTP] [PATCH 1/5 v2] lapi/syscalls: Add syscall number " Xie Ziyao
2021-07-16 10:22     ` [LTP] [PATCH 2/5 v2] lapi: Add the prototype for epoll_pwait and epoll_pwait2 Xie Ziyao
2021-07-16 10:22     ` [LTP] [PATCH 3/5 v2] epoll_pwait: Add test variants for epoll_pwait Xie Ziyao
2021-07-16 10:22     ` [LTP] [PATCH 4/5 v2] epoll_pwait: Add test for epoll_pwait02 Xie Ziyao
2021-07-16 10:22     ` Xie Ziyao [this message]
2021-07-19 13:45     ` [LTP] [PATCH 0/5 v2] epoll_pwait2: Add test for epoll_pwait2 Cyril Hrubis
2021-07-20  6:57       ` Xie Ziyao
2021-06-28  8:04 ` [LTP] [PATCH 3/3] epoll_pwait2: Add test for epoll_pwait202 Xie Ziyao
2021-07-12 12:25   ` Cyril Hrubis
2021-06-28  8:12 ` [LTP] [PATCH 0/3] epoll_pwait2: Add test for epoll_pwait2 Xie Ziyao

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=20210716102257.20882-6-xieziyao@huawei.com \
    --to=xieziyao@huawei.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 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.