From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 09FB93858C5E for ; Tue, 4 Apr 2023 13:58:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 09FB93858C5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680616687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JC2dtQ1uGpWXuqCUvMSLgtCIxVtjg6CPuvDHkL0RpnY=; b=YCukXQCOEMkoo44wahN0DgQ4jRe33ugfCB5fta2oLedy0bh4806dpApNx6EChN+UTPHb7R FH0i1v66u6ipI5OSMwsL+EjDlblqfXyeIX9IEmp0QwO3Cyml/BLZI9yuDCE11SnjiyZ61R oQoOuHFw1DmZ/5/Oo+VkZT8t6i+M5p8= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-523-kRlYhV62NeygTlT4TJcbTQ-1; Tue, 04 Apr 2023 09:58:06 -0400 X-MC-Unique: kRlYhV62NeygTlT4TJcbTQ-1 Received: by mail-qv1-f71.google.com with SMTP id pe26-20020a056214495a00b005df3eac4c0bso11540005qvb.1 for ; Tue, 04 Apr 2023 06:58:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680616686; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JC2dtQ1uGpWXuqCUvMSLgtCIxVtjg6CPuvDHkL0RpnY=; b=2Y1ng+UWI/4lOJC6+IcFkVP7Kz4E9r37z4lDIO67fCJfJvAmdNuCWfIpQTj4rfEQRE 1/QekxhR/rfzgaB9ZC1fzb3e9qSJIhRTYTubdgEAlDPMUvFwUQiuLX5lOXEwwbAD5vg/ VWuBQVatAN/we6FxsQMre90pLEnpmKLzUzMnx4wIGOvKSkoW35avHLrr+FNCdyCqTmcx On+KGwrJR5LnrYnr7/hyjW/klLJfTII/vJG2Oiolu1R8lEuOsqymrBtHFJA07N+MpC9z WHRg8Q5yJEp3nCiRjtAjLL7BM2b50rbHszIjwpkImeARiQ6XDCQX6AzRm8LmOOKS2eVu KjVw== X-Gm-Message-State: AAQBX9c07A/vZfCDtqTs7x8P+VnKBGOiunjA3ixYChfQTYx0qpefBu61 hC3Yn6fa4IrlXIANYYsni4ekTliRW+EcNyukEn3SHudFqpYFsnAakDoVLhinbeKZvHVjAU/yQ0M PnBwmOFkGfW/V4kCkbs8f X-Received: by 2002:a05:622a:1210:b0:3e6:2e9e:58f1 with SMTP id y16-20020a05622a121000b003e62e9e58f1mr3581526qtx.59.1680616685978; Tue, 04 Apr 2023 06:58:05 -0700 (PDT) X-Google-Smtp-Source: AKy350belg8jUj7/yZswvCTvUr9had9a51oYxQwDadlZXOUh6Mlk6WRfe9/bnx87ehMEoTQKJk6Lww== X-Received: by 2002:a05:622a:1210:b0:3e6:2e9e:58f1 with SMTP id y16-20020a05622a121000b003e62e9e58f1mr3581493qtx.59.1680616685655; Tue, 04 Apr 2023 06:58:05 -0700 (PDT) Received: from oak.redhat.com (c-71-206-142-238.hsd1.va.comcast.net. [71.206.142.238]) by smtp.gmail.com with ESMTPSA id i7-20020a37b807000000b0074a5ffbecd3sm167759qkf.49.2023.04.04.06.58.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 06:58:05 -0700 (PDT) From: Joe Simmons-Talbott To: Wilco Dijkstra , libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v2 1/3] stdlib: Add testcases for abs(). (BZ #30263) Date: Tue, 4 Apr 2023 09:57:45 -0400 Message-Id: <20230404135747.3576298-2-josimmon@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230404135747.3576298-1-josimmon@redhat.com> References: <20230404135747.3576298-1-josimmon@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Test minimum and maximum int values, zero, and part of the range of int values. Use '-fno-builtin' to ensure we are testing the implementation. --- stdlib/Makefile | 3 +++ stdlib/tst-abs.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 stdlib/tst-abs.c diff --git a/stdlib/Makefile b/stdlib/Makefile index 5e38f0e6a2..b7e1c028f0 100644 --- a/stdlib/Makefile +++ b/stdlib/Makefile @@ -184,6 +184,7 @@ tests := \ testmb2 \ testrand \ testsort \ + tst-abs \ tst-arc4random-fork \ tst-arc4random-stats \ tst-arc4random-thread \ @@ -287,6 +288,8 @@ LDLIBS-test-dlclose-exit-race = $(shared-thread-library) LDFLAGS-test-dlclose-exit-race = $(LDFLAGS-rdynamic) LDLIBS-test-dlclose-exit-race-helper.so = $(libsupport) $(shared-thread-library) +CFLAGS-tst-abs.c += -fno-builtin + ifeq ($(have-cxx-thread_local),yes) CFLAGS-tst-quick_exit.o = -std=c++11 LDLIBS-tst-quick_exit = -lstdc++ diff --git a/stdlib/tst-abs.c b/stdlib/tst-abs.c new file mode 100644 index 0000000000..2b96aedc3e --- /dev/null +++ b/stdlib/tst-abs.c @@ -0,0 +1,45 @@ +/* Basic tests for abs. + Copyright (C) 2023 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 + +#include + +#define LARGE_PRIME 49999 + +static int do_test (void) +{ + int i; + + TEST_COMPARE(abs(INT_MAX), INT_MAX); + TEST_COMPARE(abs(INT_MIN + 1), INT_MAX); + TEST_COMPARE(abs(-1), 1); + TEST_COMPARE(abs(0), 0); + TEST_COMPARE(abs(1), 1); + + for (i = INT_MIN + 1; i < 0; i += LARGE_PRIME) + TEST_COMPARE(abs(i), -i); + + for (i = 0; i < INT_MAX - LARGE_PRIME; i += LARGE_PRIME) + TEST_COMPARE(abs(i), i); + + return EXIT_SUCCESS; +} + +#include -- 2.39.2