From patchwork Sat Sep 28 08:44:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Crowe X-Patchwork-Id: 1168825 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-509766-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none 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="uq+ioq4E"; 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 46gMnS2xsSz9sP6 for ; Sat, 28 Sep 2019 18:50:36 +1000 (AEST) 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=oXW gKzIMCZj522h011eKABnFCnmb5O7Thz4i7iWlj46B2oHOF03BW6/xVoFFyrNaKdJ Tevd00pQzEdU8bNmfMyTijKU4NNrteYTW2Xf41rfyjUCBElvU5gXODH18x92Uwt3 qH4LW0znevOBt33j0kjM9ZFeJrJ7DJbelmM4rSD0= 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=uHbsfbbTN ZaUs0ll82iR52DjyGU=; b=uq+ioq4Eh/r4aF1RKjHFQuRALGwp0+TPuq5mDO0aA 5+eNODwLv/1txEDMTb6MDTxzeC8zKaBfOLWqn/QKoWbZUFqjZXidSM4udJ6TT4Nt BfJbSHQtXIw6t4owb0YZG4jgMMbTVAZSdGzqMGR/eWMNVzErF/ZUSZiGc5iuz3Ej i0= Received: (qmail 109623 invoked by alias); 28 Sep 2019 08:48:44 -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 109541 invoked by uid 89); 28 Sep 2019 08:48:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT autolearn=ham version=3.3.1 spammy= X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (209.51.188.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 28 Sep 2019 08:48:41 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iE8P8-0000RR-Ep for gcc-patches@gcc.gnu.org; Sat, 28 Sep 2019 04:48:39 -0400 Received: from avasout06.plus.net ([212.159.14.18]:58341) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iE8P8-00007q-8d for gcc-patches@gcc.gnu.org; Sat, 28 Sep 2019 04:48:38 -0400 Received: from deneb ([80.229.24.9]) by smtp with ESMTP id E8MDikL0qDGRHE8MEiiJKr; Sat, 28 Sep 2019 09:45:38 +0100 X-Clacks-Overhead: "GNU Terry Pratchett" X-CM-Score: 0.00 Received: from mac by deneb with local (Exim 4.92) (envelope-from ) id 1iE8Lb-0006Pk-P5; Sat, 28 Sep 2019 09:44:59 +0100 From: Mike Crowe To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Mike Crowe Subject: [PATCH 02/11] libstdc++ testsuite: Add timed_mutex::try_lock_until test Date: Sat, 28 Sep 2019 09:44:41 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 212.159.14.18 I was unable to find an existing tests for timed_mutex::try_lock_until and recursive_timed_mutex::try_lock_until timing out. It would have been easier to add a single templated test, but since these classes are tested in separate directories I've created two separate tests. * testsuite/30_threads/timed_mutex/try_lock_until/3.cc: New file. Ensure that timed_mutex::try_lock_until actually times out after the specified time when using both system_clock and steady_clock. * testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc: Likewise but for recursive_timed_mutex. --- libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 148 insertions(+) create mode 100644 libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc create mode 100644 libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc diff --git a/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc b/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc new file mode 100644 index 0000000..4f0b0b5 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc @@ -0,0 +1,74 @@ +// { dg-do run } +// { dg-options "-pthread" } +// { dg-require-effective-target c++14 } +// { dg-require-effective-target pthread } +// { dg-require-gthreads "" } + +// Copyright (C) 2013-2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + + +#include +#include +#include +#include + +template +void test() +{ + typedef std::recursive_timed_mutex mutex_type; + + try + { + mutex_type m; + m.lock(); + bool b; + + std::thread t([&] { + try + { + using namespace std::chrono; + const auto timeout = 100ms; + const auto start = clock_type::now(); + const auto b = m.try_lock_until(start + timeout); + const auto t = clock_type::now() - start; + VERIFY( !b ); + VERIFY( t >= timeout ); + } + catch (const std::system_error& e) + { + VERIFY( false ); + } + }); + t.join(); + m.unlock(); + } + catch (const std::system_error& e) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test(); + test(); +} diff --git a/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc b/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc new file mode 100644 index 0000000..69d1ea5 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/timed_mutex/try_lock_until/3.cc @@ -0,0 +1,74 @@ +// { dg-do run } +// { dg-options "-pthread" } +// { dg-require-effective-target c++14 } +// { dg-require-effective-target pthread } +// { dg-require-gthreads "" } + +// Copyright (C) 2013-2019 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + + +#include +#include +#include +#include + +template +void test() +{ + typedef std::timed_mutex mutex_type; + + try + { + mutex_type m; + m.lock(); + bool b; + + std::thread t([&] { + try + { + using namespace std::chrono; + const auto timeout = 100ms; + const auto start = clock_type::now(); + const auto b = m.try_lock_until(start + timeout); + const auto t = clock_type::now() - start; + VERIFY( !b ); + VERIFY( t >= timeout ); + } + catch (const std::system_error& e) + { + VERIFY( false ); + } + }); + t.join(); + m.unlock(); + } + catch (const std::system_error& e) + { + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } +} + +int main() +{ + test(); + test(); +}