Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1615729ybt; Thu, 9 Jul 2020 11:04:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFTtb08FmdbOn9s1DE03V66neod4j12OEaTC/PWzeREdS7xxc7kWXhx1htXptwBCkiwafN X-Received: by 2002:a50:8e53:: with SMTP id 19mr57716312edx.185.1594317884573; Thu, 09 Jul 2020 11:04:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594317884; cv=none; d=google.com; s=arc-20160816; b=jWPX7oxXvMHhwn/Z9Jrbie4rJTS/2KCz0tlAd3G89lbUlYJTSTAXQRVcbdTzoKW8OM AXjeoN/Jb3+LRYYeJPXg5RVYBh3mWOAeQCg8hreZrhSGM1O5Hox9HeQpb0XxStlYTb9W iOX0x2dnmyGnihwA64mv7Pw3TpbNyA3MDUEsRZuoMQv+EuhPgISYRjwq373Jedf26Ujs EddTtUxHojXri7ap+kJQy85ndTv77h36r01LMAsXHfq3fN0suwRJpy0z2DHrISd2DsRw IDKvGUq3DF/FxVxf8kRKhugBE4fwuxJd3fCR2tFyfHpDkqk9zG3M9PaN5CbeBFeAkYFD NICw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=pK2ZDWIxEbRIT78a/IgKGty1E/pb4IL8pWGVf+QmmCQ=; b=k7XGWvTjIiIV72YNO+yclMhnT0tUOScaOPsElJLz1o/r/1pZRXh33Di/HfPFkZczCC N2O3L1FhGNkMyPrkICXV1g8wW0uaKx4U/7q0++HuDaDXI4HA7j2nJaJGiQR9WxG24N2Y ydLC5+BoK1ecotE2jlMTzWYL2AiGpy/469YCl0fzimFeItmIuXh+7AnNOeD7L7NJZz3R HZNDMcZn00cqk6BUx9UD37w1AxcxB5UEETTqxKNTBKvEp2Sscl3qQno1Cn7tqplEv4Aq Mv0QREujh5ogjbEJkD5qLQ18oIlySGncLVl07ajiyfX976lbncqQU89SPpvo/CeVvShh +V0A== 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 s24si2495395edw.69.2020.07.09.11.04.19; Thu, 09 Jul 2020 11:04:44 -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 S1728549AbgGISA7 (ORCPT + 99 others); Thu, 9 Jul 2020 14:00:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726936AbgGISA6 (ORCPT ); Thu, 9 Jul 2020 14:00:58 -0400 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 6C741C08C5CE; Thu, 9 Jul 2020 11:00:58 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id 9C1B42A65F9 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: linux-kernel@vger.kernel.org, tglx@linutronix.de, peterz@infradead.org Cc: krisman@collabora.com, kernel@collabora.com, andrealmeid@collabora.com, dvhart@infradead.org, mingo@redhat.com, pgriffais@valvesoftware.com, fweimer@redhat.com, libc-alpha@sourceware.org, malteskarupke@web.de, linux-api@vger.kernel.org, arnd@arndb.de Subject: [RFC v2 4/4] selftests: futex: Add futex2 wouldblock test Date: Thu, 9 Jul 2020 14:59:21 -0300 Message-Id: <20200709175921.211387-5-andrealmeid@collabora.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200709175921.211387-1-andrealmeid@collabora.com> References: <20200709175921.211387-1-andrealmeid@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org 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..8187f0754cd2 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 + * 2020-Jul-9: 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_PRIVATE_FLAG | 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.27.0