summaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2006-12-19 19:05:41 +0000
committerJakub Jelinek <jakub@redhat.com>2006-12-19 19:05:41 +0000
commit1f09da09fed864c91288ff91295114fa5202edaa (patch)
tree34245c0ec96f394eb4af0caad3c1050edc6757af /stdlib
parentb51633c5723e311ffd59a2f5ec5759914ed9476b (diff)
Updated to fedora-glibc-20061219T1804cvs/fedora-glibc-2_5_90-14
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/Makefile3
-rw-r--r--stdlib/jrand48_r.c4
-rw-r--r--stdlib/tst-makecontext.c57
-rw-r--r--stdlib/tst-rand48-2.c113
-rw-r--r--stdlib/tst-rand48.c28
5 files changed, 188 insertions, 17 deletions
diff --git a/stdlib/Makefile b/stdlib/Makefile
index 64a237f820..2699ca61f6 100644
--- a/stdlib/Makefile
+++ b/stdlib/Makefile
@@ -67,7 +67,8 @@ tests := tst-strtol tst-strtod testmb testrand testsort testdiv \
tst-xpg-basename tst-random tst-random2 tst-bsearch \
tst-limits tst-rand48 bug-strtod tst-setcontext \
test-a64l tst-qsort tst-system testmb2 bug-strtod2 \
- tst-atof1 tst-atof2 tst-strtod2 tst-strtod3
+ tst-atof1 tst-atof2 tst-strtod2 tst-strtod3 tst-rand48-2 \
+ tst-makecontext
include ../Makeconfig
diff --git a/stdlib/jrand48_r.c b/stdlib/jrand48_r.c
index 2383ae129e..39e8d090a6 100644
--- a/stdlib/jrand48_r.c
+++ b/stdlib/jrand48_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 1997, 1998, 2001, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
@@ -30,7 +30,7 @@ __jrand48_r (xsubi, buffer, result)
return -1;
/* Store the result. */
- *result = ((xsubi[2] << 16) | xsubi[1]) & 0xffffffffl;
+ *result = (int32_t) ((xsubi[2] << 16) | xsubi[1]);
return 0;
}
diff --git a/stdlib/tst-makecontext.c b/stdlib/tst-makecontext.c
new file mode 100644
index 0000000000..cbce71fb92
--- /dev/null
+++ b/stdlib/tst-makecontext.c
@@ -0,0 +1,57 @@
+/* Copyright (C) 2006 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <ucontext.h>
+
+ucontext_t ucp;
+char st1[8192];
+__thread int thr;
+
+void
+cf (int i)
+{
+ if (i != 78 || thr != 94)
+ {
+ printf ("i %d thr %d\n", i, thr);
+ exit (1);
+ }
+ exit (0);
+}
+
+int
+main (void)
+{
+ if (getcontext (&ucp) != 0)
+ {
+ puts ("getcontext failed");
+ return 1;
+ }
+ thr = 94;
+ ucp.uc_link = NULL;
+ ucp.uc_stack.ss_sp = st1;
+ ucp.uc_stack.ss_size = sizeof st1;
+ makecontext (&ucp, (void (*) ()) cf, 1, 78);
+ if (setcontext (&ucp) != 0)
+ {
+ puts ("setcontext failed");
+ return 1;
+ }
+ return 2;
+}
diff --git a/stdlib/tst-rand48-2.c b/stdlib/tst-rand48-2.c
new file mode 100644
index 0000000000..3079b98839
--- /dev/null
+++ b/stdlib/tst-rand48-2.c
@@ -0,0 +1,113 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+int
+main (void)
+{
+ time_t t = time (NULL);
+ int i, ret = 0;
+ double d;
+ long int l;
+ struct drand48_data data;
+ unsigned short int buf[3];
+
+ srand48 ((long int) t);
+ for (i = 0; i < 50; i++)
+ if ((d = drand48 ()) < 0.0 || d >= 1.0)
+ {
+ printf ("drand48 %d %g\n", i, d);
+ ret = 1;
+ }
+
+ srand48_r ((long int) t, &data);
+ for (i = 0; i < 50; i++)
+ if (drand48_r (&data, &d) != 0 || d < 0.0 || d >= 1.0)
+ {
+ printf ("drand48_r %d %g\n", i, d);
+ ret = 1;
+ }
+
+ buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
+ for (i = 0; i < 50; i++)
+ if ((d = erand48 (buf)) < 0.0 || d >= 1.0)
+ {
+ printf ("erand48 %d %g\n", i, d);
+ ret = 1;
+ }
+
+ buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
+ for (i = 0; i < 50; i++)
+ if (erand48_r (buf, &data, &d) != 0 || d < 0.0 || d >= 1.0)
+ {
+ printf ("erand48_r %d %g\n", i, d);
+ ret = 1;
+ }
+
+ srand48 ((long int) t);
+ for (i = 0; i < 50; i++)
+ if ((l = lrand48 ()) < 0 || l > INT32_MAX)
+ {
+ printf ("lrand48 %d %ld\n", i, l);
+ ret = 1;
+ }
+
+ srand48_r ((long int) t, &data);
+ for (i = 0; i < 50; i++)
+ if (lrand48_r (&data, &l) != 0 || l < 0 || l > INT32_MAX)
+ {
+ printf ("lrand48_r %d %ld\n", i, l);
+ ret = 1;
+ }
+
+ buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
+ for (i = 0; i < 50; i++)
+ if ((l = nrand48 (buf)) < 0 || l > INT32_MAX)
+ {
+ printf ("nrand48 %d %ld\n", i, l);
+ ret = 1;
+ }
+
+ buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
+ for (i = 0; i < 50; i++)
+ if (nrand48_r (buf, &data, &l) != 0 || l < 0 || l > INT32_MAX)
+ {
+ printf ("nrand48_r %d %ld\n", i, l);
+ ret = 1;
+ }
+
+ srand48 ((long int) t);
+ for (i = 0; i < 50; i++)
+ if ((l = mrand48 ()) < INT32_MIN || l > INT32_MAX)
+ {
+ printf ("mrand48 %d %ld\n", i, l);
+ ret = 1;
+ }
+
+ srand48_r ((long int) t, &data);
+ for (i = 0; i < 50; i++)
+ if (mrand48_r (&data, &l) != 0 || l < INT32_MIN || l > INT32_MAX)
+ {
+ printf ("mrand48_r %d %ld\n", i, l);
+ ret = 1;
+ }
+
+ buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
+ for (i = 0; i < 50; i++)
+ if ((l = jrand48 (buf)) < INT32_MIN || l > INT32_MAX)
+ {
+ printf ("jrand48 %d %ld\n", i, l);
+ ret = 1;
+ }
+
+ buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
+ for (i = 0; i < 50; i++)
+ if (jrand48_r (buf, &data, &l) != 0 || l < INT32_MIN || l > INT32_MAX)
+ {
+ printf ("jrand48_r %d %ld\n", i, l);
+ ret = 1;
+ }
+
+ return ret;
+}
diff --git a/stdlib/tst-rand48.c b/stdlib/tst-rand48.c
index fd2c4c1955..52e1b96afe 100644
--- a/stdlib/tst-rand48.c
+++ b/stdlib/tst-rand48.c
@@ -44,10 +44,10 @@ main (void)
}
l = mrand48 ();
- if (l != 0xa28c1003l)
+ if (l != -0x5d73effdl)
{
printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
- __LINE__ - 4, 0xa28c1003l, l);
+ __LINE__ - 4, -0x5d73effdl, l);
result = 1;
}
@@ -60,10 +60,10 @@ main (void)
}
l = mrand48 ();
- if (l != 0x9e88f474l)
+ if (l != -0x61770b8cl)
{
printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
- __LINE__ - 4, 0x9e88f474l, l);
+ __LINE__ - 4, -0x61770b8cl, l);
result = 1;
}
@@ -92,10 +92,10 @@ main (void)
}
l = mrand48 ();
- if (l != 0xeb7a1fa3l)
+ if (l != -0x1485e05dl)
{
printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
- __LINE__ - 4, 0xeb7a1fa3l, l);
+ __LINE__ - 4, -0x1485e05dl, l);
result = 1;
}
@@ -171,10 +171,10 @@ main (void)
}
l = mrand48 ();
- if (l != 0xa28c1003l)
+ if (l != -0x5d73effdl)
{
printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
- __LINE__ - 4, 0xa28c1003l, l);
+ __LINE__ - 4, -0x5d73effdl, l);
result = 1;
}
@@ -187,10 +187,10 @@ main (void)
}
l = mrand48 ();
- if (l != 0x9e88f474l)
+ if (l != -0x61770b8cl)
{
printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
- __LINE__ - 4, 0x9e88f474l, l);
+ __LINE__ - 4, -0x61770b8cl, l);
result = 1;
}
@@ -231,10 +231,10 @@ main (void)
}
l = mrand48 ();
- if (l != 0xeb7a1fa3l)
+ if (l != -0x1485e05dl)
{
printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
- __LINE__ - 4, 0xeb7a1fa3l, l);
+ __LINE__ - 4, -0x1485e05dl, l);
result = 1;
}
@@ -287,10 +287,10 @@ main (void)
}
l = jrand48 (xs);
- if (l != 0xf568c7a0l)
+ if (l != -0xa973860l)
{
printf ("jrand48() in line %d failed: expected %lx, seen %lx\n",
- __LINE__ - 4, 0xf568c7a0l, l);
+ __LINE__ - 4, -0xa973860l, l);
result = 1;
}