Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5022448pxb; Mon, 15 Feb 2021 07:33:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzChwBYhy/3IxmGzXIMSiayjeP0cJXGcHKJOBrVISCaMpvHnac9xgycA2SwVoKOgTmqcE5t X-Received: by 2002:a17:906:3bc3:: with SMTP id v3mr1038979ejf.155.1613403227053; Mon, 15 Feb 2021 07:33:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613403227; cv=none; d=google.com; s=arc-20160816; b=kcX6rSKbQyv9jHlsutO4Brduqb4tfx4epz66iIOkysr9kIE25bd9UssMym1BWv/x1U p0+UNe31amneEoWMooROzWmAKBDX7TyQyQW47eiK09+M02Y7GcXY+GmijOaZ8cW3xV2K 1WqqBGlnL7Tmj/ofqg9eqpi0/vXmisvEO9Z5akL+agOfc15xLaOBi40IF7VfAY0fpMag 7hv6z2FMcM6hRfeR1nZqwobuAWvMVlu2pgcElldn35HLGmrjkupHaW0DJ3NP0MM80oob ZyfkIDwcq3DArXt/objSGv9uWUoDEUhj1RQ8WUhEKj+lOC0mvPowHU3hGMSN/wO10IAO ei3w== 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=nXytw48kldSLmTwEo56TGFVCCIi8WngOfRW8idmN2Tw=; b=I1vpc7606vRWK3q1mUxszx8liwJbr0Vov+9XgIjmpoAYXpg447GTGfy1LNLA4ihnKC E02szjaRzpFJXMEddxUnQUaC3J9ECuKghQHGg3L9Uld5s1BWF+kOkNeO1POPXf4C7PTE cajnhiCWsssU43kdZLwK9AO2GcMKMlleOqh98g/1Wgm/ptza0rzvI60ou6jI0AeByDd0 mfKZy1GWiPH8DgoRkfLWEdCzrb5Lop91IWjHLCDRBDvef3vD5BSpBU10n3cc3ubcLdVZ sZoZVnbTP/l7cVWsfqOowSwTHx9rofDzOz5RH/3uHPDoJive//y/l/w/qOmYT/ffHMT4 phsg== 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 h25si5096696ejk.416.2021.02.15.07.33.23; Mon, 15 Feb 2021 07:33:47 -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 S231195AbhBOPcY (ORCPT + 99 others); Mon, 15 Feb 2021 10:32:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbhBOP0F (ORCPT ); Mon, 15 Feb 2021 10:26:05 -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 AC627C061793; Mon, 15 Feb 2021 07:25:23 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id BB5CE1F44F1F 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 09/13] selftests: futex2: Add wouldblock test Date: Mon, 15 Feb 2021 12:24:00 -0300 Message-Id: <20210215152404.250281-10-andrealmeid@collabora.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152404.250281-1-andrealmeid@collabora.com> References: <20210215152404.250281-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.30.1