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 570B6385840E for ; Mon, 3 Apr 2023 19:12:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 570B6385840E 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=1680549154; 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=QdEjtKV0KV77yQ1loqi6Ry+2HGPB7PUODXbofSDI9iY=; b=i8z0q77Pgw3xR/bYAXN5aGMq/a1eQdkFKJRfb7klMxhNxBa9NhdxSSQwe2nyADnO0dTf3m 0LDiHD8BEPezDoRGJHrf59aHSToq0avRFxWi0bolAfrKL/lpo6J5q6O+IINVC/u35mJT0k Kqr8cHINoJOCAeI2Ds/dCRksZAthdd0= 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) From: Joe Simmons-Talbott 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 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 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 -- 2.39.2