Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1004974ybv; Thu, 13 Feb 2020 13:50:12 -0800 (PST) X-Google-Smtp-Source: APXvYqxlrpNodlUmKpAtnY6rUerx3Xv7wPtE5K3y9W7YJTsxvwlzv15ZXco0PFv6f+esNUCvIXS8 X-Received: by 2002:a9d:729c:: with SMTP id t28mr14981684otj.66.1581630611894; Thu, 13 Feb 2020 13:50:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581630611; cv=none; d=google.com; s=arc-20160816; b=MA+vYGRwxKNSiM4OGTkL1DhcPu5LaA2Y29YpH/XoWZsCnICmDGoihNwM1Hy/Dxv8m0 xrywxYQX+Vowj/xDZLWTn2BtmevfJup7dLDdXIUBwUTcF6RDMGAc60yd/4ddb3I02/OQ wtGOmD6DWINjDq79+mR5aSJomMVwGNpbVS+HSTDgxQoWmIx8hktSs185BN5Rxxb4/EEG tCDEwwLzLe/Dw4MxBaoaw1ujkiGrRDwIb1BlMBpem/4tXy9XQud8LvqILZlHP3Vi6aFO 3qmjEr72qsCHg4MArFvq9g+qCplOefWHGb3zvguAo7P7EOfTh0o+nutRGz2z+QnjfkEj jo5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0Fr7wTpuiQpHsPuLIkIEoma+VZYlyBvyX4asnE8Os3w=; b=LiC3c3oxxj2Kw3w4dAt7fGsX52eYo3WWgx8Iwt6uog5xbneRWgx/QkTn3Ez8RvcaxM spyjvb7Gl0pF+xB5FsEPlG/XOAhJMdr0a+DaU8Rc+kuuS1NlGtVjLnEYi5xln3BngHsI ahSa72ty9pKxXnTTLNv6Gznvn60866El4OXknhTCWX2GyBnolth0ec6Xj+w2gvVqgvfT GuKJU0HLYEdL6VLYCdgGqmGHsEUOby0IpZ1ebBcyorijXIeNph3Hx0w12UEg5+KTmNmk /Mt6Z84DPsAoHYyiet653nbnfP3BvMYGisl+9M8nWGzUeKpdaS9Tr0388/c18kW3wvfn fs7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e17si1833629oti.136.2020.02.13.13.49.59; Thu, 13 Feb 2020 13:50:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728787AbgBMVsT (ORCPT + 99 others); Thu, 13 Feb 2020 16:48:19 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:37534 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728740AbgBMVsT (ORCPT ); Thu, 13 Feb 2020 16:48:19 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id 50D4C29581C From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: linux-kernel@vger.kernel.org, tglx@linutronix.de Cc: kernel@collabora.com, krisman@collabora.com, shuah@kernel.org, linux-kselftest@vger.kernel.org, rostedt@goodmis.org, ryao@gentoo.org, peterz@infradead.org, dvhart@infradead.org, mingo@redhat.com, z.figura12@gmail.com, steven@valvesoftware.com, pgriffais@valvesoftware.com, steven@liquorix.net, =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH v3 2/4] selftests: futex: Add FUTEX_WAIT_MULTIPLE timeout test Date: Thu, 13 Feb 2020 18:45:23 -0300 Message-Id: <20200213214525.183689-3-andrealmeid@collabora.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200213214525.183689-1-andrealmeid@collabora.com> References: <20200213214525.183689-1-andrealmeid@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gabriel Krisman Bertazi Add test for timeout when waiting for multiple futexes. Skip the test if it's a x32 application and the kernel returned the approtiaded error, since this ABI is not supported for this operation. Signed-off-by: Gabriel Krisman Bertazi Co-developed-by: André Almeida Signed-off-by: André Almeida --- Changes since v2: none --- .../futex/functional/futex_wait_timeout.c | 38 ++++++++++++++++++- .../selftests/futex/include/futextest.h | 22 +++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_wait_timeout.c b/tools/testing/selftests/futex/functional/futex_wait_timeout.c index ee55e6d389a3..2a63e1c2cfb6 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_timeout.c +++ b/tools/testing/selftests/futex/functional/futex_wait_timeout.c @@ -11,6 +11,7 @@ * * HISTORY * 2009-Nov-6: Initial version by Darren Hart + * 2019-Dec-13: Add WAIT_MULTIPLE test by Krisman * *****************************************************************************/ @@ -41,6 +42,8 @@ int main(int argc, char *argv[]) { futex_t f1 = FUTEX_INITIALIZER; struct timespec to; + time_t secs; + struct futex_wait_block fwb = {&f1, f1, 0}; int res, ret = RET_PASS; int c; @@ -65,7 +68,7 @@ int main(int argc, char *argv[]) } ksft_print_header(); - ksft_set_plan(1); + ksft_set_plan(2); ksft_print_msg("%s: Block on a futex and wait for timeout\n", basename(argv[0])); ksft_print_msg("\tArguments: timeout=%ldns\n", timeout_ns); @@ -79,8 +82,39 @@ int main(int argc, char *argv[]) if (!res || errno != ETIMEDOUT) { fail("futex_wait returned %d\n", ret < 0 ? errno : ret); ret = RET_FAIL; + } else + ksft_test_result_pass("futex_wait timeout succeeds\n"); + + info("Calling futex_wait_multiple on f1: %u @ %p\n", f1, &f1); + + /* Setup absolute time */ + ret = clock_gettime(CLOCK_REALTIME, &to); + secs = (to.tv_nsec + timeout_ns) / 1000000000; + to.tv_nsec = ((int64_t)to.tv_nsec + timeout_ns) % 1000000000; + to.tv_sec += secs; + info("to.tv_sec = %ld\n", to.tv_sec); + info("to.tv_nsec = %ld\n", to.tv_nsec); + + res = futex_wait_multiple(&fwb, 1, &to, + FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME); + +#ifdef __ILP32__ + if (res == -1 && errno == ENOSYS) { + ksft_test_result_skip("futex_wait_multiple not supported at x32\n"); + } else { + ksft_test_result_fail("futex_wait_multiple returned %d\n", + res < 0 ? errno : res); + ret = RET_FAIL; } +#else + if (!res || errno != ETIMEDOUT) { + ksft_test_result_fail("futex_wait_multiple returned %d\n", + res < 0 ? errno : res); + ret = RET_FAIL; + } else + ksft_test_result_pass("futex_wait_multiple timeout succeeds\n"); +#endif /* __ILP32__ */ - print_result(TEST_NAME, ret); + ksft_print_cnts(); return ret; } diff --git a/tools/testing/selftests/futex/include/futextest.h b/tools/testing/selftests/futex/include/futextest.h index ddbcfc9b7bac..bb103bef4557 100644 --- a/tools/testing/selftests/futex/include/futextest.h +++ b/tools/testing/selftests/futex/include/futextest.h @@ -38,6 +38,14 @@ typedef volatile u_int32_t futex_t; #ifndef FUTEX_CMP_REQUEUE_PI #define FUTEX_CMP_REQUEUE_PI 12 #endif +#ifndef FUTEX_WAIT_MULTIPLE +#define FUTEX_WAIT_MULTIPLE 13 +struct futex_wait_block { + futex_t *uaddr; + futex_t val; + __u32 bitset; +}; +#endif #ifndef FUTEX_WAIT_REQUEUE_PI_PRIVATE #define FUTEX_WAIT_REQUEUE_PI_PRIVATE (FUTEX_WAIT_REQUEUE_PI | \ FUTEX_PRIVATE_FLAG) @@ -80,6 +88,20 @@ futex_wait(futex_t *uaddr, futex_t val, struct timespec *timeout, int opflags) return futex(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags); } +/** + * futex_wait_multiple() - block on several futexes with optional timeout + * @fwb: wait block user space address + * @count: number of entities at fwb + * @timeout: absolute timeout + */ +static inline int +futex_wait_multiple(struct futex_wait_block *fwb, int count, + struct timespec *timeout, int opflags) +{ + return futex(fwb, FUTEX_WAIT_MULTIPLE, count, timeout, NULL, 0, + opflags); +} + /** * futex_wake() - wake one or more tasks blocked on uaddr * @nr_wake: wake up to this many tasks -- 2.25.0