From patchwork Mon Apr 3 19:12:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Simmons-Talbott X-Patchwork-Id: 67233 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A2AD33858005 for ; Mon, 3 Apr 2023 19:12:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A2AD33858005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680549176; bh=HnDwlti2EtUeT+V7nYUGKrVxeRbv9rBxHQ0eUzatyMI=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=cmXDe32H2teX96vwNniThhf/3vpswm+fbaTqg0n7cvCYZfijYkrU36DUtJOQbgpCA Nf7B3N9zr+WMScbs5spxXvmAyLUBWmtXSl/ppfB80OjaYN6uc67PcmAbeUZmhGLIfL 7YH4h9hyaLXaX1HNN5Gqsir5qvJgxPxXgJxX5Vfs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 0B70D3858C27 for ; Mon, 3 Apr 2023 19:12:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B70D3858C27 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-674-ccuxHfoNN2e1gVH-vzG1Bw-1; Mon, 03 Apr 2023 15:12:31 -0400 X-MC-Unique: ccuxHfoNN2e1gVH-vzG1Bw-1 Received: by mail-qt1-f200.google.com with SMTP id v10-20020a05622a130a00b003e4ee70e001so14338398qtk.6 for ; Mon, 03 Apr 2023 12:12:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680549151; 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=HnDwlti2EtUeT+V7nYUGKrVxeRbv9rBxHQ0eUzatyMI=; b=TL3mVFKApyKc9Q4cXafSWMBmk5k5pRnoyc9iDBzE7Jn9ktL6EbDnJ2zcEPnroK120C +qmMGHv/7jRxSy7TlcKufljM9rJv4Eu3gf2hJiZtEc8tuCB4xU1ciqiBbo1H8ZD7BTv6 aBBpTAV43MaHymI8SFoT09XMROl9tK6YG9xdhrTdnK/4rl/IMz+/TPPhbcxSZhkY7pJd zUs3aGkhCKeW7huB8svWbQtY8uQLyzgXD7G1/duVAPDY2jINFc689FEwrxmj6LntRHps 3IHld36rFUOycxwFlrlTOTM9MHOHMtVzTbTwNkO50v4Qp2K/rxlFroSfxaqvxZEWotUH trNw== X-Gm-Message-State: AAQBX9e9Zlq+4YxGFTHB9udiFB9IXfzQyzvPdAb60IF7yK/UvVY+Tv5y r1YbmeqhpAg9J0fzJ2yAHcV4c+JhYxJBEX1R26LNLAmhCHCv/ic0A+t9KxkFuSQMsWugtVEX7f3 wzBIAOjMFzMlPPYrLk2ki1j48/cbR+8ruJcSZZvXKhszWcTFI6ZGHnrNJ5vFfoarUdCsk+FkPPu Ab9JBT X-Received: by 2002:ac8:5a44:0:b0:3e6:365c:2bf8 with SMTP id o4-20020ac85a44000000b003e6365c2bf8mr24832878qta.47.1680549151013; Mon, 03 Apr 2023 12:12:31 -0700 (PDT) X-Google-Smtp-Source: AKy350ahmLeoVosh8QkgmwdU57StTLPnFuwJuO1fz69M68ULpW8tp6xWmDOCSILyyPPUDRIIdBvUVg== X-Received: by 2002:ac8:5a44:0:b0:3e6:365c:2bf8 with SMTP id o4-20020ac85a44000000b003e6365c2bf8mr24832839qta.47.1680549150727; Mon, 03 Apr 2023 12:12:30 -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 p4-20020ac87404000000b003e390b48958sm2706474qtq.55.2023.04.03.12.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 12:12:30 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH 1/3] stdlib: Add testcases for abs(). (BZ #30263) Date: Mon, 3 Apr 2023 15:12:21 -0400 Message-Id: <20230403191224.2108588-2-josimmon@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230403191224.2108588-1-josimmon@redhat.com> References: <20230403191224.2108588-1-josimmon@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.5 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Joe Simmons-Talbott via Libc-alpha From: Joe Simmons-Talbott Reply-To: Joe Simmons-Talbott Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Test minimum and maximum int values, zero, and a good part of the range of int values. Use '-fno-builtin' to ensure we are testing the implementation. --- stdlib/Makefile | 3 +++ stdlib/tst-abs.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 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..639e29d33f --- /dev/null +++ b/stdlib/tst-abs.c @@ -0,0 +1,43 @@ +/* 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 + +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++) + TEST_COMPARE(abs(i), -i); + + for (i = 0; i < INT_MAX; i++) + TEST_COMPARE(abs(i), i); + + return EXIT_SUCCESS; +} + +#include