From patchwork Wed Nov 23 11:35:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13053522 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9984BC4332F for ; Wed, 23 Nov 2022 11:36:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234901AbiKWLgh (ORCPT ); Wed, 23 Nov 2022 06:36:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236183AbiKWLgf (ORCPT ); Wed, 23 Nov 2022 06:36:35 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF30E88FB9 for ; Wed, 23 Nov 2022 03:36:34 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id cl5so28973696wrb.9 for ; Wed, 23 Nov 2022 03:36:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Rt32A+mPj3rYWuCqBVS19xPD/wXoK2EaewkcD5uohDs=; b=JC7V4dOeMFy8iz0N/HFDuDjl5Jeu4jQIVGvHRYr2S0Q2ug7MQxZyzinhqJLrj+/p7x 5WHK7SeL6uB291L+i5bOiWCKlTHQWX0XcSby4YTSQZNDEQHbr19rInsOhFAtVSIiTIRi DUfl3sg3Q7CnYCdKMslWkB/xahBAcqz3o61Ag42lV4kYBUt800S4dGTgT+58VqU9vFg6 ImJrFMOMTt3S8aAFimSuoBT74CtTXBJe4HqSO91deut2q3aVvHwC2Ah8lI1FSODm8+VU 3JWRJ7tL9CCv9Pb8xTHQZLoiMN6l+VI2JXuwwifMczF9Z2dweS6/aWAnXhBvkphuBqfb 7KnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rt32A+mPj3rYWuCqBVS19xPD/wXoK2EaewkcD5uohDs=; b=Urt4/Iv3D5+1PR/0bBIxp87olfdBVBCzWarjmh9wulxEVTCo7BMGNIO1BFoxtzVtQo 4OvCxoa/o1PF5bPFUulra6rdD0IjWVrQqcJYZVJFbwo1DFzLaHC5D08Izcn8vvExpMQb 1SGZCY1YLmjD572//emvO610dgrvGr9hm/MvtE4vFqx/OGLGEF3SrYL2C7pQw9y2e9Ga EKAuAzYGG7Icn12dTUKRirJpnN5PB81ncWkTTmjAvWig6g3ATUBoWDTFZ4kZNNO6n0Rb vAC2dxRToht1SX+wtD6llitWff5glnQimyT6ZYxeiDD9Uu8pnj/YhG1zKlEfozbPU2aQ QHAg== X-Gm-Message-State: ANoB5pmR3A/U4blmcxH63Cnvx2iXHGFdso2yiPm9OY7EDw8DCJDPlQ4w MRjffFtDUp3YtnUu5L6Tqid949Bxc58= X-Google-Smtp-Source: AA0mqf7I8AVoZ9sE2KyqZFa9NmCgAHy1G47dVNpa6TIY85pd63gqbIgnxMskHrwT/8wJSTRuZC8+mw== X-Received: by 2002:a5d:5685:0:b0:235:f0a6:fafd with SMTP id f5-20020a5d5685000000b00235f0a6fafdmr17224881wrv.75.1669203393295; Wed, 23 Nov 2022 03:36:33 -0800 (PST) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:e1b]) by smtp.gmail.com with ESMTPSA id y9-20020a5d4ac9000000b00241ce5d605dsm10854508wrs.110.2022.11.23.03.36.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 03:36:32 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 1/3] tests: remove sigalarm from poll.c Date: Wed, 23 Nov 2022 11:35:08 +0000 Message-Id: X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Test loop handles timeouting and killing stuck tests, no need to have a separate sigalarm in poll.c Signed-off-by: Pavel Begunkov --- test/poll.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/test/poll.c b/test/poll.c index 1cd57ba..42123bd 100644 --- a/test/poll.c +++ b/test/poll.c @@ -14,12 +14,6 @@ #include "liburing.h" -static void sig_alrm(int sig) -{ - fprintf(stderr, "Timed out!\n"); - exit(1); -} - int main(int argc, char *argv[]) { struct io_uring_cqe *cqe; @@ -43,20 +37,12 @@ int main(int argc, char *argv[]) perror("fork"); exit(2); case 0: { - struct sigaction act; - ret = io_uring_queue_init(1, &ring, 0); if (ret) { fprintf(stderr, "child: ring setup failed: %d\n", ret); return 1; } - memset(&act, 0, sizeof(act)); - act.sa_handler = sig_alrm; - act.sa_flags = SA_RESTART; - sigaction(SIGALRM, &act, NULL); - alarm(1); - sqe = io_uring_get_sqe(&ring); if (!sqe) { fprintf(stderr, "get sqe failed\n"); From patchwork Wed Nov 23 11:35:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13053524 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D25EC3A59F for ; Wed, 23 Nov 2022 11:36:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236183AbiKWLgi (ORCPT ); Wed, 23 Nov 2022 06:36:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236491AbiKWLgg (ORCPT ); Wed, 23 Nov 2022 06:36:36 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4FA011DA29 for ; Wed, 23 Nov 2022 03:36:35 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id s5so11760038wru.1 for ; Wed, 23 Nov 2022 03:36:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=da2QefqNv60KG19SLkKIuXsfvTh0a3cDn3yIWSSJr1o=; b=c/VJRP6u53JaT7z4oWZarghKX38OQd5BsfwI5h7VHiB7WxLfvZ8GBwtOAJWVotxNXJ l+ic9itW7ORuwpimoUp3/gKR8hZKbQLVZV1sJqGkvdSrP6QhPA2hIFsyqx42O4tc+Ycs RFSkXu7FI+OqreB3mnDow/KBh4VSvL4OrKR1on97VhoDtgKgcsezqvuxZYc4QgVzJI4d hiIA2lJVsCuEZ3YYAL3FeemFCDVu5IoZZlf9QnyqThQg84LhaDoTeNy+q9XUbvWHIUyC gxYUi+7u85sEh7koyM9otvxdH2h0pych0KiiNhiUcPbv8BdQiuLYm/u+aHCvxLZmbF7q LqSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=da2QefqNv60KG19SLkKIuXsfvTh0a3cDn3yIWSSJr1o=; b=BCuOGO0e3Ga2hNILpCGZYR6sDJmWg7+Wb/zjU3GGwjtWvcfo1E1jrYs51RTIZRV8lh 5MuHpOjlEToXNtmPcdDhcjLVEsPf0oLWKiETil+NhtjkNBxSAip0vUgBSKE66QJtk0Rx iKM2UyEfLHWDFKp95lc+/hQk0iYKKRgLkDoE/AyfJxZAQt4TG2w4d7VrMf6Up3ncU0wG UEJEBgbb96r3DdRZAhAT6FvNP0bp5jzDZgQHxchSKWPG00SaIedfFdrxWQWdGk/eSORd ecnN7Yy3gT/f0fEb6CbD6Mc+SPdEKtVRqNWFLRIsyoj4sq+/2UISDS64XzpOj9f4GGyJ yx6w== X-Gm-Message-State: ANoB5pmVPlS7ZzwYPLLsZJmECQWhVD0ihqWd+xtrI4ZfdGNBH2vbv5N2 0mQC+TmhISc/Ll8ZMWrHb/pLs5uuxuY= X-Google-Smtp-Source: AA0mqf61TFD4p4aAfXTahwrvgaZXETOAmZjbrJQyDzq3VHN5kgV4BKdPbc+BmmZl7rKQxO5M3fr7Bg== X-Received: by 2002:a5d:4241:0:b0:236:57cf:1b6f with SMTP id s1-20020a5d4241000000b0023657cf1b6fmr5272698wrr.153.1669203393980; Wed, 23 Nov 2022 03:36:33 -0800 (PST) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:e1b]) by smtp.gmail.com with ESMTPSA id y9-20020a5d4ac9000000b00241ce5d605dsm10854508wrs.110.2022.11.23.03.36.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 03:36:33 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 2/3] tests: refactor poll.c Date: Wed, 23 Nov 2022 11:35:09 +0000 Message-Id: <880d8b2607a063442659025a43240127a8887470.1669079092.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Extract all poll.c testing into a separate function Signed-off-by: Pavel Begunkov --- test/poll.c | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/test/poll.c b/test/poll.c index 42123bd..f0c1c40 100644 --- a/test/poll.c +++ b/test/poll.c @@ -12,9 +12,10 @@ #include #include +#include "helpers.h" #include "liburing.h" -int main(int argc, char *argv[]) +static int test_basic(void) { struct io_uring_cqe *cqe; struct io_uring_sqe *sqe; @@ -23,20 +24,16 @@ int main(int argc, char *argv[]) pid_t p; int ret; - if (argc > 1) - return 0; - if (pipe(pipe1) != 0) { perror("pipe"); return 1; } p = fork(); - switch (p) { - case -1: + if (p == -1) { perror("fork"); exit(2); - case 0: { + } else if (p == 0) { ret = io_uring_queue_init(1, &ring, 0); if (ret) { fprintf(stderr, "child: ring setup failed: %d\n", ret); @@ -78,18 +75,36 @@ int main(int argc, char *argv[]) (long) cqe->res); return 1; } + + io_uring_queue_exit(&ring); exit(0); - } - default: - do { - errno = 0; - ret = write(pipe1[1], "foo", 3); - } while (ret == -1 && errno == EINTR); + } - if (ret != 3) { - fprintf(stderr, "parent: bad write return %d\n", ret); - return 1; - } + do { + errno = 0; + ret = write(pipe1[1], "foo", 3); + } while (ret == -1 && errno == EINTR); + + if (ret != 3) { + fprintf(stderr, "parent: bad write return %d\n", ret); + return 1; + } + close(pipe1[0]); + close(pipe1[1]); + return 0; +} + +int main(int argc, char *argv[]) +{ + int ret; + + if (argc > 1) return 0; + + ret = test_basic(); + if (ret) { + fprintf(stderr, "test_basic() failed %i\n", ret); + return T_EXIT_FAIL; } + return 0; } From patchwork Wed Nov 23 11:35:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13053523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94BCAC46467 for ; Wed, 23 Nov 2022 11:36:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236491AbiKWLgi (ORCPT ); Wed, 23 Nov 2022 06:36:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236844AbiKWLgh (ORCPT ); Wed, 23 Nov 2022 06:36:37 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4944311DA39 for ; Wed, 23 Nov 2022 03:36:36 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id x17so15496493wrn.6 for ; Wed, 23 Nov 2022 03:36:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CnrNjjHUtd8weh2wxZbyMyM1wu77vG5OfU8KEdIwyQc=; b=N3qUI4kBg6GooWVcVvblmc6j0PeokL0AkaNLmUSAPcoER6yoAvV7gukjjrrZr8SZjv IDKUhZCGon3yiR5Bhk/+GrJHpxSFnCGW4efuOqKVhqKy6TwrumJrwy301T6Jvf+agPE+ 0e4zfXsG2qB7aL6c/LA5wAeFKu9ZoBur76ABxF8FHUM5JFmX79F62R2Nw0WnL3vbnCg3 07RW4j7mASrdLEZK7wDAAM76aOIqs6llC/m4mkLDuX6XvTUOES0itBsEyWg6v4/IgdXA TqXtuYENXnxbxdQff2A7beQ1v4nHKWh+fPeMOR+TeNLlc9ddhOTzxN/4Ok13vM9bTHbc Vjdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CnrNjjHUtd8weh2wxZbyMyM1wu77vG5OfU8KEdIwyQc=; b=SKfo+Y793mDNrfjVCVyxCWu25II5dlAYci1Ht4TLxANjG0mINhaCCS1He0Ynr0HUzr 9ssTdXdN9x5NpgDAwgvsKE/t93Hh6rYr6HI6rrTlOgdmr63SlLFl5nD5LXwM26GYg6TM EiP0nkjjQBhNyYVx/sbwynf3P34VuawK9jSk1aanFXH0PlZLkCTKSlU8Um1Snuuo9T56 X814Mwbvoy2JhgPlG52WhsnfYF8X1V/XwK+Wjpw4eGJKrPX1IHsDH7onCpx/gcPf7+4+ SPn3KSRlKMUcKRthuM82gABcH0FAgeJhH9MCN2LXmzcTxIU1mbP9TnJkBMkWFkc6Zgou TamA== X-Gm-Message-State: ANoB5pk2M5NeUARFxIwOt1gplKTYHtWk0XdGvjgSWblwUUIZzbcwVvMe zv06hrE4hS7lLFCdLN+83PvLX4VySyo= X-Google-Smtp-Source: AA0mqf7lk8+mDoW6Ftd+nA9JPFMA7zCGJhRDnW40DgzJ12LyL+TUdTjScBc5cJCHRm0QhMson2IaIQ== X-Received: by 2002:a05:6000:5:b0:241:d692:3cc5 with SMTP id h5-20020a056000000500b00241d6923cc5mr8822209wrx.419.1669203394670; Wed, 23 Nov 2022 03:36:34 -0800 (PST) Received: from 127.0.0.1localhost.com ([2620:10d:c092:600::2:e1b]) by smtp.gmail.com with ESMTPSA id y9-20020a5d4ac9000000b00241ce5d605dsm10854508wrs.110.2022.11.23.03.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 03:36:34 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH liburing 3/3] tests: check for missing multipoll events Date: Wed, 23 Nov 2022 11:35:10 +0000 Message-Id: <4b0f4d96027b69d9b0f8392887dc973c5afffe31.1669079092.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Signed-off-by: Pavel Begunkov --- test/poll.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/test/poll.c b/test/poll.c index f0c1c40..a7db7dc 100644 --- a/test/poll.c +++ b/test/poll.c @@ -11,10 +11,17 @@ #include #include #include +#include #include "helpers.h" #include "liburing.h" +static void do_setsockopt(int fd, int level, int optname, int val) +{ + if (setsockopt(fd, level, optname, &val, sizeof(val))) + error(1, errno, "setsockopt %d.%d: %d", level, optname, val); +} + static int test_basic(void) { struct io_uring_cqe *cqe; @@ -94,6 +101,85 @@ static int test_basic(void) return 0; } +static int test_missing_events(void) +{ + struct io_uring_cqe *cqe; + struct io_uring_sqe *sqe; + struct io_uring ring; + int i, ret, sp[2]; + char buf[2] = {}; + int res_mask = 0; + + if (!t_probe_defer_taskrun()) + return 0; + + ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER | + IORING_SETUP_DEFER_TASKRUN); + if (ret) { + fprintf(stderr, "ring setup failed: %d\n", ret); + return 1; + } + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) != 0) { + perror("Failed to create Unix-domain socket pair\n"); + return 1; + } + do_setsockopt(sp[0], SOL_SOCKET, SO_SNDBUF, 1); + ret = send(sp[0], buf, sizeof(buf), 0); + if (ret != sizeof(buf)) { + perror("send failed\n"); + return 1; + } + + sqe = io_uring_get_sqe(&ring); + io_uring_prep_poll_multishot(sqe, sp[0], POLLIN|POLLOUT); + ret = io_uring_submit(&ring); + if (ret != 1) { + fprintf(stderr, "sqe submit failed: %d\n", ret); + return 1; + } + + /* trigger EPOLLIN */ + ret = send(sp[1], buf, sizeof(buf), 0); + if (ret != sizeof(buf)) { + fprintf(stderr, "send sp[1] failed %i %i\n", ret, errno); + return 1; + } + + /* trigger EPOLLOUT */ + ret = recv(sp[1], buf, sizeof(buf), 0); + if (ret != sizeof(buf)) { + perror("recv failed\n"); + return 1; + } + + for (i = 0; ; i++) { + if (i == 0) + ret = io_uring_wait_cqe(&ring, &cqe); + else + ret = io_uring_peek_cqe(&ring, &cqe); + + if (i != 0 && ret == -EAGAIN) { + break; + } + if (ret) { + fprintf(stderr, "wait completion %d, %i\n", ret, i); + return 1; + } + res_mask |= cqe->res; + io_uring_cqe_seen(&ring, cqe); + } + + if ((res_mask & (POLLIN|POLLOUT)) != (POLLIN|POLLOUT)) { + fprintf(stderr, "missing poll events %i\n", res_mask); + return 1; + } + io_uring_queue_exit(&ring); + close(sp[0]); + close(sp[1]); + return 0; +} + int main(int argc, char *argv[]) { int ret; @@ -106,5 +192,12 @@ int main(int argc, char *argv[]) fprintf(stderr, "test_basic() failed %i\n", ret); return T_EXIT_FAIL; } + + ret = test_missing_events(); + if (ret) { + fprintf(stderr, "test_missing_events() failed %i\n", ret); + return T_EXIT_FAIL; + } + return 0; }