comparison packages/language/c/libc/current/tests/stdlib/rand2.c @ 0:3111d98ba7b3 ecos-v1_1-release

Initial commit of eCos version 1.1
author jlarmour
date Tue, 11 May 1999 11:16:07 +0000
parents
children 443894e2e912
comparison
equal deleted inserted replaced
-1:000000000000 0:3111d98ba7b3
1 //=================================================================
2 //
3 // rand2.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 <pkgconf/libc.h> // CYGNUM_LIBC_RAND_SEED
51 #include <stdlib.h>
52 #include <cyg/infra/testcase.h>
53 #include <sys/cstartup.h> // C library initialisation
54
55
56 // HOW TO START TESTS
57
58 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_RAND)
59
60 # define START_TEST( test ) test(0)
61
62 #else
63
64 # define START_TEST( test ) CYG_EMPTY_STATEMENT
65
66 #endif // if defined(CYGPKG_LIBC)
67
68
69 // FUNCTIONS
70
71 externC void
72 cyg_package_start( void )
73 {
74 #ifdef CYGPKG_LIBC
75 cyg_iso_c_start();
76 #else
77 (void)main(0, NULL);
78 #endif
79 } // cyg_package_start()
80
81
82 #if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_RAND)
83
84 static void
85 test( CYG_ADDRWORD data )
86 {
87 static int rand_data1[100];
88 static int rand_data2[100];
89 int count;
90 int fail=0;
91
92 // Test that rand starts with the seed as CYGNUM_LIBC_RAND_SEED
93
94 for ( count=0; count < 100; ++count )
95 {
96 rand_data1[count] = rand();
97 } // for
98
99 // set seed to CYGNUM_LIBC_RAND_SEED
100 srand(CYGNUM_LIBC_RAND_SEED);
101
102 for ( count=0; count < 100; ++count )
103 {
104 rand_data2[count] = rand();
105 } // for
106
107 for ( count=0; count < 100; ++count )
108 {
109 if (rand_data1[count] != rand_data2[count])
110 ++fail;
111 } // for
112
113 CYG_TEST_PASS_FAIL(fail==0, "rand() has seed initialised to "
114 "CYGNUM_LIBC_RAND_SEED");
115
116 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C "
117 "library rand() function");
118 } // test()
119
120 #endif // if defined(CYGPKG_LIBC) && defined(CYGPKG_LIBC_RAND)
121
122
123 int
124 main(int argc, char *argv[])
125 {
126 CYG_TEST_INIT();
127
128 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C "
129 "library rand() function");
130
131 START_TEST( test );
132
133 CYG_TEST_PASS_FINISH("Testing is not applicable to this "
134 "configuration");
135 } // main()
136
137
138 // EOF rand2.c