diff options
| author | [email protected] <[email protected]> | 2010-11-18 11:31:54 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2010-11-18 11:31:54 +0000 |
| commit | d9cb84f4840c49993cfbcc80057488c50eae60cb (patch) | |
| tree | 9077055207bb6faa59cd565d37a77aa12e39b53c /examples/libc/rand.c | |
| parent | 019b6542012115190cfbde415532c8940cc47500 (diff) | |
add libc testcase.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1061 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'examples/libc/rand.c')
| -rw-r--r-- | examples/libc/rand.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/libc/rand.c b/examples/libc/rand.c new file mode 100644 index 0000000000..ca74353adc --- /dev/null +++ b/examples/libc/rand.c @@ -0,0 +1,43 @@ +/*
+ * rand.c
+ *
+ * Created on: 2010-11-17
+ * Author: bernard
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <finsh.h>
+
+int libc_rand(void)
+{
+ int i1, i2;
+ int j1, j2;
+
+ /* The C standard says that "If rand is called before any calls to
+ srand have been made, the same sequence shall be generated as
+ when srand is first called with a seed value of 1." */
+ i1 = rand();
+ i2 = rand();
+ srand(1);
+ j1 = rand();
+ j2 = rand();
+ if (i1 < 0 || i2 < 0 || j1 < 0 || j2 < 0)
+ {
+ puts("Test FAILED!");
+ }
+ if (j1 == i1 && j2 == i2)
+ {
+ puts("Test succeeded.");
+ return 0;
+ }
+ else
+ {
+ if (j1 != i1)
+ printf("%d != %d\n", j1, i1);
+ if (j2 != i2)
+ printf("%d != %d\n", j2, i2);
+ puts("Test FAILED!");
+ return 1;
+ }
+}
+FINSH_FUNCTION_EXPORT(libc_rand, rand test for libc);
|
