Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1613515ybt; Thu, 9 Jul 2020 11:02:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2hajWqQhHVzEYeWZYsQdfoKpYQ51wa1iXbDdi/pxfcLgaBrGASOarAwThdq1z/LgisyQ4 X-Received: by 2002:a17:906:c155:: with SMTP id dp21mr55313255ejc.92.1594317732483; Thu, 09 Jul 2020 11:02:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594317732; cv=none; d=google.com; s=arc-20160816; b=fISlk2ueEBAegjZOBHFOy5Ru9yFymIfjBJZeW/MJb1BcVGueahFypg792LulF0adhz PcAitGxwImr4IBvBYXQQ2RUeIlaEDJpvM03qrenGjyR1ad9kC1zE7i9d/lDPiUsfnrnG 40nxqQNU16iJJ5tFnrte1NXOMJEkGBHiAKUXAuNwStJ76BCgMXzgNYhjrK0OzBhEH38n MFXoeW8CeK0Fks1DntD1VOBkinAFwkhbniJtHjkPsEkSYrj0YbwRZAuKBMFOL5Y+mKlg jxtSjC6KGwa+qE7Vhb+BO6wJlHQQvrvVbTiZMq8nC9sz3njShMy0ckvz+8eeT1GXP4Hn KVMw== 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=Lt2LkzyGLgjqsGDk9z1mT5PKJ9wo4DNKRKan35VB3Ms=; b=mzCo94hOL3v1qxZpyazDwjukCVCSiejkLX3DZz9h7eOqEQVW4MpT3nulkqOoeVh4iH Gn7Hf4JN/TxZMNCf/IIxhnldbookVnoYzNARr6bW7FDtCxq6D/aE3LRZkmJZUINQOOJQ O7EAmRh+3CNEvqpE4KtH7SfqZp6I20+BzaDZaBcfPBhMQjU9Xw7VYVXq0PHMPT/oMrHa 1pDo3pvHvALMKq/GAvQOYuFghR/qUGzG3ez/FziQNPhSiWRKtYqEsjHuowW/8rVFiQPh D9cHNm6cgMEge93Bm10GDXgk4UJZf7cyh6SsYxyBDfgk/zEfl03VjH0hbbe/8G6HAVsd fEdg== 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 be27si2357507edb.50.2020.07.09.11.01.48; Thu, 09 Jul 2020 11:02:12 -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 S1727908AbgGISAz (ORCPT + 99 others); Thu, 9 Jul 2020 14:00:55 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:32786 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726936AbgGISAy (ORCPT ); Thu, 9 Jul 2020 14:00:54 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tonyk) with ESMTPSA id 278DA2A65F5 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 3/4] selftests: futex: Add futex2 timeout test Date: Thu, 9 Jul 2020 14:59:20 -0300 Message-Id: <20200709175921.211387-4-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 timeout file to test the same mechanism for futex2. Signed-off-by: André Almeida --- .../futex/functional/futex_wait_timeout.c | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 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..d2e7ae18985b 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-Jul-9: 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,7 +41,8 @@ void usage(char *prog) int main(int argc, char *argv[]) { futex_t f1 = FUTEX_INITIALIZER; - struct timespec to; + struct timespec to = {.tv_sec = 0, .tv_nsec = timeout_ns}; + struct timespec64 to64; int res, ret = RET_PASS; int c; @@ -65,22 +67,40 @@ 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); - /* initialize timeout */ - to.tv_sec = 0; - to.tv_nsec = timeout_ns; - 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"); + } + + /* 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\n", f1, &f1); + res = futex2_wait(&f1, f1, FUTEX_PRIVATE_FLAG | FUTEX_32, &to64); + 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