Mercurial > ecos
annotate packages/language/c/libc/current/tests/stdlib/rand2.c @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children |
| rev | line source |
|---|---|
| 0 | 1 //================================================================= |
| 2 // | |
| 3 // rand2.c | |
| 4 // | |
| 5 // Testcase for C library rand() | |
| 6 // | |
| 7 //================================================================= | |
| 8 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 // Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
21 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
24 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
25 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
29 // |
| 0 | 30 //####COPYRIGHTEND#### |
| 31 //================================================================= | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 2 | 34 // Author(s): ctarpy, jlarmour |
| 35 // Contributors: jlarmour | |
| 36 // Date: 1999-01-20 | |
| 0 | 37 // Description: Contains testcode for C library rand() function |
| 38 // | |
| 39 // | |
| 40 //####DESCRIPTIONEND#### | |
| 41 | |
| 42 // Declarations for test system: | |
| 43 // | |
| 44 // TESTCASE_TYPE=CYG_TEST_MODULE | |
| 45 | |
| 46 // CONFIGURATION | |
| 47 | |
| 48 #include <pkgconf/libc.h> // Configuration header | |
| 49 | |
| 50 // INCLUDES | |
| 51 | |
| 52 #include <pkgconf/libc.h> // CYGNUM_LIBC_RAND_SEED | |
| 53 #include <stdlib.h> | |
| 54 #include <cyg/infra/testcase.h> | |
| 55 #include <sys/cstartup.h> // C library initialisation | |
| 56 | |
| 57 | |
| 58 // HOW TO START TESTS | |
| 59 | |
| 2 | 60 #if defined(CYGPKG_LIBC) |
| 0 | 61 |
| 62 # define START_TEST( test ) test(0) | |
| 63 | |
| 64 #else | |
| 65 | |
| 66 # define START_TEST( test ) CYG_EMPTY_STATEMENT | |
| 67 | |
| 68 #endif // if defined(CYGPKG_LIBC) | |
| 69 | |
| 70 | |
| 71 // FUNCTIONS | |
| 72 | |
| 73 externC void | |
| 74 cyg_package_start( void ) | |
| 75 { | |
| 76 #ifdef CYGPKG_LIBC | |
| 77 cyg_iso_c_start(); | |
| 78 #else | |
| 79 (void)main(0, NULL); | |
| 80 #endif | |
| 81 } // cyg_package_start() | |
| 82 | |
| 83 | |
| 2 | 84 #if defined(CYGPKG_LIBC) |
| 0 | 85 |
| 86 static void | |
| 87 test( CYG_ADDRWORD data ) | |
| 88 { | |
| 89 static int rand_data1[100]; | |
| 90 static int rand_data2[100]; | |
| 91 int count; | |
| 92 int fail=0; | |
| 93 | |
| 94 // Test that rand starts with the seed as CYGNUM_LIBC_RAND_SEED | |
| 95 | |
| 2 | 96 for ( count=0; count < 100; ++count ) { |
| 0 | 97 rand_data1[count] = rand(); |
| 98 } // for | |
| 99 | |
| 100 // set seed to CYGNUM_LIBC_RAND_SEED | |
| 101 srand(CYGNUM_LIBC_RAND_SEED); | |
| 102 | |
| 2 | 103 for ( count=0; count < 100; ++count ) { |
| 0 | 104 rand_data2[count] = rand(); |
| 105 } // for | |
| 106 | |
| 2 | 107 for ( count=0; count < 100; ++count ) { |
| 0 | 108 if (rand_data1[count] != rand_data2[count]) |
| 109 ++fail; | |
| 110 } // for | |
| 111 | |
| 112 CYG_TEST_PASS_FAIL(fail==0, "rand() has seed initialised to " | |
| 113 "CYGNUM_LIBC_RAND_SEED"); | |
| 114 | |
| 115 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C " | |
| 116 "library rand() function"); | |
| 117 } // test() | |
| 118 | |
| 2 | 119 #endif // if defined(CYGPKG_LIBC) |
| 0 | 120 |
| 121 | |
| 122 int | |
| 123 main(int argc, char *argv[]) | |
| 124 { | |
| 125 CYG_TEST_INIT(); | |
| 126 | |
| 127 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C " | |
| 128 "library rand() function"); | |
| 129 | |
| 130 START_TEST( test ); | |
| 131 | |
| 2 | 132 CYG_TEST_NA("Testing is not applicable to this configuration"); |
| 0 | 133 } // main() |
| 134 | |
| 135 | |
| 136 // EOF rand2.c |
