diff mbox

Fix string/test-strncmp.c to work with wide chars.

Message ID 87twhfski5.fsf@oracle.com
State New
Headers show

Commit Message

Jose E. Marchesi May 30, 2016, 2:12 p.m. UTC
wcsmbs/test-wcsncmp.c (i.e. string/test-strncmp with defined WIDE)
triggers a signal in aligment-strict platforms, like sparc*-*-*.

This patch fixes string/test-strncmp.c to work properly when the test is
performed on arrays of wide chars.  This includes passing align1 and
align2 to do_test as bytes, and to use more meaningful values for middle
chars and large chars.

Tested in sparc64-*-* and sparcv9-*-*.
No regressions.

2016-05-30  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* string/test-strncmp.c [WIDE] (MIDCHAR): Defined.
	[WIDE} (LARGECHAR): Likewise.
	(MIDCHAR): Likewise.
	(LARGECHAR): Likewise.
	(test_main): Adapted to operate on with wide chars.

---
 ChangeLog             | 13 ++++++++
 string/test-strncmp.c | 86 +++++++++++++++++++++++++++------------------------
 2 files changed, 58 insertions(+), 41 deletions(-)

Comments

Joseph Myers June 2, 2016, 10:35 p.m. UTC | #1
On Mon, 30 May 2016, Jose E. Marchesi wrote:

> wcsmbs/test-wcsncmp.c (i.e. string/test-strncmp with defined WIDE)
> triggers a signal in aligment-strict platforms, like sparc*-*-*.
> 
> This patch fixes string/test-strncmp.c to work properly when the test is
> performed on arrays of wide chars.  This includes passing align1 and
> align2 to do_test as bytes, and to use more meaningful values for middle
> chars and large chars.

A different patch (about which Carlos had some concerns) was posted at 
<https://sourceware.org/ml/libc-alpha/2015-07/msg00698.html>.  How do the 
two compare?
Jose E. Marchesi June 3, 2016, 7:36 a.m. UTC | #2
> wcsmbs/test-wcsncmp.c (i.e. string/test-strncmp with defined WIDE)
    > triggers a signal in aligment-strict platforms, like sparc*-*-*.
    > 
    > This patch fixes string/test-strncmp.c to work properly when the test is
    > performed on arrays of wide chars.  This includes passing align1 and
    > align2 to do_test as bytes, and to use more meaningful values for middle
    > chars and large chars.
    
    A different patch (about which Carlos had some concerns) was posted at 
    <https://sourceware.org/ml/libc-alpha/2015-07/msg00698.html>.  How do the 
    two compare?

Oh, I missed that patch from davem.

In the patch I am taking the same approach than in string/test-strcmp.c
and other existing tests, i.e. to keep do_test and do_test_final
interpreting align1 and align2 in number of characters, and not bytes.
The character->bytes conversion is performed by the caller.

It also adapts the middle-char and high-char values used in the tests to
wide chars, i.e. 255 is not a high value in the range of wide chars.

Note that dave's approach is used in some other tests, like
string/test-memcmp.c.

Both approaches are equally valid IMO.
diff mbox

Patch

