From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 94C1D1F5AE for ; Fri, 14 May 2021 13:57:35 +0000 (UTC) Received: from localhost ([::1]:44154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhYJq-0002uC-FU for normalperson@yhbt.net; Fri, 14 May 2021 09:57:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhYJm-0002u3-Qi for bug-gnulib@gnu.org; Fri, 14 May 2021 09:57:30 -0400 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.221]:36152) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhYJk-00013A-GM for bug-gnulib@gnu.org; Fri, 14 May 2021 09:57:30 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1621000645; cv=none; d=strato.com; s=strato-dkim-0002; b=bFpYCrzXct30DTncTi2QsSysqpjq1TQvQtV5BpThpm5iv1Rted6GKezwLAPfCTZ+z8 oxsBFHc/jhxDP0LrIeQknXk2D0U/0V4n9hg6g7XS0SWEm+RXazG98LoOzNnswFKqFFBU j0wHJ9naEVMboM4Nv3lEu0HEOKDYi4Q3c7XjA1L80J8sP/0LSpI+BoAXOEVcDf7822kc 6cKfCNqq6fE3POoBe71db16tfYLI6stGiUWKSZ8aHz/Z1qdOByFNQl+/4BBqnmxvVLeM uIqc7h+GhxgZBcKgFWwWnPBBLIuvyAhqscv1PIAwmHue8b290M5/DcYbDJFjSOd3pELH bdHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1621000645; s=strato-dkim-0002; d=strato.com; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=ra6CXq4M+6XRBSFMb5c5o7/oLxkoY/lAODFkpdkeRYc=; b=LF9DhhXfQK1dbOJegDzrLeWJ+U3pbN9pyx1uVtFxqbdI0tcvFPzpMMcXJB6mD18qOE P5s6y8L7sX8JNYionTGr3MdVtf3P+JVoypWzn0y54Daxiz8rX5zlpeWdmgSpTUQ/1fnB eWsjKB9h4AOnSJHv//8BAvT06p8HEEhww3BDc0Rk2Hjztq385lVCW7eMr1STedhtSd6N 2DTf84AM/YPIqEyUje7vxqRHtyM3elgxCoMPVz5mtUssVHDGWh6JbNy/t8Fyj23Z2ZWV M7JYHGRybUVwmPuggrwL6ts204pL/RawKjriEWBODIlGPIvXGaTs8KTkwPgQh2AdQg56 q30w== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1621000645; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=ra6CXq4M+6XRBSFMb5c5o7/oLxkoY/lAODFkpdkeRYc=; b=Lm/EcGrBqAo84EfjQxHn5Ntab7xlYB4eEL54idF+DCVVCY8jv2qR1TQ4/F/nBkZiJb 1T9SLJfpWlWGZTdQ/jSib+Y56Bvm2e1RqPsTSOKJ7pjFo32x4dFRGbX2catiqXSDfagh ehG85iGpd9Xjk7admPo91CntFwgoKZvXJf8tX190DyiacvIZFNw1znMROLfyC+/fxNlj 7VejQWaxYaIT9YCDZpw41cK/xRmOe1esQtFCx0maHfbOjgT78DV5I0AXhQ9bJ6MkNWEb tqiiZVMtW9ez6j/0hBpkidoommVmR6jV/lUsM7kDnyOjiRkubo+vXI0B6dsybV0Ex7Zh lESg== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOHqf3z5NW" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 47.25.8 DYNA|AUTH) with ESMTPSA id I08c4ex4EDvP00C (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Fri, 14 May 2021 15:57:25 +0200 (CEST) From: Bruno Haible To: bug-gnulib@gnu.org Subject: *alloc-gnu tests: Use ASSERT macro Date: Fri, 14 May 2021 15:54:20 +0200 Message-ID: <1931121.K9jEXhfO9p@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-206-generic; KDE/5.18.0; x86_64; ; ) MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: none client-ip=81.169.146.221; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" On Solaris 11.3/sparc64, I see a test failure: FAIL test-malloc-gnu (exit status: 1) Now, there are 3 possible reasons for exit status 1 in this test. This makes the investigation of the cause unnecessarily time consuming. Similarly, test-reallocarray has exit statuses 1, 2, 3, 4, but this does not scale: there are only 125 possible exit codes available in this way. Better use the ASSERT macro, which we are using for many years in other places and which points immediately to the line in question. 2021-05-14 Bruno Haible *alloc-gnu tests: Use ASSERT macro. * tests/test-malloc-gnu.c: Include "macros.h". (main): Use ASSERT. * tests/test-calloc-gnu.c: Include "macros.h". (main): Use ASSERT. * tests/test-realloc-gnu.c: Include "macros.h". (main): Use ASSERT. * tests/test-reallocarray.c: Include "macros.h". (main): Use ASSERT. * modules/malloc-gnu-tests (Files): Add tests/macros.h. * modules/calloc-gnu-tests (Files): Likewise. * modules/realloc-gnu-tests (Files): Likewise. * modules/reallocarray-tests (Files): Likewise. diff --git a/modules/calloc-gnu-tests b/modules/calloc-gnu-tests index a4804fd..f0f061c 100644 --- a/modules/calloc-gnu-tests +++ b/modules/calloc-gnu-tests @@ -1,5 +1,6 @@ Files: tests/test-calloc-gnu.c +tests/macros.h Depends-on: stdint diff --git a/modules/malloc-gnu-tests b/modules/malloc-gnu-tests index 9a6f01c..dc1a34f 100644 --- a/modules/malloc-gnu-tests +++ b/modules/malloc-gnu-tests @@ -1,5 +1,6 @@ Files: tests/test-malloc-gnu.c +tests/macros.h Depends-on: stdint diff --git a/modules/realloc-gnu-tests b/modules/realloc-gnu-tests index 9d26260..c1dbe17 100644 --- a/modules/realloc-gnu-tests +++ b/modules/realloc-gnu-tests @@ -1,5 +1,6 @@ Files: tests/test-realloc-gnu.c +tests/macros.h Depends-on: stdint diff --git a/modules/reallocarray-tests b/modules/reallocarray-tests index 4b61da1..3082281 100644 --- a/modules/reallocarray-tests +++ b/modules/reallocarray-tests @@ -1,6 +1,7 @@ Files: tests/test-reallocarray.c tests/signature.h +tests/macros.h Depends-on: stdint diff --git a/tests/test-calloc-gnu.c b/tests/test-calloc-gnu.c index dbef019..a98a75f 100644 --- a/tests/test-calloc-gnu.c +++ b/tests/test-calloc-gnu.c @@ -16,11 +16,14 @@ #include +/* Specification. */ #include #include #include +#include "macros.h" + /* Return N. Usual compilers are not able to infer something about the return value. */ static size_t @@ -44,8 +47,7 @@ main () /* Check that calloc (0, 0) is not a NULL pointer. */ { void * volatile p = calloc (0, 0); - if (p == NULL) - return 1; + ASSERT (p != NULL); free (p); } @@ -58,11 +60,12 @@ main () for (size_t n = 2; n != 0; n <<= 1) { void *volatile p = calloc (PTRDIFF_MAX / n + 1, identity (n)); - if (!(p == NULL && errno == ENOMEM)) - return 2; - p = calloc (SIZE_MAX / n + 1, identity (n)); - if (!(p == NULL && errno == ENOMEM)) - return 3; + ASSERT (p == NULL); + ASSERT (errno == ENOMEM); + + p = calloc (SIZE_MAX / n + 1, identity (n)); + ASSERT (p == NULL); + ASSERT (errno == ENOMEM); } } diff --git a/tests/test-malloc-gnu.c b/tests/test-malloc-gnu.c index 13217c1..0160c6c 100644 --- a/tests/test-malloc-gnu.c +++ b/tests/test-malloc-gnu.c @@ -16,18 +16,20 @@ #include +/* Specification. */ #include #include #include +#include "macros.h" + int main (int argc, char **argv) { /* Check that malloc (0) is not a NULL pointer. */ void *volatile p = malloc (0); - if (p == NULL) - return 1; + ASSERT (p != NULL); free (p); /* Check that malloc (n) fails when n exceeds PTRDIFF_MAX. */ @@ -35,8 +37,8 @@ main (int argc, char **argv) { size_t one = argc != 12345; p = malloc (PTRDIFF_MAX + one); - if (!(p == NULL && errno == ENOMEM)) - return 1; + ASSERT (p == NULL); + ASSERT (errno == ENOMEM); } return 0; diff --git a/tests/test-realloc-gnu.c b/tests/test-realloc-gnu.c index a366738..3a787ed 100644 --- a/tests/test-realloc-gnu.c +++ b/tests/test-realloc-gnu.c @@ -16,18 +16,20 @@ #include +/* Specification. */ #include #include #include +#include "macros.h" + int main (int argc, char **argv) { /* Check that realloc (NULL, 0) is not a NULL pointer. */ void *volatile p = realloc (NULL, 0); - if (p == NULL) - return 1; + ASSERT (p != NULL); /* Check that realloc (p, n) fails when p is non-null and n exceeds PTRDIFF_MAX. */ @@ -35,8 +37,8 @@ main (int argc, char **argv) { size_t one = argc != 12345; p = realloc (p, PTRDIFF_MAX + one); - if (!(p == NULL && errno == ENOMEM)) - return 1; + ASSERT (p == NULL); + ASSERT (errno == ENOMEM); } free (p); diff --git a/tests/test-reallocarray.c b/tests/test-reallocarray.c index 8067542..f0839ff 100644 --- a/tests/test-reallocarray.c +++ b/tests/test-reallocarray.c @@ -16,13 +16,17 @@ #include +/* Specification. */ #include + #include #include #include "signature.h" SIGNATURE_CHECK (reallocarray, void *, (void *, size_t, size_t)); +#include "macros.h" + int main () { @@ -33,17 +37,13 @@ main () void *volatile p = NULL; p = reallocarray (p, PTRDIFF_MAX / n + 1, n); - if (p) - return 1; - if (errno != ENOMEM) - return 2; + ASSERT (p == NULL); + ASSERT (errno == ENOMEM); p = reallocarray (p, SIZE_MAX / n + 1, n); - if (p) - return 3; - if (!(errno == ENOMEM - || errno == EOVERFLOW /* NetBSD */)) - return 4; + ASSERT (p == NULL); + ASSERT (errno == ENOMEM + || errno == EOVERFLOW /* NetBSD */); /* Reallocarray should not crash with zero sizes. */ p = reallocarray (p, 0, n);