From patchwork Thu Sep 4 22:05:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arjun Shankar X-Patchwork-Id: 386025 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 4E48E1400A3 for ; Fri, 5 Sep 2014 08:04:30 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; q=dns; s=default; b=uIWOQCCuNa5AXUvkHVP+CRCG+X0U9 Fy0eQkD09IF5ALrAzQxNLELHilQGncnHZwYeL4SRJJq+u/SkVhItrekkdj3lYEEt td1ZWCwWiPNIYDP7qOpG012Gj/qAvllwrgNem28xTGWDps3AoFQxJ2jE8gyXvowT OEYSESnNrF6KzY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; s=default; bh=BuYMzOCZaHLoMbLaxyNy2h72SPI=; b=gTd 7GI4px4xCLP60t3I3WdI3uIpEG1EmYmcMO6B5RMJ1AlTFL4uNO4NIUkpnxQgCTgF ZJ168Biden7wWkKNq7i/1D4sDtMnmCKXr112KF/YZ3LrfDmLs2PrGGlmKT+iWl4B hkIwUN9ufztr9SPjOjJuoUTGwD2sbsRs6o+xa5kw= Received: (qmail 20276 invoked by alias); 4 Sep 2014 22:04:23 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 20265 invoked by uid 89); 4 Sep 2014 22:04:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: arati.lostca.se Date: Fri, 5 Sep 2014 00:05:51 +0200 From: Arjun Shankar To: libc-alpha@sourceware.org Subject: [PATCH] New test for ftime Message-ID: <20140905000551.537b0597@zion> Mime-Version: 1.0 This test verifies the sanity of ftime and exposes bugs such as BZ #16430. It takes between one and two seconds to finish. ChangeLog: 2014-09-04 Arjun Shankar * time/tst-ftime.c: New test. * time/Makefile (tests): Add tst-ftime. --- time/Makefile | 2 +- time/tst-ftime.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 time/tst-ftime.c diff --git a/time/Makefile b/time/Makefile index a07c041..55c1de8 100644 --- a/time/Makefile +++ b/time/Makefile @@ -37,7 +37,7 @@ aux := era alt_digit lc-time-cleanup tests := test_time clocktest tst-posixtz tst-strptime tst_wcsftime \ tst-getdate tst-mktime tst-mktime2 tst-ftime_l tst-strftime \ tst-mktime3 tst-strptime2 bug-asctime bug-asctime_r bug-mktime1 \ - tst-strptime3 bug-getdate1 tst-strptime-whitespace + tst-strptime3 bug-getdate1 tst-strptime-whitespace tst-ftime include ../Rules diff --git a/time/tst-ftime.c b/time/tst-ftime.c new file mode 100644 index 0000000..9345915f --- /dev/null +++ b/time/tst-ftime.c @@ -0,0 +1,51 @@ +/* Copyright (C) 2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +/* The test takes between 1 and 2 seconds. */ +#define TIMEOUT 3 + +static int +do_test (void) +{ + struct timeb prev, curr = {.time = 0, .millitm = 0}; + int sec = 0; + + while (sec != 3) + { + prev = curr; + + if (ftime (&curr)) + errx (1, "ftime returned an error"); + + if (curr.time < prev.time) + errx (1, "ftime's time flowed backwards"); + + if (curr.time == prev.time + && curr.millitm < prev.millitm) + errx (1, "ftime's millitm flowed backwards"); + + if (curr.time > prev.time) + sec ++; + } + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c"