From patchwork Sun Oct 27 15:46:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Crowe X-Patchwork-Id: 1185042 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-511862-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=mcrowe.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="FI/K3lTb"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mcrowe.com header.i=@mcrowe.com header.b="l7xXXyFf"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 471Mhx4hV7z9sP4 for ; Mon, 28 Oct 2019 02:49:05 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; q=dns; s=default; b=N8W H37BqE2e6WEF07zZKqHmNJHD4H6vdVh2ft02rRfn1nkUEaW2sa44a9GA/AB2EkHA OJCHqmfC1AQRFZmHycxgZX1OV5UUKV+2mcMpYCmsd0D08VLAMhAqcrmiQbZvj/YX gqRZQ1N92rPF/axyDtP6vfwG5yPSBrKCDnmoYW88= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=default; bh=kCmXvoAko RjHPLKULG1eJUY4GkE=; b=FI/K3lTbV+6CJuPIoE+X6DgMWpB9pmriya8pu7DVB J9PW/DO/9R4lTR3g7k8knSIezS81sLMMLTB7KeH9CAT3XpAGtppxOwjMbqOvMcYE SkbfGN+3D4lQCs/Hw8AjsZD6ZtDBDWu9M+UweHExb5GWDVMlvPipZleH9r4WWcuC 3M= Received: (qmail 95039 invoked by alias); 27 Oct 2019 15:47:04 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 94518 invoked by uid 89); 27 Oct 2019 15:47:01 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=properly, HX-Languages-Length:2645, warp, whilst X-HELO: avasout03.plus.net Received: from avasout03.plus.net (HELO avasout03.plus.net) (84.93.230.244) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 27 Oct 2019 15:46:59 +0000 Received: from deneb ([80.229.24.9]) by smtp with ESMTP id OkkoieIUmtvkXOkkpihKUR; Sun, 27 Oct 2019 15:46:57 +0000 X-Clacks-Overhead: "GNU Terry Pratchett" X-CM-Score: 0.00 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mcrowe.com; s=20191005; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description; bh=9S2mIPLMdjHp1/R4NIit2rd5swqiFZE0aCMURMebkWc=; b=l7xXX yFfzNWe1Qyz7gyFpL8NHZkNE2v4i0DKUd1CmQZe8rcujpI7bUjnhtXceC00AyKmbQ+pD2IIPrL0ZO /A5jXKx05dFgFgJvaCSbcQU8L46v1/i0pBhFyWMRZ43pqhPBP5Y3r3mEXiALLiYEvlc7eIdgtFcX5 F6CeOVV9mj4asWrn8AoMxH+wx5jgrR13nNYqC/0EMojGExV6sjyGA8miss8hqm9TYsCEAKxdPWa4w +xsOTTA+vNG8Xu3IeinqU78tFu5fUvwzd4ZlQKx9zL1Bzb0rWfaDuKTlzLHxajPyErgGboo+qT8R3 XxGZItleOVmD/EF2K7DFWTjTTJWkQ==; Received: from mac by deneb with local (Exim 4.92) (envelope-from ) id 1iOkkf-0005PV-74; Sun, 27 Oct 2019 15:46:45 +0000 From: Mike Crowe To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Mike Crowe Subject: [PATCH v4 1/7] libstdc++: Improve async test Date: Sun, 27 Oct 2019 15:46:24 +0000 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Add tests for waiting for the future using both std::chrono::steady_clock and std::chrono::system_clock in preparation for dealing with those clocks properly in futex.cc. * libstdc++-v3/testsuite/30_threads/async/async.cc (test02): Test steady_clock with std::future::wait_until. (test03): Add new test templated on clock type waiting for future associated with async to resolve. (main): Call test03 to test both system_clock and steady_clock. --- libstdc++-v3/testsuite/30_threads/async/async.cc | 33 +++++++++++++++++- 1 file changed, 33 insertions(+) diff --git a/libstdc++-v3/testsuite/30_threads/async/async.cc b/libstdc++-v3/testsuite/30_threads/async/async.cc index 851925b..1b6e2ff 100644 --- a/libstdc++-v3/testsuite/30_threads/async/async.cc +++ b/libstdc++-v3/testsuite/30_threads/async/async.cc @@ -51,17 +51,50 @@ void test02() VERIFY( status == std::future_status::timeout ); status = f1.wait_until(std::chrono::system_clock::now()); VERIFY( status == std::future_status::timeout ); + status = f1.wait_until(std::chrono::steady_clock::now()); + VERIFY( status == std::future_status::timeout ); l.unlock(); // allow async thread to proceed f1.wait(); // wait for it to finish status = f1.wait_for(std::chrono::milliseconds(0)); VERIFY( status == std::future_status::ready ); status = f1.wait_until(std::chrono::system_clock::now()); VERIFY( status == std::future_status::ready ); + status = f1.wait_until(std::chrono::steady_clock::now()); + VERIFY( status == std::future_status::ready ); +} + +// This test is prone to failures if run on a loaded machine where the +// kernel decides not to schedule us for several seconds. It also +// assumes that no-one will warp CLOCK whilst the test is +// running when CLOCK is std::chrono::system_clock. +template +void test03() +{ + auto const start = CLOCK::now(); + future f1 = async(launch::async, []() { + std::this_thread::sleep_for(std::chrono::seconds(2)); + }); + std::future_status status; + + status = f1.wait_for(std::chrono::milliseconds(500)); + VERIFY( status == std::future_status::timeout ); + + status = f1.wait_until(start + std::chrono::seconds(1)); + VERIFY( status == std::future_status::timeout ); + + status = f1.wait_until(start + std::chrono::seconds(5)); + VERIFY( status == std::future_status::ready ); + + auto const elapsed = CLOCK::now() - start; + VERIFY( elapsed >= std::chrono::seconds(2) ); + VERIFY( elapsed < std::chrono::seconds(5) ); } int main() { test01(); test02(); + test03(); + test03(); return 0; }