This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Testing of memcmp(). Possible patch to tester.c


Hello,

the following message was originally sent to the uClibc ML,
but in a response to that, Mike Frysinger <vapier@gentoo.org>
suggested that I should resend this message also to you.
If I understand him correctly he is considering to somehow
incorporate my idea to the testing package for uClibc,
and that you folks working on the large C-library, would possibly
find my idea not utterly without merit!


(Original message and code patch now follow.)


Hello there,

the attached difference file addresses the problem of
better detecting a malfunctioning memcmp() call. It concerns
the file

	uClibc-0.9.29/test/string/tester.c

in the test suite. Where possible the old test cases were
rebuilt to avoid the return values (from memcmp) +1 and -1,
but still only positivity and negativity are tested for.
This was done in order to better disclose problems with
the optimized and architecture specific implementations.
In addition, there are some new test cases gleaned from
Dropbear, and which conduct tests with shifting alignment.
Of course, not all of these twenty test cases are independent,
but in more verbose forms they were instrumental when I
debugged architecture specific assembly code for an embedded
system (not yet incorporated into the code base of uClibc).
It was also essential to use a flag "-fno-builtin" to detect the
failures, both for the old test cases and these new ones.

Based I on this recent experience, I have begun developing
a modified testing machinery that better would issue warnings
for false positives. The effort to avoid return values +1 and -1
is an afterglow of this methodology. Since the present test
suite is somewhat awkward to use in cross compiled settings,
I might come back to that issue another time.

Best regards for now

Ynglingatal


--- /tmp/test/string/tester.c.orig	2007-10-27 19:36:22.998411224 +0200
+++ /tmp/test/string/tester.c	2007-10-27 19:36:08.118673288 +0200
@@ -1087,15 +1087,31 @@
 static void
 test_memcmp (void)
 {
+  int i, cnt = 1;
+  char one[21], two[21];
+  
   it = "memcmp";
-  check(memcmp("a", "a", 1) == 0, 1);		/* Identity. */
-  check(memcmp("abc", "abc", 3) == 0, 2);	/* Multicharacter. */
-  check(memcmp("abcd", "abce", 4) < 0, 3);	/* Honestly unequal. */
-  check(memcmp("abce", "abcd", 4) > 0, 4);
-  check(memcmp("alph", "beta", 4) < 0, 5);
-  check(memcmp("a\203", "a\003", 2) > 0, 6);
-  check(memcmp("abce", "abcd", 3) == 0, 7);	/* Count limited. */
-  check(memcmp("abc", "def", 0) == 0, 8);	/* Zero count. */
+  check(memcmp("a", "a", 1) == 0, cnt++);	/* Identity. */
+  check(memcmp("abc", "abc", 3) == 0, cnt++);	/* Multicharacter. */
+  check(memcmp("abcd", "abcf", 4) < 0, cnt++);	/* Honestly unequal. */
+  check(memcmp("abcf", "abcd", 4) > 0, cnt++);
+  check(memcmp("alph", "cold", 4) < 0, cnt++);
+  check(memcmp("a\203", "a\003", 2) > 0, cnt++);
+  check(memcmp("a\003", "a\203", 2) < 0, cnt++);
+  check(memcmp("a\003bc", "a\203bc", 2) < 0, cnt++);
+  check(memcmp("abc\203", "abc\003", 4) > 0, cnt++);
+  check(memcmp("abc\003", "abc\203", 4) < 0, cnt++);
+  check(memcmp("abcf", "abcd", 3) == 0, cnt++);	/* Count limited. */
+  check(memcmp("abc", "def", 0) == 0, cnt++);	/* Zero count. */
+  /* Comparisons with shifting 4-byte boundaries. */
+  for (i=0; i<4; i++)
+  {
+    char *a = one + i, *b = two + i;
+    strncpy( a, "--------11112222", 16);
+    strncpy( b, "--------33334444", 16);
+    check( memcmp(b, a, 16) > 0, cnt++);
+    check( memcmp(a, b, 16) < 0, cnt++);
+  }
 }
 
 static void

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]