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]

Re: [PATCH v3][BZ 14561] Testcase


On Tue, Jun 04, 2013 at 10:44:28AM -0400, Carlos O'Donell wrote:
> On 06/04/2013 10:25 AM, OndÅej BÃlka wrote:
> > On Tue, Jun 04, 2013 at 09:08:17AM -0400, Carlos O'Donell wrote:
> >> This is a good first pass, but we need to make this easier to debug
> >> when it fails and when we switch to PASS/FAIL test we should be able
> >> to explain which ordering failed.
> >>
> > I plan to add a breakpoint() function to test which counts times it was
> > called before failure(or signal). Then we can output something like:
> > 
> > FAIL, Type following for debugging:
> > 
> > SKIP = 2341 gdb command
> > b breakpoint_fail
> > r
> > 
> > I could relatively easily add it to most test* with spatch.
> 
> Interesting idea.
> 
> >> Each of the `return 1'; needs to be able to print the ordering
> >> which lead to the failure (since it might be intermittent).
> >>
> >> If that's too difficult to do then I suggest manually (using
> >> a script) unrolling this loop into a static ordering that can
> >> use distinct messages for each failure state.
> >>
> >> Feel free to compact the error message printout to something
> >> like: "FAIL: Order was rRr.\n"
> >>
> > I decided to print sequence of calls.
> 
> I like that. Thanks.
> 
> > +++ b/stdlib/bug-srand-srandom-dependency.c
> > @@ -0,0 +1,86 @@
> > +/* Test that srand and srandom do not interact.
> 
> Mention BZ#.
>
Done. 
> > +do_test (void)
> > +{
> > +  char buf[1000], *p;
> 
> Big enough?
>
Buffer here is used only for single sequence and then reset to
beginning. A 1000 bytes should be enough.

I was ending on first failure so I decided to collect all failures.

> > +#define FAIL {                                                                \
> > +    fputs ("Inconsisted results for sequence:\n",stderr);                     \
> > +    fputs (buf, stderr);                                                      \
> > +    return 1;                                                                 \
> > +}
> 
> Please make this a function so you can easily put a breakpoint on it.
>
Done.
 
> Looks good to me with above two changes and proof 
> that 1000 bytes is enough, otherwise use 8kb, which
> is certainly large enough for 6144 (64*6*13) bytes
> of messages.
> 
When this is good and rand is also good is this OK to commit them both?

Ondra

	* bug-srand-srandom-dependency.c: New file.
	* Makefile (tests): Add it.


diff --git a/stdlib/Makefile b/stdlib/Makefile
index 17d80e0..9433cda 100644
--- a/stdlib/Makefile
+++ b/stdlib/Makefile
@@ -71,7 +71,8 @@ tests		:= tst-strtol tst-strtod testmb testrand testsort testdiv   \
 		   tst-makecontext2 tst-strtod6 tst-unsetenv1		    \
 		   tst-makecontext3 bug-getcontext bug-fmtmsg1		    \
 		   tst-secure-getenv tst-strtod-overflow tst-strtod-round   \
-		   tst-tininess tst-strtod-underflow tst-tls-atexit
+		   tst-tininess tst-strtod-underflow tst-tls-atexit         \
+		   bug-srand-srandom-dependency
 tests-static	:= tst-secure-getenv
 
 modules-names	= tst-tls-atexit-lib
diff --git a/stdlib/bug-srand-srandom-dependency.c b/stdlib/bug-srand-srandom-dependency.c
new file mode 100644
index 0000000..2cf0864
--- /dev/null
+++ b/stdlib/bug-srand-srandom-dependency.c
@@ -0,0 +1,93 @@
+/* Test that srand and srandom do not interact. See BZ #14561.
+   Copyright (C) 2013 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int failed;
+
+static __attribute__ ((__noinline__))
+void
+fail (char *buf)
+{
+  fputs ("FAIL: Inconsistent results for sequence:\n", stderr);
+  fputs (buf, stderr);
+  failed = 1;
+}
+
+int
+do_test (void)
+{
+  failed = 0;
+  char buf[1000], *p;
+  int rand1, rand2;
+  int random1, random2;
+
+  srand (43);
+  rand1 = rand ();
+  rand2 = rand ();
+  srandom (42);
+  random1 = random ();
+  random2 = random ();
+  /* The six lines above are sequentialy ordered. We try interleave rand and
+     random parts in all possible ways and check if they give same results.   */
+  for (int com = 0; com < 64; com++)
+    {
+      p = buf;
+      int randstate = 0, randomstate = 0;
+      for (int i = 0; i < 6; i++)
+	if (com & (1 << i))
+	  {
+	    if (randstate == 0)
+	      p += sprintf (p, "srand(43);\n");
+	    if (randstate == 1)
+	      p += sprintf (p, "rand();\n");
+	    if (randstate == 2)
+	      p += sprintf (p, "rand();\n");
+
+	    if (randstate == 0)
+	      srand (43);
+	    if (randstate == 1 && rand1 != rand ())
+	      fail (buf);
+	    if (randstate == 2 && rand2 != rand ())
+	      fail (buf);
+	    randstate++;
+	  }
+	else
+	  {
+	    if (randomstate == 0)
+	      p += sprintf (p, "srandom(42);\n");
+	    if (randomstate == 1)
+	      p += sprintf (p, "random();\n");
+	    if (randomstate == 2)
+	      p += sprintf (p, "random();\n");
+
+	    if (randomstate == 0)
+	      srandom (42);
+	    if (randomstate == 1 && random1 != random ())
+	      fail (buf);
+	    if (randomstate == 2 && random2 != random ())
+	      fail (buf);
+	    randomstate++;
+	  }
+    }
+  return failed;
+}
+
+#define TEST_FUNCTION   do_test ()
+#include "../test-skeleton.c"
-- 
1.7.10.4


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