Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1213572pxb; Thu, 4 Mar 2021 06:18:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJxs6wyJU0ni5cum9m32ZufUOjmHcLtLX3nDkim11JzYSispYuCK+GzABxvp7NF2HBgbPXgO X-Received: by 2002:a50:ec0e:: with SMTP id g14mr4621036edr.264.1614867504994; Thu, 04 Mar 2021 06:18:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614867504; cv=none; d=google.com; s=arc-20160816; b=EP//ntMf7A9sc1M3cd+5lEVueE26DfAH3mKovgrAy6TKUNQyEuxe19A0XGd2j3hWeB CX+252paomKSvd6LVtM7y20T0lDZsb0FTHJmayCm/bBA6l2MgwblHRStBptpIKDrPea1 aY52COxYek8LDHA3qHl7RQ8FnT9IeJpLtsHIjesh9+CnQCnpXwWonsX6LBgZD8d3wQo2 Tq+GoLnPuTrW6Pqyfwh1dWaKX4AoPWlPzwUFzG69PTsIqZOo4YrlDFFVjRLxzRwOV1C1 n6HUdAeF0wsbKGmy0ijdrElH4+YUykKhdewS3Sq4iOJ2Cfyg4V6RosVdofg6Dk38PzQ4 UklQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=NPGtegOFo6d1L6hKDkBwcrA38kkZEO2SeR+Mh47nc2o=; b=C0vjnrs1hYgBsqirW7mQGsTr2Ev3/oU0G16U3OzpQUhbsV8DLkbBMWJWaPY2YlIuBv hu+zkSuwlQUrM6WHJhv1mq/cG/dFOLK/SHhXK1+iaikR1gjI6Z9apUscsbW/VNMaXho1 u1Td9XazjZR3y2HQ6LSgpyjqXkCJ0aXEaZw8r/m6eMdjCmicSfbTF4ZNfOdvUhwzCimu 1EnuGMZHHHN3Fwbze8Hlzddd5gzZDzk+mI7ahVDTgqsstxnw0+LLZDnrTf9uno5pz/bn LTJNSjQBkCTCxygrybFl+h94cUKcw2JlBdEmKMnvMF30N+PJjPSZbbc02vyMKc8eTuaC D6lA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id a13si18244032edn.209.2021.03.04.06.18.02; Thu, 04 Mar 2021 06:18:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1447772AbhCDBG7 (ORCPT + 99 others); Wed, 3 Mar 2021 20:06:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1453070AbhCDAoZ (ORCPT ); Wed, 3 Mar 2021 19:44:25 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08DC9C061764; Wed, 3 Mar 2021 16:43:43 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id 0567D1F46043 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , linux-kernel@vger.kernel.org, Steven Rostedt , Sebastian Andrzej Siewior Cc: kernel@collabora.com, krisman@collabora.com, pgriffais@valvesoftware.com, z.figura12@gmail.com, joel@joelfernandes.org, malteskarupke@fastmail.fm, linux-api@vger.kernel.org, fweimer@redhat.com, libc-alpha@sourceware.org, linux-kselftest@vger.kernel.org, shuah@kernel.org, acme@kernel.org, corbet@lwn.net, =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [RFC PATCH v2 08/13] selftests: futex2: Add timeout test Date: Wed, 3 Mar 2021 21:42:14 -0300 Message-Id: <20210304004219.134051-9-andrealmeid@collabora.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210304004219.134051-1-andrealmeid@collabora.com> References: <20210304004219.134051-1-andrealmeid@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adapt existing futex wait timeout file to test the same mechanism for futex2. futex2 accepts only absolute 64bit timers, but supports both monotonic and realtime clocks. Signed-off-by: André Almeida --- .../futex/functional/futex_wait_timeout.c | 58 ++++++++++++++++--- 1 file changed, 49 insertions(+), 9 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..b4dffe9e3b44 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 + * 2021-Feb-5: Add futex2 test by André * *****************************************************************************/ @@ -20,7 +21,7 @@ #include #include #include -#include "futextest.h" +#include "futex2test.h" #include "logging.h" #define TEST_NAME "futex-wait-timeout" @@ -40,7 +41,8 @@ void usage(char *prog) int main(int argc, char *argv[]) { futex_t f1 = FUTEX_INITIALIZER; - struct timespec to; + struct timespec to = {.tv_sec = 0, .tv_nsec = timeout_ns}; + struct timespec64 to64; int res, ret = RET_PASS; int c; @@ -65,22 +67,60 @@ int main(int argc, char *argv[]) } ksft_print_header(); - ksft_set_plan(1); + ksft_set_plan(3); 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); - /* initialize timeout */ - to.tv_sec = 0; - to.tv_nsec = timeout_ns; - info("Calling futex_wait on f1: %u @ %p\n", f1, &f1); res = futex_wait(&f1, f1, &to, FUTEX_PRIVATE_FLAG); if (!res || errno != ETIMEDOUT) { - fail("futex_wait returned %d\n", ret < 0 ? errno : ret); + ksft_test_result_fail("futex_wait returned %d\n", ret < 0 ? errno : ret); + ret = RET_FAIL; + } else { + ksft_test_result_pass("futex_wait timeout succeeds\n"); + } + + /* setting absolute monotonic timeout for futex2 */ + if (gettime64(CLOCK_MONOTONIC, &to64)) + error("gettime64 failed\n", errno); + + to64.tv_nsec += timeout_ns; + + if (to64.tv_nsec >= 1000000000) { + to64.tv_sec++; + to64.tv_nsec -= 1000000000; + } + + info("Calling futex2_wait on f1: %u @ %p\n", f1, &f1); + res = futex2_wait(&f1, f1, FUTEX_32, &to64); + if (!res || errno != ETIMEDOUT) { + ksft_test_result_fail("futex2_wait monotonic returned %d\n", ret < 0 ? errno : ret); + ret = RET_FAIL; + } else { + ksft_test_result_pass("futex2_wait monotonic timeout succeeds\n"); + } + + /* setting absolute realtime timeout for futex2 */ + if (gettime64(CLOCK_REALTIME, &to64)) + error("gettime64 failed\n", errno); + + to64.tv_nsec += timeout_ns; + + if (to64.tv_nsec >= 1000000000) { + to64.tv_sec++; + to64.tv_nsec -= 1000000000; + } + + info("Calling futex2_wait on f1: %u @ %p\n", f1, &f1); + res = futex2_wait(&f1, f1, FUTEX_32 | FUTEX_CLOCK_REALTIME, &to64); + if (!res || errno != ETIMEDOUT) { + ksft_test_result_fail("futex2_wait realtime returned %d\n", ret < 0 ? errno : ret); ret = RET_FAIL; + } else { + ksft_test_result_pass("futex2_wait realtime timeout succeeds\n"); } - print_result(TEST_NAME, ret); + ksft_print_cnts(); return ret; } -- 2.30.1