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 From patchwork Mon Apr 3 19:12:22 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: 67235 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 3AAC3385B800 for ; Mon, 3 Apr 2023 19:13:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AAC3385B800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680549220; bh=QdEjtKV0KV77yQ1loqi6Ry+2HGPB7PUODXbofSDI9iY=; 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=MgjyvxUlmVwArd0Rgrn89QfvvUL2ysINCeaeXyN/0szhtSCM/d1ol4kEEu88fCKgY u7ZjpHnLegYSfCZuwLiILnMvflvCZUz88xlv2ggilkiqGIaDMKX+/boOhW4fbz7I6X zSbRtQNuOgpvXAXDdzLOXpVyIgta/6DnXe/1/q8I= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 570B6385840E for ; Mon, 3 Apr 2023 19:12:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 570B6385840E Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-577-RxxZOV-QP02JjyNjeqfJsg-1; Mon, 03 Apr 2023 15:12:34 -0400 X-MC-Unique: RxxZOV-QP02JjyNjeqfJsg-1 Received: by mail-qk1-f200.google.com with SMTP id 187-20020a3707c4000000b007468d9a30faso13617651qkh.23 for ; Mon, 03 Apr 2023 12:12:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680549153; 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=QdEjtKV0KV77yQ1loqi6Ry+2HGPB7PUODXbofSDI9iY=; b=tXrLwbtAqFdHWK7GJqhMR9CR2iC9HeJdUmTFVseP/EQiCfhHh0GDGOKC8RGFx6Uj1P 8yyvP52E6Qo5PlCWgdLEDZIEO0jthp8oQONrBOF+xVdIF3pjWqHAHP42VTH26jVjA7Uw wlDxy/QgzpplLK7TfdTUO3fkx1cuL3AFqWAXhUclQQJGtNmyARuNYR+Iqofd1BmPeOcu OdMw/Oc1OdhfKFdMTzdKNSc6twfOCu65kaVJE8LYtRMTVmSLf31uN1/72ZXBRP/G/6V8 1h9u4EItIMcs+dDnc137uJxQB2tobUNksJJiyqp9HSCQsm+MApx82IVFDRze2rGX5Hmo HQiw== X-Gm-Message-State: AAQBX9cH3DIiWjMjS3pDQssJwl6An9Wwz54ai8DDgt8G2HAfN42dcPsg WNyf3qUj/SdjZhdXZHNzT4zO26Bqa7tLOkbIBe5A4iOKIretpY8sGxs1qeA6z2bSjS8inNx1ndq 83fJHY7LUhtnFp6poaW1sB4HIh7Zz2hQsPxPMMCIploija/HOKCHkAkoaOoatHpgYVokJw0QHQH ZBWTCb X-Received: by 2002:a05:6214:2304:b0:5cc:ce87:7d7a with SMTP id gc4-20020a056214230400b005ccce877d7amr65970625qvb.41.1680549153205; Mon, 03 Apr 2023 12:12:33 -0700 (PDT) X-Google-Smtp-Source: AKy350bk3BkHgQ5wjMtFCmJmdwuYA/FppDdJQDWezi8iNS2JgzuFi8yujValGHfwHGobEW8wAGO+NA== X-Received: by 2002:a05:6214:2304:b0:5cc:ce87:7d7a with SMTP id gc4-20020a056214230400b005ccce877d7amr65970589qvb.41.1680549152863; Mon, 03 Apr 2023 12:12:32 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 12:12:32 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH 2/3] stdlib: Add testcases for labs(). (BZ #30263) Date: Mon, 3 Apr 2023 15:12:22 -0400 Message-Id: <20230403191224.2108588-3-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.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 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 long values, zero, and part of the range of long values. Use '-fno-builtin' to ensure we are testing the implementation. --- stdlib/Makefile | 2 ++ stdlib/tst-labs.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 stdlib/tst-labs.c diff --git a/stdlib/Makefile b/stdlib/Makefile index b7e1c028f0..5899cc1865 100644 --- a/stdlib/Makefile +++ b/stdlib/Makefile @@ -198,6 +198,7 @@ tests := \ tst-cxa_atexit \ tst-environ \ tst-getrandom \ + tst-labs \ tst-limits \ tst-makecontext \ tst-makecontext-align \ @@ -289,6 +290,7 @@ LDFLAGS-test-dlclose-exit-race = $(LDFLAGS-rdynamic) LDLIBS-test-dlclose-exit-race-helper.so = $(libsupport) $(shared-thread-library) CFLAGS-tst-abs.c += -fno-builtin +CFLAGS-tst-labs.c += -fno-builtin ifeq ($(have-cxx-thread_local),yes) CFLAGS-tst-quick_exit.o = -std=c++11 diff --git a/stdlib/tst-labs.c b/stdlib/tst-labs.c new file mode 100644 index 0000000000..38c0f7b007 --- /dev/null +++ b/stdlib/tst-labs.c @@ -0,0 +1,49 @@ +/* Basic tests for labs. + 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) +{ + long i; + + TEST_COMPARE(labs(LONG_MAX), LONG_MAX); + TEST_COMPARE(labs(LONG_MIN + 1), LONG_MAX); + TEST_COMPARE(labs(-1), 1); + TEST_COMPARE(labs(0), 0); + TEST_COMPARE(labs(1), 1); + + for (i = LONG_MIN + 1; i < LONG_MIN + INT_MAX; i++) + TEST_COMPARE(llabs(i), -i); + + for (i = LONG_MAX - INT_MAX; i < LONG_MAX; i++) + TEST_COMPARE(llabs(i), i); + + for (i = INT_MIN + 1; i < 0; i++) + TEST_COMPARE(labs(i), -i); + + for (i = 0; i < INT_MAX; i++) + TEST_COMPARE(labs(i), i); + + return EXIT_SUCCESS; +} + +#include From patchwork Mon Apr 3 19:12:23 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: 67234 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 4A057385841E for ; Mon, 3 Apr 2023 19:13:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A057385841E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680549215; bh=2rQIaaTsGppSgMigp0QHee9O19DszS2MDRVjjUdF81E=; 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=sMgAgZoYBBtao4YzxABUkj6RA9KWCGFc510miaH8sUovN3wltvdX6uYC3X2zCdCmp Y50ZOusjHrglMiiVYPoWJghBomx8wUbmjD+87Cv6mMjosguQF1i4oaq908MrDlEt1m OrXa1yrNagSWfXWZzKEek1qx9ATNVHjrNGP4FgkI= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id D22753858D39 for ; Mon, 3 Apr 2023 19:12:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D22753858D39 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-403-pmfh5pIpNMKlIcpmO_bw9A-1; Mon, 03 Apr 2023 15:12:36 -0400 X-MC-Unique: pmfh5pIpNMKlIcpmO_bw9A-1 Received: by mail-qk1-f197.google.com with SMTP id v5-20020a379305000000b0074a37810157so2029372qkd.21 for ; Mon, 03 Apr 2023 12:12:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680549155; 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=2rQIaaTsGppSgMigp0QHee9O19DszS2MDRVjjUdF81E=; b=cBHXj4/BlE43l4TftAdh1PUslr73BOjOIkC1IkTVeM10OGfdkVM8R43XQ9LOs0x2gz fhJYeEBQN2/oiZ8KQ6jz/CB7e2DMJ7i3xiZlYFCSgdS17e6C8aRTsin7Id4AKZ9EUN1J oYAk+kA10N+HmXmILfp2Pf+E4TTC38jdDkwQhpJfU8663guU29/NaGWkTKsy9JrhGCTP S4wC5nFvrrvN7xJmyPdZRqM/QE+KqTVQ/87EwoSa7MwsKFB7fhKyWg7GBuoYJUZ1ZbSw YTMC2jqYy8BS3f7X04BlYC9xv8UiH/fofbDFuH4wkjZn8k/Bcr+AGSLLM5QHeBAksk7w i9JA== X-Gm-Message-State: AO0yUKXM7GzyhOdMwwBhx0l/w5H6Si4K0eIDZI1v9F69FSGLhRJQOriZ wCB7ggkC2qh7YgSAxelTX4O2pYoLZ58XzEEqrupCGixtw+O6FyGluhb03Sx6lVIGoD7TzsK0zMk C5+j46nF8NKb34tUZQ9UB//qCktF8Zdg8cuZ7iJNjCWYenPs5Vu9Efao5abhax2npRH93cvCtk8 Xk7luy X-Received: by 2002:a05:622a:13cc:b0:3e3:89a5:192f with SMTP id p12-20020a05622a13cc00b003e389a5192fmr57849728qtk.61.1680549155574; Mon, 03 Apr 2023 12:12:35 -0700 (PDT) X-Google-Smtp-Source: AK7set+NfY28MdKHsANayR66YlfZ39hJXtt9Nxudzl4M+zurnF+VTZ+aFeNHMJKHpdlT6Unj7EnT6w== X-Received: by 2002:a05:622a:13cc:b0:3e3:89a5:192f with SMTP id p12-20020a05622a13cc00b003e389a5192fmr57849693qtk.61.1680549155260; Mon, 03 Apr 2023 12:12:35 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 12:12:34 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH 3/3] stdlib: Add testcases for llabs(). (BZ #30263) Date: Mon, 3 Apr 2023 15:12:23 -0400 Message-Id: <20230403191224.2108588-4-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.9 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 long long values, zero, and part of the range of long long values. Use '-fno-builtin' to ensure we are testing the implementation. --- stdlib/Makefile | 2 ++ stdlib/tst-llabs.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 stdlib/tst-llabs.c diff --git a/stdlib/Makefile b/stdlib/Makefile index 5899cc1865..40886dea11 100644 --- a/stdlib/Makefile +++ b/stdlib/Makefile @@ -200,6 +200,7 @@ tests := \ tst-getrandom \ tst-labs \ tst-limits \ + tst-llabs \ tst-makecontext \ tst-makecontext-align \ tst-makecontext2 \ @@ -291,6 +292,7 @@ LDLIBS-test-dlclose-exit-race-helper.so = $(libsupport) $(shared-thread-library) CFLAGS-tst-abs.c += -fno-builtin CFLAGS-tst-labs.c += -fno-builtin +CFLAGS-tst-llabs.c += -fno-builtin ifeq ($(have-cxx-thread_local),yes) CFLAGS-tst-quick_exit.o = -std=c++11 diff --git a/stdlib/tst-llabs.c b/stdlib/tst-llabs.c new file mode 100644 index 0000000000..631f13baa3 --- /dev/null +++ b/stdlib/tst-llabs.c @@ -0,0 +1,49 @@ +/* Basic tests for llabs. + 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) +{ + long i; + + TEST_COMPARE(llabs(LLONG_MAX), LLONG_MAX); + TEST_COMPARE(llabs(LLONG_MIN + 1), LLONG_MAX); + TEST_COMPARE(llabs(-1), 1); + TEST_COMPARE(llabs(0), 0); + TEST_COMPARE(llabs(1), 1); + + for (i = LLONG_MIN + 1; i < LLONG_MIN + INT_MAX; i++) + TEST_COMPARE(llabs(i), -i); + + for (i = LLONG_MAX - INT_MAX; i < LLONG_MAX; i++) + TEST_COMPARE(llabs(i), i); + + for (i = INT_MIN + 1; i < 0; i++) + TEST_COMPARE(llabs(i), -i); + + for (i = 0; i < INT_MAX; i++) + TEST_COMPARE(llabs(i), i); + + return EXIT_SUCCESS; +} + +#include