From patchwork Tue Apr 4 13:57:46 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: 1764981 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=I+6tun9Y; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PrTr53jj9z1yZQ for ; Tue, 4 Apr 2023 23:58:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F5FF3853D36 for ; Tue, 4 Apr 2023 13:58:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F5FF3853D36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680616707; bh=9UrtiQE7x4WF/MOkYmrgEKHuL0oFHXljP3yxfV+p9FM=; 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=I+6tun9YwItilele7NKH2pU1QxNnrjxwFGRuaNULYSWzKUz2GYjY7mAZGrFShp9bX R3xXCBcE9PWa6IDrcvoTcsBjgFLsWio++hxFG6pUaVJCX9lvgVSbxHtuDyXmDLEniR tCkqNniGT/h73GaFxSmSfVX5J4F38RhxFiwjGcg4= 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 F04103858C39 for ; Tue, 4 Apr 2023 13:58:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F04103858C39 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-139-7OXAhgzuPEu2BtxtWVZLyA-1; Tue, 04 Apr 2023 09:58:09 -0400 X-MC-Unique: 7OXAhgzuPEu2BtxtWVZLyA-1 Received: by mail-qt1-f199.google.com with SMTP id f36-20020a05622a1a2400b003deb2fa544bso22260692qtb.0 for ; Tue, 04 Apr 2023 06:58:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680616689; 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=9UrtiQE7x4WF/MOkYmrgEKHuL0oFHXljP3yxfV+p9FM=; b=hEnRwsQo2lSOQFr55mVqUT0XTRfV7aw7ouwyKmGbLP4mZwmcOK3W5HUcnU1OjXw/Xy RjF0y9N7nuRxeQLGNvAPVhqQfNnOtFaZFXZwEr8eqYeCyaR5Ufa+bBGAJaaNBfK0X1XG +12URPhdZMEPNkjBWqxCbjCK8BcD2jpOWOQfeSTru6iis9KWNAXHbwJV1zWr3XNSSNwT 7hKZ4fbWMaie/malW6DbSxieIzsndIGt5Q7tpVcWjsqUqC6A6E2A9pqfaCVdA0rvNJr0 sCEkF8CG3CgAOhY2fyx2C9yG9ED+ceNrSE6D28sOdZignR/peJVxbsrqBDbP1E6xjv4G y9xg== X-Gm-Message-State: AAQBX9dR4ZtvdCFdwOr4j/N8KJdr5hqudGhoBUPNtj7cMyKX4VJbP1Gn tC35reG5+OpUlQic+68mc5IpxfEVbwOC4TwahD33DJoQjmwh+u0h4MRqEKtA6IKFlvcyPdJNbzY 4/Lm9cEzXrylBE4/ifCajPY7KdyJ5 X-Received: by 2002:a05:622a:547:b0:3b6:2f0d:1925 with SMTP id m7-20020a05622a054700b003b62f0d1925mr2593559qtx.64.1680616688729; Tue, 04 Apr 2023 06:58:08 -0700 (PDT) X-Google-Smtp-Source: AKy350YsUDxNeg2OBNaKguMtz5q4ITYyZFTRcGyKpCyI58ErBFOo6QdD8/a6oR9hLcA6lSQ1CjtPOg== X-Received: by 2002:a05:622a:547:b0:3b6:2f0d:1925 with SMTP id m7-20020a05622a054700b003b62f0d1925mr2593540qtx.64.1680616688456; Tue, 04 Apr 2023 06:58:08 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 06:58:07 -0700 (PDT) To: Wilco Dijkstra , libc-alpha@sourceware.org Cc: Joe Simmons-Talbott Subject: [PATCH v2 2/3] stdlib: Add testcases for labs(). (BZ #30263) Date: Tue, 4 Apr 2023 09:57:46 -0400 Message-Id: <20230404135747.3576298-3-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 X-Spam-Status: No, score=-11.8 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+incoming=patchwork.ozlabs.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 | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 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..92b456745a --- /dev/null +++ b/stdlib/tst-labs.c @@ -0,0 +1,51 @@ +/* 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 + +#define LARGE_PRIME 49999 + +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 += LARGE_PRIME) + TEST_COMPARE(labs(i), -i); + + for (i = LONG_MAX - INT_MAX; i < LONG_MAX - LARGE_PRIME; i += LARGE_PRIME) + TEST_COMPARE(labs(i), i); + + for (i = INT_MIN + 1; i < 0; i += LARGE_PRIME) + TEST_COMPARE(labs(i), -i); + + for (i = 0; i < INT_MAX; i += LARGE_PRIME) + TEST_COMPARE(labs(i), i); + + return EXIT_SUCCESS; +} + +#include