* [PATCH v2 1/3] stdlib: Add testcases for abs(). (BZ #30263)
2023-04-04 13:57 [PATCH v2 0/3] Add tests for abs(), labs(), llabs() (BZ #30263) Joe Simmons-Talbott
@ 2023-04-04 13:57 ` Joe Simmons-Talbott
2023-04-04 13:57 ` [PATCH v2 2/3] stdlib: Add testcases for labs(). " Joe Simmons-Talbott
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Joe Simmons-Talbott @ 2023-04-04 13:57 UTC (permalink / raw)
To: Wilco Dijkstra, libc-alpha; +Cc: Joe Simmons-Talbott
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
+ <https://www.gnu.org/licenses/>. */
+
+#include <limits.h>
+#include <stdlib.h>
+
+#include <support/check.h>
+
+#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 <support/test-driver.c>
--
2.39.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 2/3] stdlib: Add testcases for labs(). (BZ #30263)
2023-04-04 13:57 [PATCH v2 0/3] Add tests for abs(), labs(), llabs() (BZ #30263) Joe Simmons-Talbott
2023-04-04 13:57 ` [PATCH v2 1/3] stdlib: Add testcases for abs(). " Joe Simmons-Talbott
@ 2023-04-04 13:57 ` Joe Simmons-Talbott
2023-04-04 13:57 ` [PATCH v2 3/3] stdlib: Add testcases for llabs(). " Joe Simmons-Talbott
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Joe Simmons-Talbott @ 2023-04-04 13:57 UTC (permalink / raw)
To: Wilco Dijkstra, libc-alpha; +Cc: Joe Simmons-Talbott
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
+ <https://www.gnu.org/licenses/>. */
+
+#include <limits.h>
+#include <stdlib.h>
+
+#include <support/check.h>
+
+#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 <support/test-driver.c>
--
2.39.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 3/3] stdlib: Add testcases for llabs(). (BZ #30263)
2023-04-04 13:57 [PATCH v2 0/3] Add tests for abs(), labs(), llabs() (BZ #30263) Joe Simmons-Talbott
2023-04-04 13:57 ` [PATCH v2 1/3] stdlib: Add testcases for abs(). " Joe Simmons-Talbott
2023-04-04 13:57 ` [PATCH v2 2/3] stdlib: Add testcases for labs(). " Joe Simmons-Talbott
@ 2023-04-04 13:57 ` Joe Simmons-Talbott
2023-04-19 14:23 ` [PATCH v2 0/3] Add tests for abs(), labs(), llabs() " Joe Simmons-Talbott
2023-05-04 12:53 ` Wilco Dijkstra
4 siblings, 0 replies; 9+ messages in thread
From: Joe Simmons-Talbott @ 2023-04-04 13:57 UTC (permalink / raw)
To: Wilco Dijkstra, libc-alpha; +Cc: Joe Simmons-Talbott
Test minimum and maximum long long values, zero, 32bit crossover points, 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 | 55 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 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..be3cd78ceb
--- /dev/null
+++ b/stdlib/tst-llabs.c
@@ -0,0 +1,55 @@
+/* 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
+ <https://www.gnu.org/licenses/>. */
+
+#include <limits.h>
+#include <stdlib.h>
+
+#include <support/check.h>
+
+#define LARGE_PRIME 49999
+
+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(0x00000000ffffffffL), 0x00000000ffffffffL);
+ TEST_COMPARE(llabs(0x0000000100000000L), 0x0000000100000000L);
+ TEST_COMPARE(llabs(0x80000000ffffffffL), 0x7fffffff00000001L);
+ TEST_COMPARE(llabs(0x8000000100000000L), 0x7fffffff00000000L);
+ 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 += LARGE_PRIME)
+ TEST_COMPARE(llabs(i), -i);
+
+ for (i = LLONG_MAX - INT_MAX; i < LLONG_MAX - LARGE_PRIME; i += LARGE_PRIME)
+ TEST_COMPARE(llabs(i), i);
+
+ for (i = INT_MIN + 1; i < 0; i += LARGE_PRIME)
+ TEST_COMPARE(llabs(i), -i);
+
+ for (i = 0; i < INT_MAX; i += LARGE_PRIME)
+ TEST_COMPARE(llabs(i), i);
+
+ return EXIT_SUCCESS;
+}
+
+#include <support/test-driver.c>
--
2.39.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/3] Add tests for abs(), labs(), llabs() (BZ #30263)
2023-04-04 13:57 [PATCH v2 0/3] Add tests for abs(), labs(), llabs() (BZ #30263) Joe Simmons-Talbott
` (2 preceding siblings ...)
2023-04-04 13:57 ` [PATCH v2 3/3] stdlib: Add testcases for llabs(). " Joe Simmons-Talbott
@ 2023-04-19 14:23 ` Joe Simmons-Talbott
2023-04-26 16:38 ` Joe Simmons-Talbott
2023-05-04 12:53 ` Wilco Dijkstra
4 siblings, 1 reply; 9+ messages in thread
From: Joe Simmons-Talbott @ 2023-04-19 14:23 UTC (permalink / raw)
To: Wilco Dijkstra, libc-alpha
On Tue, Apr 04, 2023 at 09:57:44AM -0400, Joe Simmons-Talbott wrote:
Gentle ping.
Thanks,
Joe
> Add testcases for abs(), labs(), and llabs(). Test the bounds of the
> given type, zero, and part of the full range of values for labs() and
> llabs(). Test the full range for abs().
>
> Changes in V2:
> Reduce number of iterations by using a prime interval. For llabs() test
> the 32bit crossover point.
>
> Joe Simmons-Talbott (3):
> stdlib: Add testcases for abs(). (BZ #30263)
> stdlib: Add testcases for labs(). (BZ #30263)
> stdlib: Add testcases for llabs(). (BZ #30263)
>
> stdlib/Makefile | 7 ++++++
> stdlib/tst-abs.c | 45 +++++++++++++++++++++++++++++++++++++
> stdlib/tst-labs.c | 51 ++++++++++++++++++++++++++++++++++++++++++
> stdlib/tst-llabs.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 158 insertions(+)
> create mode 100644 stdlib/tst-abs.c
> create mode 100644 stdlib/tst-labs.c
> create mode 100644 stdlib/tst-llabs.c
>
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/3] Add tests for abs(), labs(), llabs() (BZ #30263)
2023-04-19 14:23 ` [PATCH v2 0/3] Add tests for abs(), labs(), llabs() " Joe Simmons-Talbott
@ 2023-04-26 16:38 ` Joe Simmons-Talbott
0 siblings, 0 replies; 9+ messages in thread
From: Joe Simmons-Talbott @ 2023-04-26 16:38 UTC (permalink / raw)
To: Wilco Dijkstra, libc-alpha
On Wed, Apr 19, 2023 at 10:23:28AM -0400, Joe Simmons-Talbott via Libc-alpha wrote:
> On Tue, Apr 04, 2023 at 09:57:44AM -0400, Joe Simmons-Talbott wrote:
>
> Gentle ping.
x2
Thanks,
Joe
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/3] Add tests for abs(), labs(), llabs() (BZ #30263)
2023-04-04 13:57 [PATCH v2 0/3] Add tests for abs(), labs(), llabs() (BZ #30263) Joe Simmons-Talbott
` (3 preceding siblings ...)
2023-04-19 14:23 ` [PATCH v2 0/3] Add tests for abs(), labs(), llabs() " Joe Simmons-Talbott
@ 2023-05-04 12:53 ` Wilco Dijkstra
2023-05-16 18:58 ` Siddhesh Poyarekar
4 siblings, 1 reply; 9+ messages in thread
From: Wilco Dijkstra @ 2023-05-04 12:53 UTC (permalink / raw)
To: Joe Simmons-Talbott, libc-alpha
Hi Joe,
> Add testcases for abs(), labs(), and llabs(). Test the bounds of the
> given type, zero, and part of the full range of values for labs() and
> llabs(). Test the full range for abs().
>
> Changes in V2:
> Reduce number of iterations by using a prime interval. For llabs() test
> the 32bit crossover point.
v2 looks good to me.
Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
Cheers,
Wilco
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/3] Add tests for abs(), labs(), llabs() (BZ #30263)
2023-05-04 12:53 ` Wilco Dijkstra
@ 2023-05-16 18:58 ` Siddhesh Poyarekar
2023-05-16 20:52 ` Florian Weimer
0 siblings, 1 reply; 9+ messages in thread
From: Siddhesh Poyarekar @ 2023-05-16 18:58 UTC (permalink / raw)
To: Wilco Dijkstra, Joe Simmons-Talbott, libc-alpha
On 2023-05-04 08:53, Wilco Dijkstra via Libc-alpha wrote:
> Hi Joe,
>
>> Add testcases for abs(), labs(), and llabs(). Test the bounds of the
>> given type, zero, and part of the full range of values for labs() and
>> llabs(). Test the full range for abs().
>>
>> Changes in V2:
>> Reduce number of iterations by using a prime interval. For llabs() test
>> the 32bit crossover point.
>
> v2 looks good to me.
>
> Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
I've pushed these now.
Thanks,
Sid
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/3] Add tests for abs(), labs(), llabs() (BZ #30263)
2023-05-16 18:58 ` Siddhesh Poyarekar
@ 2023-05-16 20:52 ` Florian Weimer
0 siblings, 0 replies; 9+ messages in thread
From: Florian Weimer @ 2023-05-16 20:52 UTC (permalink / raw)
To: Siddhesh Poyarekar; +Cc: Wilco Dijkstra, Joe Simmons-Talbott, libc-alpha
* Siddhesh Poyarekar:
> On 2023-05-04 08:53, Wilco Dijkstra via Libc-alpha wrote:
>> Hi Joe,
>>
>>> Add testcases for abs(), labs(), and llabs(). Test the bounds of the
>>> given type, zero, and part of the full range of values for labs() and
>>> llabs(). Test the full range for abs().
>>>
>>> Changes in V2:
>>> Reduce number of iterations by using a prime interval. For llabs() test
>>> the 32bit crossover point.
>> v2 looks good to me.
>> Reviewed-by: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
>
> I've pushed these now.
This breaks on various 32-bit architectures. As seen on microblaze:
tst-llabs.c: In function ‘do_test’:
tst-llabs.c:40:12: error: overflow in conversion from ‘long long int’ to ‘long int’ changes value from ‘-9223372036854775807’ to ‘1’ [-Werror=overflow]
40 | for (i = LLONG_MIN + 1; i < LLONG_MIN + INT_MAX; i += LARGE_PRIME)
| ^~~~~~~~~
tst-llabs.c:43:12: error: overflow in conversion from ‘long long int’ to ‘long int’ changes value from ‘9223372034707292160’ to ‘-2147483648’ [-Werror=overflow]
43 | for (i = LLONG_MAX - INT_MAX; i < LLONG_MAX - LARGE_PRIME; i += LARGE_PRIME)
| ^~~~~~~~~
cc1: all warnings being treated as errors
Thanks,
Florian
^ permalink raw reply [flat|nested] 9+ messages in thread