From patchwork Fri Oct 19 14:25:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 986834 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=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-96533-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="Inc31cjL"; 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 42c7Vr6Jcxz9sDJ for ; Sat, 20 Oct 2018 01:25:40 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=qpfML9OqoN0d3c+PDoq/AucEiWmW/ hBEJi6M//FutoItZpBQX17VYlJfK2TL8bH2yI5YaKe4Gp+oBAf0hCNjZjrBwnNsA tZdo+/4u6S9fuCL7xHUjLeC8ZkyEqdhYgefFKSDj/IzwfJEsy0tkrJxlZf5gb3L1 d4PhZIkzxTS3Zc= 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:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=ke79XYDzjvpgGdLIGCpo0rPiFKk=; b=Inc 31cjL91hGVyqdxA1Ndl6EtbPK0hgX1AX56cT0XQPqiYCITdQAEzOV+ck10cqCDrV 1wPuyd3j4CM9I/qk99sWmVJl0OI6mJdltS8P95TxbiNo5U1yQlWHVoQjGFQVzJp+ 5dWBJTrVdp6KT4IZyKBlBnn2E0HWMTfcdxf6rI+Q= Received: (qmail 99376 invoked by alias); 19 Oct 2018 14:25:35 -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 99361 invoked by uid 89); 19 Oct 2018 14:25:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=EST, Vancouver, vancouver, 1088 X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] time/tst-mktime2: Improve test error reporting Date: Fri, 19 Oct 2018 16:25:29 +0200 Message-ID: <87r2gm9fom.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 2018-10-19 Florian Weimer * time/tst-mktime2.c (N_STRINGS): Remove. (set_timezone): New function. (spring_forward_gap): Call it. Use FAIL_EXIT1. (mktime_test1): Report localtime failure and check errno value. Use TEST_COMPARE. (irix_6_4_bug, bigtime_test): Use TEST_COMPARE. (do_test): Remove alarm call. Use set_timezone and array_length. diff --git a/time/tst-mktime2.c b/time/tst-mktime2.c index c41db3e3b7..09f85134d2 100644 --- a/time/tst-mktime2.c +++ b/time/tst-mktime2.c @@ -1,8 +1,12 @@ /* Test program from Paul Eggert and Tony Leneis. */ +#include +#include #include -#include +#include #include +#include +#include #include /* True if the arithmetic type T is signed. */ @@ -34,7 +38,14 @@ static const char *tz_strings[] = (const char *) 0, "GMT0", "JST-9", "EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00" }; -#define N_STRINGS ((int) (sizeof (tz_strings) / sizeof (tz_strings[0]))) + +static void +set_timezone (const char *tz) +{ + printf ("info: setting TZ=%s\n", tz); + if (setenv ("TZ", tz, 1) != 0) + FAIL_EXIT1 ("setenv: %m"); +} /* Fail if mktime fails to convert a date in the spring-forward gap. Based on a problem report from Andreas Jaeger. */ @@ -48,7 +59,7 @@ spring_forward_gap (void) instead of "TZ=America/Vancouver" in order to detect the bug even on systems that don't support the Olson extension, or don't have the full zoneinfo tables installed. */ - setenv ("TZ", "PST8PDT,M4.1.0,M10.5.0", 1); + set_timezone ("PST8PDT,M4.1.0,M10.5.0"); tm.tm_year = 98; tm.tm_mon = 3; @@ -58,15 +69,22 @@ spring_forward_gap (void) tm.tm_sec = 0; tm.tm_isdst = -1; if (mktime (&tm) == (time_t)-1) - exit (1); + FAIL_EXIT1 ("mktime: %m"); } static void mktime_test1 (time_t now) { struct tm *lt = localtime (&now); - if (lt && mktime (lt) != now) - exit (2); + if (lt == NULL) + { + /* For extreme input values, it is expected that localtime fails + with EOVERFLOW. */ + printf ("info: localtime (%lld) failed: %m\n", (long long int) now); + TEST_COMPARE (errno, EOVERFLOW); + return; + } + TEST_COMPARE (mktime (lt), now); } static void @@ -90,8 +108,8 @@ irix_6_4_bug (void) tm.tm_sec = 0; tm.tm_isdst = -1; mktime (&tm); - if (tm.tm_mon != 2 || tm.tm_mday != 31) - exit (3); + TEST_COMPARE (tm.tm_mon, 2); + TEST_COMPARE (tm.tm_mday, 31); } static void @@ -105,18 +123,16 @@ bigtime_test (int j) if (now != (time_t) -1) { struct tm *lt = localtime (&now); - if (! (lt - && lt->tm_year == tm.tm_year - && lt->tm_mon == tm.tm_mon - && lt->tm_mday == tm.tm_mday - && lt->tm_hour == tm.tm_hour - && lt->tm_min == tm.tm_min - && lt->tm_sec == tm.tm_sec - && lt->tm_yday == tm.tm_yday - && lt->tm_wday == tm.tm_wday - && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst) - == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst)))) - exit (4); + TEST_COMPARE (lt->tm_year, tm.tm_year); + TEST_COMPARE (lt->tm_mon, tm.tm_mon); + TEST_COMPARE (lt->tm_mday, tm.tm_mday); + TEST_COMPARE (lt->tm_hour, tm.tm_hour); + TEST_COMPARE (lt->tm_min, tm.tm_min); + TEST_COMPARE (lt->tm_sec, tm.tm_sec); + TEST_COMPARE (lt->tm_yday, tm.tm_yday); + TEST_COMPARE (lt->tm_wday, tm.tm_wday); + TEST_COMPARE (lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst, + tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst); } } @@ -127,17 +143,13 @@ do_test (void) int i; unsigned int j; - setenv ("TZ", "America/Sao_Paulo", 1); - /* This test makes some buggy mktime implementations loop. - Give up after 60 seconds; a mktime slower than that - isn't worth using anyway. */ - alarm (60); + set_timezone ("America/Sao_Paulo"); delta = TIME_T_MAX / 997; /* a suitable prime number */ - for (i = 0; i < N_STRINGS; i++) + for (i = 0; i < array_length (tz_strings); i++) { - if (tz_strings[i]) - setenv ("TZ", tz_strings[i], 1); + if (tz_strings[i] != NULL) + set_timezone (tz_strings[i]); for (t = 0; t <= TIME_T_MAX - delta; t += delta) mktime_test (t); @@ -154,5 +166,4 @@ do_test (void) return 0; } -#define TEST_FUNCTION do_test () -#include "../test-skeleton.c" +#include