Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp141894pxv; Thu, 8 Jul 2021 17:16:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXZYR1P2iW6IXQB7pWk2zguMK76MuhQ89MGIzCc87e2P/fYo+1wperJ8XhZqfMdnWXLuPD X-Received: by 2002:a17:906:546:: with SMTP id k6mr34011527eja.53.1625789788882; Thu, 08 Jul 2021 17:16:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625789788; cv=none; d=google.com; s=arc-20160816; b=F+wH6mJn1j1D/6mqMCz/U+L5zTPQLuUisB0hFFHjrxV6R5zfsBgGvK55yAjInc4zS6 6kDXqfumkd8nwlTB33uP/rLdSCJFiblz35+F9ZPnlpNKZybCOGqH1nGSeVPIfHHv+ReS wQTIyh4/h8MubyBWva0cC3tg7Xoii6nJxKcT/UwMhVqKMgCatTzyJRtw22M7808tFd+A QhJjs+MTJDxs9gqA1AmEh7UhSp1T75Rr7veIGU3zEILc9MjYnmrLtZNUp+aPW5YckHMc U5r2m4YxaRojPKCogxMX7vZssY7G0yjv14Ed+kUyAKW/4vwzX+f5Q0zJ0vocw5NS/HvC 5Jbw== 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=TcorSbwgbFwvQl+A+/VL2Kf9iHdE3xA+OvJbPbH6eBE=; b=uf85bjB5u/G1ZMvR4/Bje9Bl8DuKgyT2CTBJOfBpe5ZSh6fR+tXyJXOn+L4kV5W6Z6 /D7WI+0i6SIxeQY+RppqqIQf+diRd5v7Szt/87ipjO4iJUGmPqk/UAGraWO7zNJOmX4g wuMPi4irAXIWMi24Qk2qzdSHdzcvpwqfg4MtbbsAelINDlwewq9Usq+RPTwIMIx3EjQN aHoU2ego8fOnnXGsuZy896TbHtd8Oll4KB28xd5SyZPE3rO2WAqYFGIYdh3KQ2YFNl0L kHeaMAt/pQ5W4E69iwln/Ipmjw4jU46qFcRZyw0mM0rx3Pvo7XoHgoZEoDzHJ/4WeWVc m3kg== 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 eo9si5550919ejc.528.2021.07.08.17.16.06; Thu, 08 Jul 2021 17:16:28 -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 S230166AbhGIARR (ORCPT + 99 others); Thu, 8 Jul 2021 20:17:17 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:44816 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230135AbhGIARQ (ORCPT ); Thu, 8 Jul 2021 20:17:16 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id 5207F1F4198C 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 , Nicholas Piggin , Adhemerval Zanella , =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH v5 06/11] selftests: futex2: Add timeout test Date: Thu, 8 Jul 2021 21:13:23 -0300 Message-Id: <20210709001328.329716-7-andrealmeid@collabora.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210709001328.329716-1-andrealmeid@collabora.com> References: <20210709001328.329716-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 | 24 +++++++++++++++++-- 1 file changed, 22 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 1f8f6daaf1e7..d20f54745c2e 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_timeout.c +++ b/tools/testing/selftests/futex/functional/futex_wait_timeout.c @@ -17,6 +17,14 @@ #include #include "futextest.h" + +#include +#include +#include +#include +#include +#include +#include "futex2test.h" #include "logging.h" #define TEST_NAME "futex-wait-timeout" @@ -92,8 +100,8 @@ static int futex_get_abs_timeout(clockid_t clockid, struct timespec *to, int main(int argc, char *argv[]) { futex_t f1 = FUTEX_INITIALIZER; + struct timespec to = {.tv_sec = 0, .tv_nsec = timeout_ns}; int res, ret = RET_PASS; - struct timespec to; pthread_t thread; int c; @@ -118,7 +126,7 @@ int main(int argc, char *argv[]) } ksft_print_header(); - ksft_set_plan(7); + ksft_set_plan(9); 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); @@ -175,6 +183,18 @@ int main(int argc, char *argv[]) res = futex_lock_pi(&futex_pi, NULL, 0, FUTEX_CLOCK_REALTIME); test_timeout(res, &ret, "futex_lock_pi invalid timeout flag", ENOSYS); + /* setting absolute monotonic timeout for futex2 */ + if (futex_get_abs_timeout(CLOCK_MONOTONIC, &to, timeout_ns)) + return RET_FAIL; + res = futex2_wait(&f1, f1, FUTEX_32, &to); + test_timeout(res, &ret, "futex2_wait monotonic", ETIMEDOUT); + + /* setting absolute realtime timeout for futex2 */ + if (futex_get_abs_timeout(CLOCK_REALTIME, &to, timeout_ns)) + return RET_FAIL; + res = futex2_wait(&f1, f1, FUTEX_32 | FUTEX_CLOCK_REALTIME, &to); + test_timeout(res, &ret, "futex2_wait realtime", ETIMEDOUT); + ksft_print_cnts(); return ret; } -- 2.32.0