Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp689357ybg; Fri, 12 Jun 2020 11:56:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+Wxw7fKCoTTx7QIOVPpYjZ122C92g7/sOYjClZ3tgECdEJaYPnw3M2htP2X2WiZ5FkcXr X-Received: by 2002:aa7:d7ca:: with SMTP id e10mr13346152eds.45.1591988177548; Fri, 12 Jun 2020 11:56:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591988177; cv=none; d=google.com; s=arc-20160816; b=eOw/XM+hB6B+pj4z+IFNAaaOZLFFf4WOfO8NxDi7Jsyfp5D5TMNLiWIC9ujdmFaV+O jmxnEorcAossg6wuON+6Hq3nQdsZwnLgMZoWxFEAQjvy1LNPehw3080um86h3pY/6Pa7 Qm5eQbuYVxCpliBVbmS5wXNE7pa6NW9j71luBYu1I1epwsANipHIchARmYZ4aelrq5/Q hSz52tkVFRG4/PB2Q9ImoCiKhkuuaY3KkezYwL0WDfxmRDKo3Y/mbXz/iAaH/x0qecD5 azSwzbDz7liW9H1aFWi90DkCLhqbWFmLs7JbSOxIJ+81DcB9vZj8n7kYuDRkQcMNDWlo WoLQ== 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=xfCHjbrf2WonX+CpR8WVJIAcIf0i+NPYaR5QSCPwQII=; b=I2/9Lh9m1KI6iZ7hqHca8DOBoPEOb0s3v7hk6aPS+FV90lSPBqRv9oDXM5hXfaGnIP 93G1DY9lGc7dhYUdRWwVmyVf1xUSey299jxHa1DDnMiTPKdJ6bgYnGZGdkPQePZqL+KL VZgmbAX93k3cVgQ3ZHU1ZFOs9bUxHz2s+0BOOIQ1P1F5FfMJG7vD3w2EWNCFVITaw71Q lpfvBsWNKe+vrcUccRkGtZZ6t8vU6wjiXd5+xhUtgD7nvlJsoVVoWNGQD421RhQkMwBq g1HGe1fLW6WKfak7v0P1Qp5kWsGCcu+wWKEs/TENybCKaLsJEdL3Xdz749bbZKAZyUR7 rdnA== 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 a13si4371773ejb.241.2020.06.12.11.55.55; Fri, 12 Jun 2020 11:56:17 -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 S1726388AbgFLSvj (ORCPT + 99 others); Fri, 12 Jun 2020 14:51:39 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:37988 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726085AbgFLSvi (ORCPT ); Fri, 12 Jun 2020 14:51:38 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id D53412A57E9 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 Subject: [RFC 3/4] selftests: futex: Add futex2 timeout test Date: Fri, 12 Jun 2020 15:51:21 -0300 Message-Id: <20200612185122.327860-4-andrealmeid@collabora.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200612185122.327860-1-andrealmeid@collabora.com> References: <20200612185122.327860-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 timeout file to test the same mechanism for futex2. Signed-off-by: André Almeida --- .../futex/functional/futex_wait_timeout.c | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_wait_timeout.c b/tools/testing/selftests/futex/functional/futex_wait_timeout.c index ee55e6d389a3..e0b802fcb005 100644 --- a/tools/testing/selftests/futex/functional/futex_wait_timeout.c +++ b/tools/testing/selftests/futex/functional/futex_wait_timeout.c @@ -11,6 +11,7 @@ * * HISTORY * 2009-Nov-6: Initial version by Darren Hart + * 2020-Jun-11: Add futex2 test by André * *****************************************************************************/ @@ -20,7 +21,7 @@ #include #include #include -#include "futextest.h" +#include "futex2test.h" #include "logging.h" #define TEST_NAME "futex-wait-timeout" @@ -40,6 +41,7 @@ void usage(char *prog) int main(int argc, char *argv[]) { futex_t f1 = FUTEX_INITIALIZER; + time_t abs_to; struct timespec to; int res, ret = RET_PASS; int c; @@ -65,11 +67,17 @@ int main(int argc, char *argv[]) } ksft_print_header(); - ksft_set_plan(1); + ksft_set_plan(2); 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); + /* setting absolute timeout for futex2 */ + if (clock_gettime(CLOCK_MONOTONIC, &to)) + error("clock_gettime failed\n", errno); + + abs_to = (NSEC_PER_SEC * to.tv_sec) + to.tv_nsec + timeout_ns; + /* initialize timeout */ to.tv_sec = 0; to.tv_nsec = timeout_ns; @@ -77,10 +85,21 @@ int main(int argc, char *argv[]) info("Calling futex_wait on f1: %u @ %p\n", f1, &f1); res = futex_wait(&f1, f1, &to, FUTEX_PRIVATE_FLAG); if (!res || errno != ETIMEDOUT) { - fail("futex_wait returned %d\n", ret < 0 ? errno : ret); + ksft_test_result_fail("futex_wait returned %d\n", ret < 0 ? errno : ret); + ret = RET_FAIL; + } else { + ksft_test_result_pass("futex_wait timeout succeeds\n"); + } + + info("Calling futex2_wait on f1: %u @ %p\n", f1, &f1); + res = futex2_wait(&f1, f1, FUTEX_PRIVATE_FLAG | FUTEX_32, &abs_to); + if (!res || errno != ETIMEDOUT) { + ksft_test_result_fail("futex2_wait returned %d\n", ret < 0 ? errno : ret); ret = RET_FAIL; + } else { + ksft_test_result_pass("futex2_wait timeout succeeds\n"); } - print_result(TEST_NAME, ret); + ksft_print_cnts(); return ret; } -- 2.27.0