Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4930391pxy; Tue, 27 Apr 2021 16:18:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxE5rEfLKKAuQEDgnL49yLg8o27/yw2bmRlNGSI9uNufFjGe50apRqtCMPM6yNrAzO1hCrn X-Received: by 2002:a17:90b:1e10:: with SMTP id pg16mr773656pjb.30.1619565517491; Tue, 27 Apr 2021 16:18:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619565517; cv=none; d=google.com; s=arc-20160816; b=usTslCNSCzoZEYU2mx3jq3BHerFdp2djDlqX9PbBGRMvRdkHRZynXfeD5nOoxDSvRM QGMqGWjkxsqLtGXG6xWhXjYH4GszzKJ4T6xfuxJSe79Swio3iaeliD6DCQSwUNTU0bfr Y0EXdlKcXci04T7S+sGtp40LXQACMuuqIfGBePxhIYDbZ18sX8djHX9WTWPB50Mv1SAw 2iBYlaBLG9IW3t1u2d4ej35TK5vXyNvWlyoiTGLjZfOoP0HMtdXu/D1l4E8bgkZ83l4E UXk8X3vQKehkLyzeDw9DoLNPhcXAidu/gfXbsov4Kjv9w8PadoKXmIG5adwk9SK1w67j qaiA== 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=775QpKYyZSRDluNsXQsYl1JGKCaqXBywx31XBPvGYEk=; b=obLSfsRVlpqJ6OrcMt3eGCCTpcwLjcjJfPQVtSW4ZAfSP6HDibyIzdLEpii8NwK2Xs o3hbXz8LHKxu7BTSub/TUwAgVmuWTWl5G3MfLcTU2wxIqBxafqbpdQaglr6iAON1KqWD uxsekaH7luwC+HlGcLgMlR78BEyI/8hR9ozEzk3QBi8esubZc1ugH53Y3ciNsmF3YMfa ZDPZteW5S79YmpjdwlAXYOH2dCyCknfaU1227v8zMAfld2zHVPokqAkYz29vMcOTgyLx uDlfc8oDxEvZbujFPpNkyJZx735bks9R3oFGt9Zo745BOdZle5NabcfjFJibkU+sLRtJ y02g== 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 z2si1601541pgu.92.2021.04.27.16.18.08; Tue, 27 Apr 2021 16:18:37 -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 S239563AbhD0XQk (ORCPT + 99 others); Tue, 27 Apr 2021 19:16:40 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:37004 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239561AbhD0XQi (ORCPT ); Tue, 27 Apr 2021 19:16:38 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id 5DC911F426B8 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 , =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH v3 09/13] selftests: futex2: Add wouldblock test Date: Tue, 27 Apr 2021 20:12:44 -0300 Message-Id: <20210427231248.220501-10-andrealmeid@collabora.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210427231248.220501-1-andrealmeid@collabora.com> References: <20210427231248.220501-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 wouldblock file to test the same mechanism for futex2. Signed-off-by: André Almeida --- .../futex/functional/futex_wait_wouldblock.c | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c index 0ae390ff8164..ed3660090907 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c +++ b/tools/testing/selftests/futex/functional/futex_wait_wouldblock.c @@ -12,6 +12,7 @@ * * HISTORY * 2009-Nov-14: Initial version by Gowrishankar + * 2021-Feb-5: Add futex2 test by André * *****************************************************************************/ @@ -21,7 +22,7 @@ #include #include #include -#include "futextest.h" +#include "futex2test.h" #include "logging.h" #define TEST_NAME "futex-wait-wouldblock" @@ -39,6 +40,7 @@ void usage(char *prog) int main(int argc, char *argv[]) { struct timespec to = {.tv_sec = 0, .tv_nsec = timeout_ns}; + struct timespec64 to64; futex_t f1 = FUTEX_INITIALIZER; int res, ret = RET_PASS; int c; @@ -61,18 +63,41 @@ int main(int argc, char *argv[]) } ksft_print_header(); - ksft_set_plan(1); + ksft_set_plan(2); ksft_print_msg("%s: Test the unexpected futex value in FUTEX_WAIT\n", basename(argv[0])); info("Calling futex_wait on f1: %u @ %p with val=%u\n", f1, &f1, f1+1); res = futex_wait(&f1, f1+1, &to, FUTEX_PRIVATE_FLAG); if (!res || errno != EWOULDBLOCK) { - fail("futex_wait returned: %d %s\n", + ksft_test_result_fail("futex_wait returned: %d %s\n", res ? errno : res, res ? strerror(errno) : ""); ret = RET_FAIL; + } else { + ksft_test_result_pass("futex_wait wouldblock succeeds\n"); } - print_result(TEST_NAME, ret); + /* setting absolute 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 with val=%u\n", f1, &f1, f1+1); + res = futex2_wait(&f1, f1+1, FUTEX_32, &to64); + if (!res || errno != EWOULDBLOCK) { + ksft_test_result_fail("futex2_wait returned: %d %s\n", + res ? errno : res, res ? strerror(errno) : ""); + ret = RET_FAIL; + } else { + ksft_test_result_pass("futex2_wait wouldblock succeeds\n"); + } + + ksft_print_cnts(); return ret; } -- 2.31.1