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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [services/] [memalloc/] [common/] [current/] [tests/] [heaptest.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//=================================================================
2
//
3
//        heaptest.cxx
4
//
5
//        Test all the memory used by heaps to check it's all valid
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 Free Software Foundation, 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      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//=================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):     jlarmour
43
// Contributors:  
44
// Date:          2001-07-17
45
// Description:   Tests all memory allocated for use by heaps.
46
//
47
//
48
//####DESCRIPTIONEND####
49
 
50
// INCLUDES
51
 
52
#include <pkgconf/system.h>
53
#include <pkgconf/hal.h>
54
#include <pkgconf/memalloc.h> // config header
55
#ifdef CYGPKG_ISOINFRA
56
# include <pkgconf/isoinfra.h>
57
# include <stdlib.h>
58
#endif
59
#include <cyg/infra/testcase.h>
60
 
61
#if !defined(CYGPKG_ISOINFRA)
62
# define NA_MSG "Requires isoinfra package"
63
#elif !CYGINT_ISO_MALLOC
64
# define NA_MSG "Requires malloc"
65
#elif !CYGINT_ISO_MALLINFO
66
# define NA_MSG "Requires mallinfo"
67
#endif
68
 
69
#ifdef NA_MSG
70
 
71
externC void
72
cyg_start(void)
73
{
74
    CYG_TEST_INIT();
75
    CYG_TEST_NA( NA_MSG );
76
    CYG_TEST_FINISH("Done");
77
}
78
#else
79
 
80
#include <cyg/infra/diag.h>
81
 
82
#define ERRORTHRESHOLD 10
83
#define ITERS (cyg_test_is_simulator ? 1 : 10)
84
#define INTALIGNED(_x_) (!((unsigned long)(_x_) & (sizeof(int)-1)))
85
 
86
int
87
test_pat(unsigned char *buf, int size,
88
         unsigned int pat, cyg_bool addrpat,
89
         const char *testname)
90
{
91
    unsigned char *bufptr=buf;
92
    register unsigned int *ibufptr;
93
    unsigned char *endptr=buf+size;
94
    register unsigned int *endptra; // int aligned
95
    int errors=0;
96
    unsigned char bpat = pat & 0xFF;
97
 
98
    endptra = (unsigned int *)((unsigned long)endptr & ~(sizeof(int)-1));
99
 
100
    // Set to the pattern
101
    while (!INTALIGNED(bufptr)) {
102
        if (addrpat)
103
            bpat = ((int)bufptr)&0xFF;
104
        *bufptr++ = bpat;
105
    }
106
 
107
    ibufptr = (unsigned int *)bufptr;
108
 
109
    while ( ibufptr < endptra ) {
110
        if (addrpat)
111
            pat = (unsigned int)ibufptr;
112
        *ibufptr++ = pat;
113
    }
114
 
115
    bufptr = (unsigned char *)ibufptr;
116
    while ( bufptr < endptr ) {
117
        if (addrpat)
118
            bpat = ((int)bufptr)&0xFF;
119
        *bufptr++ = bpat;
120
    }
121
 
122
    // Now compare to the pattern
123
    bufptr = buf;
124
    while ( !INTALIGNED(bufptr) ) {
125
        if (addrpat)
126
            bpat = ((int)bufptr)&0xFF;
127
        if ( *bufptr != bpat ) {
128
            diag_printf( "FAIL:<Memory at 0x%08x: expected 0x%02x, read 0x%02x>\n",
129
                         (unsigned int)bufptr, (unsigned int)bpat,
130
                         (unsigned int)*bufptr );
131
            if ( errors++ == ERRORTHRESHOLD )
132
                CYG_TEST_FAIL_FINISH( testname );
133
        }
134
        bufptr++;
135
    }
136
 
137
    ibufptr = (unsigned int *)bufptr;
138
 
139
    while ( ibufptr < endptra ) {
140
        if (addrpat)
141
            pat = (unsigned int)ibufptr;
142
        if ( *ibufptr != pat ) {
143
            diag_printf( "FAIL:<Memory at 0x%08x: expected 0x%08x, read 0x%08x>\n",
144
                         (unsigned int) ibufptr, pat, *ibufptr );
145
            if ( errors++ == ERRORTHRESHOLD )
146
                CYG_TEST_FAIL_FINISH( testname );
147
        }
148
        ibufptr++;
149
    }
150
 
151
    bufptr = (unsigned char *)ibufptr;
152
    while ( bufptr < endptr ) {
153
        if (addrpat)
154
            bpat = ((int)bufptr)&0xFF;
155
        if ( *bufptr != bpat ) {
156
            diag_printf( "FAIL:<Memory at 0x%08x: expected 0x%02x, read 0x%02x>\n",
157
                         (unsigned int) bufptr, (unsigned int)bpat,
158
                         (unsigned int)*bufptr );
159
            if ( errors++ == ERRORTHRESHOLD )
160
                CYG_TEST_FAIL_FINISH( testname );
161
        }
162
        bufptr++;
163
    }
164
    if (errors)
165
        CYG_TEST_FAIL( testname );
166
    else
167
        CYG_TEST_PASS( testname );
168
    return errors;
169
} // test_pat()
170
 
171
externC void
172
cyg_start(void)
173
{
174
    unsigned int allonesint=0, checkerboardint1=0, checkerboardint2=0;
175
    int i;
176
    int errors=0;
177
 
178
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
179
    cyg_hal_invoke_constructors();
180
#endif
181
    CYG_TEST_INIT();
182
    CYG_TEST_INFO("Starting heaptest - testing all memory usable as heap");
183
    CYG_TEST_INFO("Any failures reported may indicate failing RAM hardware,");
184
    CYG_TEST_INFO("or an invalid memory map");
185
 
186
    for (i=0; i<sizeof(int); i++) {
187
        allonesint = allonesint << 8;
188
        allonesint |= 0xFF;
189
        checkerboardint1 = checkerboardint1 << 8;
190
        checkerboardint1 |= 0xAA;
191
        checkerboardint2 = checkerboardint2 << 8;
192
        checkerboardint2 |= 0x55;
193
    }
194
 
195
    for (;;) {
196
        struct mallinfo info;
197
        unsigned char *buf;
198
 
199
        info = mallinfo();
200
 
201
        if ( info.maxfree <= 0 )
202
            break;
203
 
204
        buf = malloc(info.maxfree);
205
        if (!buf) {
206
            diag_printf("Couldn't malloc %d bytes claimed as available",
207
                        info.maxfree);
208
            CYG_TEST_FAIL_FINISH("heaptest");
209
        }
210
 
211
        diag_printf( "INFO:<Testing memory at 0x%08x of size %d for %d iterations>\n",
212
                     (unsigned int)buf, info.maxfree, ITERS );
213
        for (i=0; i<ITERS; i++) {
214
            errors += test_pat( buf, info.maxfree, 0, 0, "all zeroes" );
215
            errors += test_pat( buf, info.maxfree, allonesint, 0,
216
                                "all ones" );
217
            errors += test_pat( buf, info.maxfree, checkerboardint1, 0,
218
                                "checkerboard 1" );
219
            errors += test_pat( buf, info.maxfree, checkerboardint2, 0,
220
                                "checkerboard 2" );
221
            errors += test_pat( buf, info.maxfree, 0, 1,
222
                                "memory addr" );
223
        }
224
 
225
        // deliberately don't free so we get the next space
226
    }
227
 
228
    if (errors)
229
        CYG_TEST_FAIL_FINISH( "heaptest errors found" );
230
    else
231
        CYG_TEST_PASS_FINISH( "heaptest OK" );
232
} // cyg_start()
233
 
234
#endif // !NA_MSG
235
 
236
// EOF heaptest.cxx

powered by: WebSVN 2.1.0

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