OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [language/] [c/] [libc/] [stdlib/] [v2_0/] [tests/] [rand4.c] - Blame information for rev 249

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//=================================================================
2
//
3
//        rand4.c
4
//
5
//        Testcase for C library rand()
6
//
7
//=================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//=================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):     rosalia
44
// Contributors:  jlarmour
45
// Date:          2000-04-30
46
// Description:   Contains testcode for C library rand() function. This tests
47
//                that random numbers do not have periodicity in the lower
48
//                bit
49
//
50
//
51
//####DESCRIPTIONEND####
52
 
53
// CONFIGURATION
54
 
55
#include <pkgconf/libc_stdlib.h>   // Configuration header
56
 
57
// INCLUDES
58
 
59
#include <stdlib.h>
60
#include <cyg/infra/testcase.h>
61
 
62
// CONSTANTS
63
 
64
#define TEST_LENGTH 100000        // how many samples to take
65
 
66
// DEFINES
67
 
68
#define TEST_VALID (!defined(CYGIMP_LIBC_RAND_SIMPLEST))
69
 
70
// FUNCTIONS
71
 
72
int
73
main(int argc, char *argv[])
74
{
75
#if TEST_VALID
76
    int i;
77
    int r, prev, prevprev;
78
    int how_many_periodics = 0;
79
#endif
80
 
81
    CYG_TEST_INIT();
82
 
83
    CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
84
                  "rand() function");
85
 
86
    CYG_TEST_INFO("This test tests the distribution of random numbers and");
87
    CYG_TEST_INFO("may take some time");
88
 
89
#if TEST_VALID
90
    r = rand() % 2;
91
    prev = r;
92
    r = rand() % 2;
93
    for (i = 0; i < TEST_LENGTH; ++i) {
94
      prevprev = prev;
95
      prev = r;
96
      r = rand() % 2;
97
      if (r == prevprev) {
98
        ++how_many_periodics;
99
      }
100
      if (how_many_periodics > (2*TEST_LENGTH)/3) {
101
        break;
102
      }
103
    }
104
 
105
    CYG_TEST_PASS_FAIL( (how_many_periodics <= (2*TEST_LENGTH)/3),
106
                        "periodicity of rand() in lowest bit");
107
 
108
#else
109
 
110
    // TODO: should be an _expected_ fail i.e. XFAIL
111
    CYG_TEST_NA("Chosen rand algorithm is known to fail this test");
112
 
113
#endif
114
 
115
    CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for "
116
                    "C library rand() function");
117
} // main()
118
 
119
 
120
// EOF rand4.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.