Mercurial > ecos
annotate packages/language/c/libc/current/tests/stdlib/rand1.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 // rand1.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 <stdlib.h> | |
| 53 #include <cyg/infra/testcase.h> | |
| 54 #include <sys/cstartup.h> // C library initialisation | |
| 55 | |
| 56 | |
| 57 // HOW TO START TESTS | |
| 58 | |
| 2 | 59 #if defined(CYGPKG_LIBC) |
| 0 | 60 |
| 61 # define START_TEST( test ) test(0) | |
| 62 | |
| 63 #else | |
| 64 | |
| 65 # define START_TEST( test ) CYG_EMPTY_STATEMENT | |
| 66 | |
| 67 #endif // if defined(CYGPKG_LIBC) | |
| 68 | |
| 69 | |
| 70 // CONSTANTS | |
| 71 | |
| 72 // This is the max allowable hits, where a hit is an element | |
| 73 // of a random array being the same as index+1 or index+2 | |
| 74 #define TOLERANCE 2 | |
| 75 | |
| 76 // FUNCTIONS | |
| 77 | |
| 78 | |
| 79 externC void | |
| 80 cyg_package_start( void ) | |
| 81 { | |
| 82 #ifdef CYGPKG_LIBC | |
| 83 cyg_iso_c_start(); | |
| 84 #else | |
| 85 (void)main(0, NULL); | |
| 86 #endif | |
| 87 } // cyg_package_start() | |
| 88 | |
| 89 | |
| 90 | |
| 2 | 91 #if defined(CYGPKG_LIBC) |
| 0 | 92 |
| 93 static void | |
| 94 test( CYG_ADDRWORD data ) | |
| 95 { | |
| 96 int ctr; | |
| 97 static int array[1024]; | |
| 98 int hits=0; | |
| 99 | |
| 100 for (ctr=0; ctr<1024; ctr++) | |
| 101 array[ctr] = rand(); | |
| 102 | |
| 103 for (ctr=0; ctr< 1021; ctr++) | |
| 104 if ((array[ctr]==array[ctr+1]) || | |
| 105 (array[ctr]==array[ctr+2]) || | |
| 106 (array[ctr]==array[ctr+3])) | |
| 107 hits++; | |
| 108 | |
| 2 | 109 CYG_TEST_PASS_FAIL(hits <= TOLERANCE, |
| 110 "Simple test for rand() repetition"); | |
| 0 | 111 |
| 2 | 112 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for " |
| 113 "C library rand() function"); | |
| 0 | 114 } // test() |
| 115 | |
| 2 | 116 #endif // if defined(CYGPKG_LIBC) |
| 0 | 117 |
| 118 | |
| 119 int | |
| 120 main(int argc, char *argv[]) | |
| 121 { | |
| 122 CYG_TEST_INIT(); | |
| 123 | |
| 124 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library " | |
| 125 "rand() function"); | |
| 126 | |
| 127 START_TEST( test ); | |
| 128 | |
| 2 | 129 CYG_TEST_NA("Testing is not applicable to this configuration"); |
| 0 | 130 } // main() |
| 131 | |
| 132 // EOF rand1.c |
