From patchwork Sat Dec 31 10:50:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 89418 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp6799747qgi; Sat, 31 Dec 2016 02:50:37 -0800 (PST) X-Received: by 10.98.150.206 with SMTP id s75mr47619842pfk.155.1483181437339; Sat, 31 Dec 2016 02:50:37 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id u90si59827333pfk.38.2016.12.31.02.50.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 31 Dec 2016 02:50:37 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-76456-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of libc-alpha-return-76456-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-76456-patch=linaro.org@sourceware.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:references:cc:from:message-id:date :mime-version:in-reply-to:content-type; q=dns; s=default; b=rxQa dzcYuQBeZeSeHBxKeCUJl9SoLD7wg9krE/YUFk64QbdHFXDOYgNU1WWVGvs/q3N5 AsCRcNlkgR/PTTszdpe46xbQjv46GqjtUBt2aA/JUqIqvXOSvKvsu3OJE+gfq/tE NVrTDWdJ3CfjQPf+lglhRmUGHoJe6OYarh1bsyQ= 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:subject:to:references:cc:from:message-id:date :mime-version:in-reply-to:content-type; s=default; bh=Kd4zgCmB/e iS4/uMBkEXCGl5dv0=; b=UkLnhLQiDdwnP8NLRMdIZiX0S3KjY0iFw6vCePfxeE rIRyR4KnVQgaM5iMGLu6h/oD94LpdHn+hFloHV2VOOezBarMUZ2o9kRGeGbQg0ac ZItQAc+PYJaJix8gFebFaoA+Xo5id9G/6kw6QvvNuxIYeOTMxSvQrxqcrKiQTGVF Y= Received: (qmail 128344 invoked by alias); 31 Dec 2016 10:50:27 -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 128327 invoked by uid 89); 31 Dec 2016 10:50:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.1 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=36, 8, 45, 6, UD:time.h, timespec X-HELO: mx1.redhat.com Subject: Re: [PATCH] support: Add support for delayed test failure reporting To: Adhemerval Zanella References: <372cbbc7-2396-12af-49e8-8bca20cae4ae@redhat.com> <60827736-0add-5bc9-0172-df1efa54ba8c@linaro.org> <1b88c2cd-04b8-3ffe-7ea0-6c9440aa8710@redhat.com> Cc: libc-alpha@sourceware.org From: Florian Weimer Message-ID: Date: Sat, 31 Dec 2016 11:50:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <1b88c2cd-04b8-3ffe-7ea0-6c9440aa8710@redhat.com> On 12/28/2016 02:36 PM, Florian Weimer wrote: > We might want to add implicit delayed error reporting to FAIL_EXIT1 > eventually, so that it works from subprocess as well. In that case, > this would introduce a circular dependency. This is what I had an in mind. Thanks, Florian support: Use support_record_failure consistently This causes more test programs to link in the support_record_failure function, which triggers an early call to mmap from an ELF constructor, but this should not have side effects intefering with the functionality actually under test (unlike, say, a call to malloc). 2016-12-31 Florian Weimer * support/check.h (FAIL_RET, FAIL_EXIT, FAIL_EXIT1): Document that test failures are recorded. * support/check.c (support_print_failure_impl): Call support_record_failure. (support_exit_failure_impl): Call support_record_failure if status indicates failure. * support/delayed_exit.c (delayed_exit_thread): Use FAIL_EXIT1. * support/xasprintf.c (xasprintf): Likewise. * support/xfork.c (xfork): Likewise. * support/xpthread_check_return.c (xpthread_check_return): Likewise. * support/xsocket.c (xsocket): Likeweise. * support/xwaitpid.c (xwaitpid): Likewise. * support/support_record_failure.c (struct test_failures): Adjust to coding style. * support/support_test_verify_impl.c (support_test_verify_impl): Adjust error messages. * support/tst-support_record_failure-2.sh (different_status): Adjust error messages. diff --git a/support/check.c b/support/check.c index 75fdf52..04d2503 100644 --- a/support/check.c +++ b/support/check.c @@ -21,6 +21,7 @@ #include #include #include +#include static void print_failure (const char *file, int line, const char *format, va_list ap) @@ -34,6 +35,7 @@ int support_print_failure_impl (const char *file, int line, const char *format, ...) { + support_record_failure (); va_list ap; va_start (ap, format); print_failure (file, line, format, ap); @@ -45,6 +47,8 @@ void support_exit_failure_impl (int status, const char *file, int line, const char *format, ...) { + if (status != EXIT_SUCCESS && status != EXIT_UNSUPPORTED) + support_record_failure (); va_list ap; va_start (ap, format); print_failure (file, line, format, ap); diff --git a/support/check.h b/support/check.h index 92cb5d9..129bff2 100644 --- a/support/check.h +++ b/support/check.h @@ -23,15 +23,19 @@ __BEGIN_DECLS -/* Print failure message to standard output and return 1. */ +/* Record a test failure, print the failure message to standard output + and return 1. */ #define FAIL_RET(...) \ return support_print_failure_impl (__FILE__, __LINE__, __VA_ARGS__) -/* Print failure message and terminate the process with STATUS. */ +/* Print the failure message and terminate the process with STATUS. + Record a the process as failed if STATUS is neither EXIT_SUCCESS + nor EXIT_UNSUPPORTED. */ #define FAIL_EXIT(status, ...) \ support_exit_failure_impl (status, __FILE__, __LINE__, __VA_ARGS__) -/* Print failure message and terminate with exit status 1. */ +/* Record a test failure, print the failure message and terminate with + exit status 1. */ #define FAIL_EXIT1(...) \ support_exit_failure_impl (1, __FILE__, __LINE__, __VA_ARGS__) diff --git a/support/delayed_exit.c b/support/delayed_exit.c index d5b2e10..a961410 100644 --- a/support/delayed_exit.c +++ b/support/delayed_exit.c @@ -22,6 +22,7 @@ #include #include #include +#include #include static void * @@ -31,10 +32,7 @@ delayed_exit_thread (void *seconds_as_ptr) struct timespec delay = { seconds, 0 }; struct timespec remaining = { 0 }; if (nanosleep (&delay, &remaining) != 0) - { - printf ("error: nanosleep: %m\n"); - exit (1); - } + FAIL_EXIT1 ("nanosleep: %m\n"); /* Exit the process sucessfully. */ exit (0); return NULL; diff --git a/support/support_record_failure.c b/support/support_record_failure.c index 24b2d6e..30de2f6 100644 --- a/support/support_record_failure.c +++ b/support/support_record_failure.c @@ -36,8 +36,8 @@ propagate to the parent process. */ struct test_failures { - unsigned counter; - unsigned failed; + unsigned int counter; + unsigned int failed; }; static struct test_failures *state; diff --git a/support/support_test_verify_impl.c b/support/support_test_verify_impl.c index 28b1524..3b74e57 100644 --- a/support/support_test_verify_impl.c +++ b/support/support_test_verify_impl.c @@ -26,7 +26,7 @@ support_test_verify_impl (int status, const char *file, int line, const char *expr) { support_record_failure (); - printf ("FAIL %s:%d: not true: %s\n", file, line, expr); + printf ("error: %s:%d: not true: %s\n", file, line, expr); if (status >= 0) exit (status); diff --git a/support/tst-support_record_failure-2.sh b/support/tst-support_record_failure-2.sh index 71af382..a96a60d 100644 --- a/support/tst-support_record_failure-2.sh +++ b/support/tst-support_record_failure-2.sh @@ -52,15 +52,15 @@ different_status () { run_test 1 "error: 1 test failures" $direct --status=1 run_test 2 "error: 1 test failures" $direct --status=2 run_test 1 "error: 1 test failures" $direct --status=77 - run_test 2 "FAIL tst-support_record_failure.c:108: not true: false + run_test 2 "error: tst-support_record_failure.c:108: not true: false error: 1 test failures" $direct --test-verify } different_status different_status --direct -run_test 1 "FAIL tst-support_record_failure.c:113: not true: false +run_test 1 "error: tst-support_record_failure.c:113: not true: false error: 1 test failures" --test-verify-exit # --direct does not print the summary error message if exit is called. -run_test 1 "FAIL tst-support_record_failure.c:113: not true: false" \ +run_test 1 "error: tst-support_record_failure.c:113: not true: false" \ --direct --test-verify-exit diff --git a/support/xasprintf.c b/support/xasprintf.c index b9dc91b..a8391b4 100644 --- a/support/xasprintf.c +++ b/support/xasprintf.c @@ -21,6 +21,7 @@ #include #include #include +#include char * xasprintf (const char *format, ...) @@ -29,10 +30,7 @@ xasprintf (const char *format, ...) va_start (ap, format); char *result; if (vasprintf (&result, format, ap) < 0) - { - printf ("error: asprintf: %m\n"); - exit (1); - } + FAIL_EXIT1 ("asprintf: %m\n"); va_end (ap); return result; } diff --git a/support/xfork.c b/support/xfork.c index 4b2ce91..c4f4d39 100644 --- a/support/xfork.c +++ b/support/xfork.c @@ -20,15 +20,13 @@ #include #include +#include pid_t xfork (void) { pid_t result = fork (); if (result < 0) - { - printf ("error: fork: %m\n"); - exit (1); - } + FAIL_EXIT1 ("fork: %m\n"); return result; } diff --git a/support/xpthread_check_return.c b/support/xpthread_check_return.c index 8781ee1..737bb47 100644 --- a/support/xpthread_check_return.c +++ b/support/xpthread_check_return.c @@ -21,6 +21,7 @@ #include #include #include +#include void xpthread_check_return (const char *function, int value) @@ -28,7 +29,6 @@ xpthread_check_return (const char *function, int value) if (value != 0) { errno = value; - printf ("error: %s: %m\n", function); - exit (1); + FAIL_EXIT1 ("%s: %m\n", function); } } diff --git a/support/xsocket.c b/support/xsocket.c index 9ebe63f..268a825 100644 --- a/support/xsocket.c +++ b/support/xsocket.c @@ -27,10 +27,6 @@ xsocket (int domain, int type, int protocol) { int fd = socket (domain, type, protocol); if (fd < 0) - { - support_record_failure (); - printf ("error: socket (%d, %d, %d): %m\n", domain, type, protocol); - exit (1); - } + FAIL_EXIT1 ("socket (%d, %d, %d): %m\n", domain, type, protocol); return fd; } diff --git a/support/xwaitpid.c b/support/xwaitpid.c index 5a6e540..f577535 100644 --- a/support/xwaitpid.c +++ b/support/xwaitpid.c @@ -20,6 +20,7 @@ #include #include +#include #include int @@ -27,9 +28,6 @@ xwaitpid (int pid, int *status, int flags) { pid_t result = waitpid (pid, status, flags); if (result < 0) - { - printf ("error: waitpid: %m\n"); - exit (1); - } + FAIL_EXIT1 ("waitpid: %m\n"); return result; }