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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [services/] [memalloc/] [common/] [current/] [tests/] [sepmeta2.cxx] - Blame information for rev 838

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        sepmeta2.cxx
4
//
5
//        Variable memory pool with separate metadata test 2
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):     dsm, jlarmour
43
// Contributors:  
44
// Date:          2001-06-28
45
// Description:   test allocation and freeing in variable memory pools
46
//####DESCRIPTIONEND####
47
 
48
#include <pkgconf/memalloc.h>
49
#include <pkgconf/system.h>
50
 
51
#ifdef CYGPKG_KERNEL
52
#include <pkgconf/kernel.h>
53
 
54
#include <cyg/kernel/sched.hxx>         // Cyg_Scheduler::start()
55
#include <cyg/kernel/thread.hxx>        // Cyg_Thread
56
#include <cyg/kernel/thread.inl>
57
#include <cyg/kernel/sema.hxx>
58
 
59
#include <cyg/kernel/sched.inl>
60
 
61
#define NTHREADS 1
62
#include "testaux.hxx"
63
 
64
#endif
65
 
66
#include <cyg/memalloc/sepmeta.hxx>
67
 
68
#include <cyg/infra/testcase.h>
69
 
70
static const cyg_int32 memsize = 10240;
71
static const cyg_int32 metadatasize = 2048;
72
 
73
static cyg_uint8 mem[memsize];
74
static cyg_uint8 metadata[metadatasize];
75
 
76
static Cyg_Mempool_Sepmeta mempool(mem, memsize, 8,
77
                                   metadata, metadatasize);
78
 
79
#define NUM_PTRS 16                     // Should be even
80
 
81
static cyg_uint8 *ptr[NUM_PTRS];
82
static cyg_int32 size[NUM_PTRS];
83
 
84
// We make a number of passes over a table of pointers which point to
85
// blocks of allocated memory.  The block is freed and a new block
86
// allocated.  The size and the order of the processing of blocks
87
// is varied.
88
static void entry( CYG_ADDRWORD data )
89
{
90
    cyg_uint32 s = 1;
91
 
92
    // The number of passes that can be successfully performed
93
    // depends on the fragmentation performance of the memory
94
    // allocator.
95
    for(cyg_ucount32 passes = 0; passes < 10; passes++) {
96
 
97
 
98
        // The order which the table is processed varies according to
99
        // stepsize.
100
        cyg_ucount8 stepsize = (passes*2 + 1) % NUM_PTRS; // odd
101
 
102
 
103
        for(cyg_ucount8 c=0, i=0; c < NUM_PTRS; c++) {
104
            i = (i+stepsize) % NUM_PTRS;
105
            if(ptr[i]) {
106
                for(cyg_ucount32 j=size[i];j--;) {
107
                    CYG_TEST_CHECK(ptr[i][j]==i, "Memory corrupted");
108
                }
109
                CYG_TEST_CHECK(mempool.free(ptr[i], size[i]),
110
                               "bad free");
111
            }
112
            s = (s*2 + 17) % 100;  // size always odds therefore non-0
113
            ptr[i] = mempool.try_alloc(s);
114
            size[i] = s;
115
 
116
            CYG_TEST_CHECK(NULL != ptr[i], "Memory pool not big enough");
117
            CYG_TEST_CHECK(mem<=ptr[i] && ptr[i]+s < mem+memsize,
118
                           "Allocated region not within pool");
119
 
120
            // Scribble over memory to check whether region overlaps
121
            // with other regions.  The contents of the memory are
122
            // checked on freeing.  This also tests that the memory
123
            // does not overlap with allocator memory structures.
124
            for(cyg_ucount32 j=size[i];j--;) {
125
                ptr[i][j]=i;
126
            }
127
        }
128
    }
129
 
130
    CYG_TEST_PASS_FINISH("Sepmeta memory pool 2 OK");
131
}
132
 
133
 
134
void sepmeta2_main( void )
135
{
136
    CYG_TEST_INIT();
137
    CYG_TEST_INFO("Starting Seperate metadata memory pool 2 test");
138
 
139
    for(cyg_ucount32 i = 0; i<NUM_PTRS; i++) {
140
        ptr[i]      = NULL;
141
    }
142
 
143
#ifdef CYGPKG_KERNEL
144
    new_thread(entry, 0);
145
    Cyg_Scheduler::start();
146
#else
147
    entry(0);
148
#endif
149
 
150
    CYG_TEST_FAIL_FINISH("Not reached");
151
}
152
 
153
externC void
154
cyg_start( void )
155
{
156
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
157
    cyg_hal_invoke_constructors();
158
#endif
159
    sepmeta2_main();
160
}
161
// EOF sepmeta2.cxx

powered by: WebSVN 2.1.0

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