Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp542624pxj; Thu, 3 Jun 2021 13:04:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWcur5tOmPSdflRpiBrpxsrhEXKs8qhfpGE0kH1VkGMK29s3gj3eVn/GlTqgczKOZr6QAY X-Received: by 2002:a05:6402:145a:: with SMTP id d26mr1089560edx.151.1622750640291; Thu, 03 Jun 2021 13:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622750640; cv=none; d=google.com; s=arc-20160816; b=nfJ02KVpxa+qg5nW7SFbbethO9tncaWdmGGAuTLoQm+3yMVPaGXux89d3Falbt8olQ sfjM85Pplzawb34JlKT6kgbeATNs1UohKtZD1K5XAEcRUfQrHFOtxNHkekL50ePTDfC9 TE11k/LqXgo+8KG/W9DUPv8ySYoUE6ipmF2XuehkWi0AH7/JvxnnTGLIPSlW1idZXwTF gWsoaMpqWPGXJSTtpFv++NQ2Cgh1qxu3jEyweUG7eosYLGJXo4v2ZSbchwgNP1NG5j6l swYXDjXvhf4sCqCQX/YMwnvGflGdk9TdTV32F1RAPOByrvqP0ltgbPqKLC37bwxgCrZb /Tiw== 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=OwJ7Zrz+5DmJ+qFIpNWHozF392/dvZNLMhU/lqtUODg=; b=w5rpclv3s8XKC9Aau384aLL7OQI1NeZPHmKtatQ8AwHkc48qJW4WRtrov8L0um7eaJ 5UhmGHBl4ng30uXfE4SB8YWfBXesVb4sU4aBSQ3PFGwxIaxSMBl9HLK8QEkMWiFMNII4 8NwZhfqwij5UJT/VEpkNyUT+X32zjLsRZ+XAtlc96B8ntaL1HZv6yYEK53uUHAYhSdLi B3vmszyyNuWdYbsHR+WF7XqgjdQmqhZGMG9sPIEPiQ+zXMkehNcsgZ7CzcCVlmI5UTt1 LOV28QaCtPRDNU+fjnU8RNBm0JIVf1HfBxF5pS3f1iJpzNaUTn1L00fQV3gjPNPFsov0 Q1mA== 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 w4si2882427edu.173.2021.06.03.13.03.37; Thu, 03 Jun 2021 13:04:00 -0700 (PDT) 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 S230247AbhFCUCy (ORCPT + 99 others); Thu, 3 Jun 2021 16:02:54 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:53034 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229661AbhFCUCw (ORCPT ); Thu, 3 Jun 2021 16:02:52 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id D6AC31F434CB 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, Peter Oskolkov , Andrey Semashev , Davidlohr Bueso , =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH v4 09/15] selftests: futex2: Add timeout test Date: Thu, 3 Jun 2021 16:59:18 -0300 Message-Id: <20210603195924.361327-10-andrealmeid@collabora.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210603195924.361327-1-andrealmeid@collabora.com> References: <20210603195924.361327-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.31.1