{"id":817383,"url":"http://patchwork.ozlabs.org/api/patches/817383/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/20170922081728.32508-5-mac@mcrowe.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170922081728.32508-5-mac@mcrowe.com>","list_archive_url":null,"date":"2017-09-22T08:17:28","name":"[RFC,4/4] Extra async tests, not for merging","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"2f82b1337aa9e38e6490536219d59593fb87a476","submitter":{"id":66786,"url":"http://patchwork.ozlabs.org/api/people/66786/?format=json","name":"Mike Crowe","email":"mac@mcrowe.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/20170922081728.32508-5-mac@mcrowe.com/mbox/","series":[{"id":4567,"url":"http://patchwork.ozlabs.org/api/series/4567/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=4567","date":"2017-09-22T08:17:24","name":"Make std::future::wait_* use std::chrono::steady_clock when required","version":1,"mbox":"http://patchwork.ozlabs.org/series/4567/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/817383/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/817383/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-return-462759-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-462759-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"ScfUFgqu\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xz5yX0082z9s9Y\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 22 Sep 2017 18:20:35 +1000 (AEST)","(qmail 29583 invoked by alias); 22 Sep 2017 08:18:30 -0000","(qmail 29387 invoked by uid 89); 22 Sep 2017 08:18:30 -0000","from relay101b.appriver.com (HELO relay.appriver.com)\n\t(207.97.230.15) by sourceware.org\n\t(qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tFri, 22 Sep 2017 08:18:28 +0000","from [213.210.30.29] (HELO elite.brightsign) by relay.appriver.com\n\t(CommuniGate Pro SMTP 6.1.7) with ESMTPS id 202112913;\n\tFri, 22 Sep 2017 04:18:21 -0400","from chuckie.brightsign ([fd44:d8b8:cab5:cb01::19]\n\thelo=chuckie)\tby elite.brightsign with esmtp (Exim\n\t4.89)\t(envelope-from <mcrowe@brightsign.biz>)\tid\n\t1dvJAC-000B0P-P5; Fri, 22 Sep 2017 09:18:20 +0100","from mac by chuckie with local (Exim 4.89)\t(envelope-from\n\t<mcrowe@brightsign.biz>)\tid 1dvJAC-0008Ty-OU;\n\tFri, 22 Sep 2017 09:18:20 +0100"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:from\n\t:to:cc:subject:date:message-id:in-reply-to:references; q=dns; s=\n\tdefault; b=vbmwjSktqTT9zMCOXRudbkUgJlJaEXXQDSoDIpRePthw+S9Eh25h6\n\tY0sm+5h4+HR83EKLvr9myhrRRWtJrLgkq8BRbuYU8VxIICt5gYYs5VtjRBdNP97t\n\tUCRmzaPGLdIf8fi5WgX+GGYNrZ+J9cYfVMBF0LQHeuaQ42enNA8Qbg=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:from\n\t:to:cc:subject:date:message-id:in-reply-to:references; s=\n\tdefault; bh=TKV5WFjnzI94iPvetMrXo0qyc5M=; b=ScfUFgquZy2X7vGyBlOO\n\tVpKcSmsEeXRorG1KHGafE3K9BpeAlilKQgb0i/YCO2paWuIUufWlarvxEimqtlhl\n\touwj4VFaEz3+H0adW/D3PlyYwIYitZKIDEcCxrDVbrlvDxQYZr8sKq2oe12/jsAm\n\tEWeyYh/MZAlw5sseEUsRZKo=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-26.6 required=5.0 tests=BAYES_00, GIT_PATCH_0,\n\tGIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3,\n\tKAM_LAZY_DOMAIN_SECURITY,\n\tRCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=","X-Spam-User":"qpsmtpd, 2 recipients","X-HELO":"relay.appriver.com","X-Note":["This Email was scanned by AppRiver SecureTide","SecureTide Build: 7/20/2017 1:24:22 PM UTC (2.6.20.0)","Filtered by 10.238.11.162","ICH-CT/SI:0-1052/SG:1 9/22/2017 4:18:16 AM","TCH-CT/SI:0-25/SG:1 9/22/2017 4:18:16 AM","Spam Tests Failed:","User Rule Hits:","Global Rule Hits: G281 G282 G283 G284 G288 G289 G418","Encrypt Rule Hits:","Mail Class: VALID","Headers Injected"],"X-Note-AR-ScanTimeLocal":"09/22/2017 4:18:21 AM","X-Policy":["brightsign.biz  - brightsign.biz","brightsign.biz  - brightsign.biz","brightsign.biz  - brightsign.biz"],"X-Primary":"mcrowe@brightsign.biz","X-Virus-Scan":"V-","X-Note-SnifferID":"0","X-GBUdb-Analysis":"0, 213.210.30.29, Ugly c=0.524912 p=-0.877301 Source Normal","X-Signature-Violations":"0-0-0-6809-c","X-Country-Path":"->->United Kingdom->United States","X-Note-Sending-IP":"213.210.30.29","X-Note-Reverse-DNS":"elite.brightsigndigital.co.uk","X-Note-Return-Path":"mcrowe@brightsign.biz","From":"Mike Crowe <mac@mcrowe.com>","To":"libstdc++@gcc.gnu.org,\tgcc-patches@gcc.gnu.org","Cc":"Mike Crowe <mac@mcrowe.com>","Subject":"[RFC PATCH 4/4] Extra async tests, not for merging","Date":"Fri, 22 Sep 2017 09:17:28 +0100","Message-Id":"<20170922081728.32508-5-mac@mcrowe.com>","In-Reply-To":"<20170922081728.32508-1-mac@mcrowe.com>","References":"<20170922081728.32508-1-mac@mcrowe.com>"},"content":"These tests show that changing the system clock has an effect on\nstd::future::wait_until when using std::chrono::system_clock but not when\nusing std::chrono::steady_clock. Unfortunately these tests have a number of\ndownsides:\n\n1. Nothing that is attempting to keep the clock set correctly (ntpd,\n   systemd-timesyncd) can be running at the same time.\n\n2. The test process requires the CAP_SYS_TIME capability.\n\n3. Other processes running concurrently may misbehave when the clock darts\n   back and forth.\n\n4. They are slow to run.\n\nAs such, I don't think they are suitable for merging. I include them here\nbecause I wanted to document how I had tested the changes in the previous\ncommits.\n---\n libstdc++-v3/testsuite/30_threads/async/async.cc | 76 ++++++++++++++++++++++++\n 1 file changed, 76 insertions(+)","diff":"diff --git a/libstdc++-v3/testsuite/30_threads/async/async.cc b/libstdc++-v3/testsuite/30_threads/async/async.cc\nindex 59905b4666f..0a3cb28fbda 100644\n--- a/libstdc++-v3/testsuite/30_threads/async/async.cc\n+++ b/libstdc++-v3/testsuite/30_threads/async/async.cc\n@@ -25,6 +25,7 @@\n \n #include <future>\n #include <testsuite_hooks.h>\n+#include <sys/time.h>\n \n using namespace std;\n \n@@ -94,11 +95,86 @@ void test03()\n   VERIFY( elapsed < std::chrono::seconds(20) );\n }\n \n+void perturb_system_clock(const std::chrono::seconds &seconds)\n+{\n+  struct timeval tv;\n+  if (gettimeofday(&tv, NULL))\n+    abort();\n+\n+  tv.tv_sec += seconds.count();\n+  if (settimeofday(&tv, NULL))\n+    abort();\n+}\n+\n+void work04()\n+{\n+  std::this_thread::sleep_for(std::chrono::seconds(10));\n+}\n+\n+// Ensure that advancing CLOCK_REALTIME doesn't make any difference\n+// when we're waiting on std::chrono::steady_clock.\n+void test04()\n+{\n+  auto const start = chrono::steady_clock::now();\n+  future<void> f1 = async(launch::async, &work04);\n+\n+  perturb_system_clock(chrono::seconds(20));\n+\n+  std::future_status status;\n+  status = f1.wait_for(std::chrono::seconds(4));\n+  VERIFY( status == std::future_status::timeout );\n+\n+  status = f1.wait_until(start + std::chrono::seconds(6));\n+  VERIFY( status == std::future_status::timeout );\n+\n+  status = f1.wait_until(start + std::chrono::seconds(12));\n+  VERIFY( status == std::future_status::ready );\n+\n+  auto const elapsed = chrono::steady_clock::now() - start;\n+  VERIFY( elapsed >= std::chrono::seconds(10) );\n+  VERIFY( elapsed < std::chrono::seconds(15) );\n+\n+  perturb_system_clock(chrono::seconds(-20));\n+}\n+\n+void work05()\n+{\n+  std::this_thread::sleep_for(std::chrono::seconds(5));\n+  perturb_system_clock(chrono::seconds(60));\n+  std::this_thread::sleep_for(std::chrono::seconds(5));\n+}\n+\n+// Ensure that advancing CLOCK_REALTIME does make a difference when\n+// we're waiting on std::chrono::system_clock.\n+void test05()\n+{\n+  auto const start = chrono::system_clock::now();\n+  auto const start_steady = chrono::steady_clock::now();\n+\n+  future<void> f1 = async(launch::async, &work05);\n+  future_status status;\n+  status = f1.wait_until(start + std::chrono::seconds(60));\n+  VERIFY( status == std::future_status::timeout );\n+\n+  auto const elapsed_steady = chrono::steady_clock::now() - start_steady;\n+  VERIFY( elapsed_steady >= std::chrono::seconds(5) );\n+  VERIFY( elapsed_steady < std::chrono::seconds(10) );\n+\n+  status = f1.wait_until(start + std::chrono::seconds(75));\n+  VERIFY( status == std::future_status::ready );\n+\n+  perturb_system_clock(chrono::seconds(-60));\n+}\n+\n int main()\n {\n   test01();\n   test02();\n   test03<std::chrono::system_clock>();\n   test03<std::chrono::steady_clock>();\n+  if (geteuid() == 0) {\n+    test04();\n+    test05();\n+  }\n   return 0;\n }\n","prefixes":["RFC","4/4"]}