|
0
|
1 //================================================================= |
|
|
2 // |
|
|
3 // rand1.c |
|
|
4 // |
|
|
5 // Testcase for C library rand() |
|
|
6 // |
|
|
7 //================================================================= |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
|
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. |
|
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //================================================================= |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
|
32 // Author(s): ctarpy@cygnus.co.uk, jlarmour@cygnus.co.uk |
|
|
33 // Contributors: jlarmour@cygnus.co.uk |
|
|
34 // Date: 1998/6/3 |
|
|
35 // Description: Contains testcode for C library rand() function |
|
|
36 // |
|
|
37 // |
|
|
38 //####DESCRIPTIONEND#### |
|
|
39 |
|
|
40 // Declarations for test system: |
|
|
41 // |
|
|
42 // TESTCASE_TYPE=CYG_TEST_MODULE |
|
|
43 |
|
|
44 // CONFIGURATION |
|
|
45 |
|
|
46 #include <pkgconf/libc.h> // Configuration header |
|
|
47 |
|
|
48 // INCLUDES |
|
|
49 |
|
|
50 #include <stdlib.h> |
|
|
51 #include <cyg/infra/testcase.h> |
|
|
52 #include <sys/cstartup.h> // C library initialisation |
|
|
53 |
|
|
54 |
|
|
55 // HOW TO START TESTS |
|
|
56 |
|
|
57 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_RAND) |
|
|
58 |
|
|
59 # define START_TEST( test ) test(0) |
|
|
60 |
|
|
61 #else |
|
|
62 |
|
|
63 # define START_TEST( test ) CYG_EMPTY_STATEMENT |
|
|
64 |
|
|
65 #endif // if defined(CYGPKG_LIBC) |
|
|
66 |
|
|
67 |
|
|
68 // CONSTANTS |
|
|
69 |
|
|
70 // This is the max allowable hits, where a hit is an element |
|
|
71 // of a random array being the same as index+1 or index+2 |
|
|
72 #define TOLERANCE 2 |
|
|
73 |
|
|
74 // FUNCTIONS |
|
|
75 |
|
|
76 |
|
|
77 externC void |
|
|
78 cyg_package_start( void ) |
|
|
79 { |
|
|
80 #ifdef CYGPKG_LIBC |
|
|
81 cyg_iso_c_start(); |
|
|
82 #else |
|
|
83 (void)main(0, NULL); |
|
|
84 #endif |
|
|
85 } // cyg_package_start() |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_RAND) |
|
|
90 |
|
|
91 static void |
|
|
92 test( CYG_ADDRWORD data ) |
|
|
93 { |
|
|
94 int ctr; |
|
|
95 static int array[1024]; |
|
|
96 int hits=0; |
|
|
97 |
|
|
98 for (ctr=0; ctr<1024; ctr++) |
|
|
99 array[ctr] = rand(); |
|
|
100 |
|
|
101 for (ctr=0; ctr< 1021; ctr++) |
|
|
102 if ((array[ctr]==array[ctr+1]) || |
|
|
103 (array[ctr]==array[ctr+2]) || |
|
|
104 (array[ctr]==array[ctr+3])) |
|
|
105 hits++; |
|
|
106 |
|
|
107 CYG_TEST_PASS_FAIL(hits <= TOLERANCE, "Simple test for rand() repetition"); |
|
|
108 |
|
|
109 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library " |
|
|
110 "rand() function"); |
|
|
111 } // test() |
|
|
112 |
|
|
113 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_RAND) |
|
|
114 |
|
|
115 |
|
|
116 int |
|
|
117 main(int argc, char *argv[]) |
|
|
118 { |
|
|
119 CYG_TEST_INIT(); |
|
|
120 |
|
|
121 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library " |
|
|
122 "rand() function"); |
|
|
123 |
|
|
124 START_TEST( test ); |
|
|
125 |
|
|
126 CYG_TEST_PASS_FINISH("Testing is not applicable to this configuration"); |
|
|
127 } // main() |
|
|
128 |
|
|
129 // EOF rand1.c |