This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v2][BZ 14561] Testcase
- From: "Carlos O'Donell" <carlos at redhat dot com>
- To: OndÅej BÃlka <neleai at seznam dot cz>
- Cc: libc-alpha at sourceware dot org
- Date: Tue, 04 Jun 2013 10:44:28 -0400
- Subject: Re: [PATCH v2][BZ 14561] Testcase
- References: <20130520190628 dot GA22088 at domone dot kolej dot mff dot cuni dot cz> <519E93F3 dot 8060203 at redhat dot com> <20130603204113 dot GA26974 at domone dot kolej dot mff dot cuni dot cz> <51ADE6C1 dot 1030806 at redhat dot com> <20130604142546 dot GA32680 at domone dot kolej dot mff dot cuni dot cz>
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.
> Here is v2.
>
> * bug-srand-srandom-dependency.c: New file.
> * Makefile (tests): Add it.
>
> ---
> stdlib/Makefile | 3 +-
> stdlib/bug-srand-srandom-dependency.c | 86 +++++++++++++++++++++++++++++++++
> 2 files changed, 88 insertions(+), 1 deletion(-)
> create mode 100644 stdlib/bug-srand-srandom-dependency.c
>
> 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..2ed5261
> --- /dev/null
> +++ b/stdlib/bug-srand-srandom-dependency.c
> @@ -0,0 +1,86 @@
> +/* Test that srand and srandom do not interact.
Mention BZ#.
> + 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
> +do_test (void)
> +{
> + char buf[1000], *p;
Big enough?
> +#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.
> + 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;
> + if (randstate == 2 && rand2 != rand ())
> + FAIL;
> + 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;
> + if (randomstate == 2 && random2 != random ())
> + FAIL;
> + randomstate++;
> + }
> + }
> + return 0;
> +}
> +
> +#define TEST_FUNCTION do_test ()
> +#include "../test-skeleton.c"
>
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.
Cheers,
Carlos.