diff --git a/ChangeLog b/ChangeLog
index 8f119fa..0686772 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@ 
+2016-05-30  Jose E. Marchesi  <jose.marchesi@oracle.com>
+
+	* string/test-strncmp.c [WIDE] (MIDCHAR): Defined.
+	[WIDE} (LARGECHAR): Likewise.
+	(MIDCHAR): Likewise.
+	(LARGECHAR): Likewise.
+	(test_main): Adapted to operate on with wide chars.
+
+2016-05-25  Jose E. Marchesi  <jose.marchesi@oracle.com>
+
+	* string/test-strncmp.c (do_test): ALIGN is an offset to CHAR*
+	pointers, not char*.
+
 2016-05-24  Joseph Myers  <joseph@codesourcery.com>
 
 	[BZ #15479]
diff --git a/string/test-strncmp.c b/string/test-strncmp.c
index 8c0a331..318773f 100644
--- a/string/test-strncmp.c
+++ b/string/test-strncmp.c
@@ -38,6 +38,8 @@ 
 # define CHAR wchar_t
 # define UCHAR wchar_t
 # define CHARBYTES 4
+# define MIDCHAR 0x7fffffff
+# define LARGECHAR 0xfffffffe
 # define CHAR__MAX WCHAR_MAX
 # define CHAR__MIN WCHAR_MIN
 
@@ -88,6 +90,8 @@  stupid_wcsncmp (const CHAR *s1, const CHAR *s2, size_t n)
 # define CHAR char
 # define UCHAR unsigned char
 # define CHARBYTES 1
+# define MIDCHAR 0x7f
+# define LARGECHAR 0xfe
 # define CHAR__MAX CHAR_MAX
 # define CHAR__MIN CHAR_MIN
 
@@ -414,56 +418,56 @@  test_main (void)
 
   for (i =0; i < 16; ++i)
     {
-      do_test (0, 0, 8, i, 127, 0);
-      do_test (0, 0, 8, i, 127, -1);
-      do_test (0, 0, 8, i, 127, 1);
-      do_test (i, i, 8, i, 127, 0);
-      do_test (i, i, 8, i, 127, 1);
-      do_test (i, i, 8, i, 127, -1);
-      do_test (i, 2 * i, 8, i, 127, 0);
-      do_test (2 * i, i, 8, i, 127, 1);
-      do_test (i, 3 * i, 8, i, 127, -1);
-      do_test (0, 0, 8, i, 255, 0);
-      do_test (0, 0, 8, i, 255, -1);
-      do_test (0, 0, 8, i, 255, 1);
-      do_test (i, i, 8, i, 255, 0);
-      do_test (i, i, 8, i, 255, 1);
-      do_test (i, i, 8, i, 255, -1);
-      do_test (i, 2 * i, 8, i, 255, 0);
-      do_test (2 * i, i, 8, i, 255, 1);
-      do_test (i, 3 * i, 8, i, 255, -1);
+      do_test (0, 0, 8, i, MIDCHAR, 0);
+      do_test (0, 0, 8, i, MIDCHAR, -1);
+      do_test (0, 0, 8, i, MIDCHAR, 1);
+      do_test (CHARBYTES * i, CHARBYTES * i, 8, i, MIDCHAR, 0);
+      do_test (CHARBYTES * i, CHARBYTES * i, 8, i, MIDCHAR, 1);
+      do_test (CHARBYTES * i, CHARBYTES * i, 8, i, MIDCHAR, -1);
+      do_test (CHARBYTES * i, 2 * CHARBYTES * i, 8, i, MIDCHAR, 0);
+      do_test (2 * CHARBYTES * i, CHARBYTES * i, 8, i, MIDCHAR, 1);
+      do_test (CHARBYTES * i, 3 * CHARBYTES * i, 8, i, MIDCHAR, -1);
+      do_test (0, 0, 8, i, LARGECHAR, 0);
+      do_test (0, 0, 8, i, LARGECHAR, -1);
+      do_test (0, 0, 8, i, LARGECHAR, 1);
+      do_test (CHARBYTES * i, CHARBYTES * i, 8, i, LARGECHAR, 0);
+      do_test (CHARBYTES * i, CHARBYTES * i, 8, i, LARGECHAR, 1);
+      do_test (CHARBYTES * i, CHARBYTES * i, 8, i, LARGECHAR, -1);
+      do_test (CHARBYTES * i, 2 * CHARBYTES * i, 8, i, LARGECHAR, 0);
+      do_test (2 * CHARBYTES * i, CHARBYTES * i, 8, i, LARGECHAR, 1);
+      do_test (CHARBYTES * i, 3 * CHARBYTES * i, 8, i, LARGECHAR, -1);
     }
 
   for (i = 1; i < 8; ++i)
     {
-      do_test (0, 0, 8 << i, 16 << i, 127, 0);
-      do_test (0, 0, 8 << i, 16 << i, 127, 1);
-      do_test (0, 0, 8 << i, 16 << i, 127, -1);
-      do_test (0, 0, 8 << i, 16 << i, 255, 0);
-      do_test (0, 0, 8 << i, 16 << i, 255, 1);
-      do_test (0, 0, 8 << i, 16 << i, 255, -1);
-      do_test (8 - i, 2 * i, 8 << i, 16 << i, 127, 0);
-      do_test (8 - i, 2 * i, 8 << i, 16 << i, 127, 1);
-      do_test (2 * i, i, 8 << i, 16 << i, 255, 0);
-      do_test (2 * i, i, 8 << i, 16 << i, 255, 1);
+      do_test (0, 0, 8 << i, 16 << i, MIDCHAR, 0);
+      do_test (0, 0, 8 << i, 16 << i, MIDCHAR, 1);
+      do_test (0, 0, 8 << i, 16 << i, MIDCHAR, -1);
+      do_test (0, 0, 8 << i, 16 << i, LARGECHAR, 0);
+      do_test (0, 0, 8 << i, 16 << i, LARGECHAR, 1);
+      do_test (0, 0, 8 << i, 16 << i, LARGECHAR, -1);
+      do_test (CHARBYTES * (8 - i), 2 * CHARBYTES * i, 8 << i, 16 << i, MIDCHAR, 0);
+      do_test (CHARBYTES * (8 - i), 2 * CHARBYTES * i, 8 << i, 16 << i, MIDCHAR, 1);
+      do_test (2 * CHARBYTES * i, CHARBYTES * i, 8 << i, 16 << i, LARGECHAR, 0);
+      do_test (2 * CHARBYTES * i, CHARBYTES * i, 8 << i, 16 << i, LARGECHAR, 1);
     }
 
-  do_test_limit (0, 0, 0, 0, 127, 0);
-  do_test_limit (4, 0, 21, 20, 127, 0);
-  do_test_limit (0, 4, 21, 20, 127, 0);
-  do_test_limit (8, 0, 25, 24, 127, 0);
-  do_test_limit (0, 8, 25, 24, 127, 0);
+  do_test_limit (0, 0, 0, 0, MIDCHAR, 0);
+  do_test_limit (CHARBYTES * 4, 0, 21, 20, MIDCHAR, 0);
+  do_test_limit (0, CHARBYTES * 4, 21, 20, MIDCHAR, 0);
+  do_test_limit (CHARBYTES * 8, 0, 25, 24, MIDCHAR, 0);
+  do_test_limit (0, CHARBYTES * 8, 25, 24, MIDCHAR, 0);
 
   for (i = 0; i < 8; ++i)
     {
-      do_test_limit (0, 0, 17 - i, 16 - i, 127, 0);
-      do_test_limit (0, 0, 17 - i, 16 - i, 255, 0);
-      do_test_limit (0, 0, 15 - i, 16 - i, 127, 0);
-      do_test_limit (0, 0, 15 - i, 16 - i, 127, 1);
-      do_test_limit (0, 0, 15 - i, 16 - i, 127, -1);
-      do_test_limit (0, 0, 15 - i, 16 - i, 255, 0);
-      do_test_limit (0, 0, 15 - i, 16 - i, 255, 1);
-      do_test_limit (0, 0, 15 - i, 16 - i, 255, -1);
+      do_test_limit (0, 0, 17 - i, 16 - i, MIDCHAR, 0);
+      do_test_limit (0, 0, 17 - i, 16 - i, LARGECHAR, 0);
+      do_test_limit (0, 0, 15 - i, 16 - i, MIDCHAR, 0);
+      do_test_limit (0, 0, 15 - i, 16 - i, MIDCHAR, 1);
+      do_test_limit (0, 0, 15 - i, 16 - i, MIDCHAR, -1);
+      do_test_limit (0, 0, 15 - i, 16 - i, LARGECHAR, 0);
+      do_test_limit (0, 0, 15 - i, 16 - i, LARGECHAR, 1);
+      do_test_limit (0, 0, 15 - i, 16 - i, LARGECHAR, -1);
     }
 
   do_random_tests ();