Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp542196pxj; Thu, 3 Jun 2021 13:03:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybqKy98QJud4eB0rvQg11oGnW/6tn8t3b2zGAHGX3yUCJNBKm69TJkHfXzyQbLIE0wsGAM X-Received: by 2002:a50:ed82:: with SMTP id h2mr1160261edr.140.1622750609006; Thu, 03 Jun 2021 13:03:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622750608; cv=none; d=google.com; s=arc-20160816; b=Mcww2sl0cTAdpsYTW3hVZYWulfu7qSlKMPvvLpzWRVYi9PMuRwejiRG6WmtO5dMMq4 4jMVJXxQs2ZmDTR4xMKEmwEJs81U1gUqGBHTKCMtr2xbWm69fr7XpDXZ9hr6hpgCPKQ4 y/t1vXPzpp+abfIid5zwX8X6UUjsaf1/ib//CBUqt7XNVImcLct/8xIszf7yVVTkDP8f BYMV96yZAcjYGrTVcsdPHDo98LkRlbtK8kAqGfJIKj5PWR2dMkxKDVMIoLfZUErCCAEl 53MDneLykc+JuTg8ez6wKBbwbToKbyFiIabUMgRanEfRi0rJNl8FClfiuYYHwaI5Kvgp DBdQ== 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=nAdeHv+dYnRNoZma89igqDLRVhPjfshFQO3vlpKCJyA=; b=CfXjSnu/pJguzWldfb1+LHB3nY+BJuyA6rzEVGPExM8xvQpMlWZzPbPjGR818PYXOD G7pX2Opq2wMjhyavhPIoMRGC0OykeWiVJkGABhlPnFkbEyzVpDTm9lCInXt1TrkNRQg+ XMxTmeoSQVxLnunXpO7GzA882b9L7t7V7Fwrz0TJxjzdr5qs4DjXaNDXJvOpVVcBICvp 83dCP6pyuvdngAyi32WJdR4JaJPUtJpvFGjeQ+Co3UpljriVbmtXR5BqEondg06V/U6W EfZIhNR/NsxDiVw14Gg45HjRcBtdZcSyZGtxm5fyEGUbs9kQGEX+FMqw9PHyfgOg9RZF sWDg== 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 be14si2932775edb.452.2021.06.03.13.03.02; Thu, 03 Jun 2021 13:03: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 S230078AbhFCUDB (ORCPT + 99 others); Thu, 3 Jun 2021 16:03:01 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:53060 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230254AbhFCUC6 (ORCPT ); Thu, 3 Jun 2021 16:02:58 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id C50071F43475 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 10/15] selftests: futex2: Add wouldblock test Date: Thu, 3 Jun 2021 16:59:19 -0300 Message-Id: <20210603195924.361327-11-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 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..510a98320248 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\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\n"); + } + + ksft_print_cnts(); return ret; } -- 2.31.1