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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [ecos-2.0/] [packages/] [services/] [memalloc/] [common/] [v2_0/] [tests/] [heaptest.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1254 phoenix
//=================================================================
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 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):     jlarmour
44
// Contributors:  
45
// Date:          2001-07-17
46
// Description:   Tests all memory allocated for use by heaps.
47
//
48
//
49
//####DESCRIPTIONEND####
50
 
51
// INCLUDES
52
 
53
#include <pkgconf/system.h>
54
#include <pkgconf/hal.h>
55
#include <pkgconf/memalloc.h> // config header
56
#ifdef CYGPKG_ISOINFRA
57
# include <pkgconf/isoinfra.h>
58
# include <stdlib.h>
59
#endif
60
#include <cyg/infra/testcase.h>
61
 
62
#if !defined(CYGPKG_ISOINFRA)
63
# define NA_MSG "Requires isoinfra package"
64
#elif !CYGINT_ISO_MALLOC
65
# define NA_MSG "Requires malloc"
66
#elif !CYGINT_ISO_MALLINFO
67
# define NA_MSG "Requires mallinfo"
68
#endif
69
 
70
#ifdef NA_MSG
71
 
72
externC void
73
cyg_start(void)
74
{
75
    CYG_TEST_INIT();
76
    CYG_TEST_NA( NA_MSG );
77
    CYG_TEST_FINISH("Done");
78
}
79
#else
80
 
81
#include <cyg/infra/diag.h>
82
 
83
#define ERRORTHRESHOLD 10
84
#define ITERS (cyg_test_is_simulator ? 1 : 10)
85
#define INTALIGNED(_x_) (!((unsigned long)(_x_) & (sizeof(int)-1)))
86
 
87
int
88
test_pat(unsigned char *buf, int size,
89
         unsigned int pat, cyg_bool addrpat,
90
         const char *testname)
91
{
92
    unsigned char *bufptr=buf;
93
    register unsigned int *ibufptr;
94
    unsigned char *endptr=buf+size;
95
    register unsigned int *endptra; // int aligned
96
    int errors=0;
97
    unsigned char bpat = pat & 0xFF;
98
 
99
    endptra = (int *)((unsigned long)endptr & ~(sizeof(int)-1));
100
 
101
    // Set to the pattern
102
    while (!INTALIGNED(bufptr)) {
103
        if (addrpat)
104
            bpat = ((int)bufptr)&0xFF;
105
        *bufptr++ = bpat;
106
    }
107
 
108
    ibufptr = (unsigned int *)bufptr;
109
 
110
    while ( ibufptr < endptra ) {
111
        if (addrpat)
112
            pat = (unsigned int)ibufptr;
113
        *ibufptr++ = pat;
114
    }
115
 
116
    bufptr = (unsigned char *)ibufptr;
117
    while ( bufptr < endptr ) {
118
        if (addrpat)
119
            bpat = ((int)bufptr)&0xFF;
120
        *bufptr++ = bpat;
121
    }
122
 
123
    // Now compare to the pattern
124
    bufptr = buf;
125
    while ( !INTALIGNED(bufptr) ) {
126
        if (addrpat)
127
            bpat = ((int)bufptr)&0xFF;
128
        if ( *bufptr != bpat ) {
129
            diag_printf( "FAIL:<Memory at 0x%08x: expected 0x%02x, read 0x%02x>\n",
130
                         bufptr, (int)bpat, (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
                         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
                         bufptr, (int)bpat, (int)*bufptr );
158
            if ( errors++ == ERRORTHRESHOLD )
159
                CYG_TEST_FAIL_FINISH( testname );
160
        }
161
        bufptr++;
162
    }
163
    if (errors)
164
        CYG_TEST_FAIL( testname );
165
    else
166
        CYG_TEST_PASS( testname );
167
    return errors;
168
} // test_pat()
169
 
170
externC void
171
cyg_start(void)
172
{
173
    unsigned int allonesint=0, checkerboardint1=0, checkerboardint2=0;
174
    int i;
175
    int errors=0;
176
 
177
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
178
    cyg_hal_invoke_constructors();
179
#endif
180
    CYG_TEST_INIT();
181
    CYG_TEST_INFO("Starting heaptest - testing all memory usable as heap");
182
    CYG_TEST_INFO("Any failures reported may indicate failing RAM hardware,");
183
    CYG_TEST_INFO("or an invalid memory map");
184
 
185
    for (i=0; i<sizeof(int); i++) {
186
        allonesint = allonesint << 8;
187
        allonesint |= 0xFF;
188
        checkerboardint1 = checkerboardint1 << 8;
189
        checkerboardint1 |= 0xAA;
190
        checkerboardint2 = checkerboardint2 << 8;
191
        checkerboardint2 |= 0x55;
192
    }
193
 
194
    for (;;) {
195
        struct mallinfo info;
196
        char *buf;
197
 
198
        info = mallinfo();
199
 
200
        if ( info.maxfree <= 0 )
201
            break;
202
 
203
        buf = malloc(info.maxfree);
204
        if (!buf) {
205
            diag_printf("Couldn't malloc %d bytes claimed as available",
206
                        info.maxfree);
207
            CYG_TEST_FAIL_FINISH("heaptest");
208
        }
209
 
210
        diag_printf( "INFO:<Testing memory at 0x%08x of size %d for %d iterations>\n",
211
                     buf, info.maxfree, ITERS );
212
        for (i=0; i<ITERS; i++) {
213
            errors += test_pat( buf, info.maxfree, 0, 0, "all zeroes" );
214
            errors += test_pat( buf, info.maxfree, allonesint, 0,
215
                                "all ones" );
216
            errors += test_pat( buf, info.maxfree, checkerboardint1, 0,
217
                                "checkerboard 1" );
218
            errors += test_pat( buf, info.maxfree, checkerboardint2, 0,
219
                                "checkerboard 2" );
220
            errors += test_pat( buf, info.maxfree, 0, 1,
221
                                "memory addr" );
222
        }
223
 
224
        // deliberately don't free so we get the next space
225
    }
226
 
227
    if (errors)
228
        CYG_TEST_FAIL_FINISH( "heaptest errors found" );
229
    else
230
        CYG_TEST_PASS_FINISH( "heaptest OK" );
231
} // cyg_start()
232
 
233
#endif // !NA_MSG
234
 
235
// EOF heaptest.cxx

powered by: WebSVN 2.1.0

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