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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [services/] [memalloc/] [common/] [current/] [tests/] [sepmeta1.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
//        sepmeta1.cxx
4
//
5
//        Variable memory pool with separate metadata test 1
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:   Tests basic variable memory pool functionality
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
 
57
#include <cyg/kernel/sched.inl>
58
#include <cyg/kernel/thread.inl>
59
 
60
#include <cyg/kernel/timer.hxx>         // Cyg_Timer
61
#include <cyg/kernel/clock.inl>         // Cyg_Clock
62
 
63
#define NTHREADS 2
64
#include "testaux.hxx"
65
 
66
#endif
67
 
68
#include <cyg/memalloc/sepmeta.hxx>
69
 
70
#include <cyg/infra/testcase.h>
71
 
72
static const cyg_int32 memsize = 10240;
73
static const cyg_int32 metadatasize = 2048;
74
 
75
static cyg_uint8 mem[2][memsize];
76
static cyg_uint8 metadata[2][metadatasize];
77
 
78
static Cyg_Mempool_Sepmeta mempool0(mem[0], memsize, 8,
79
                                    metadata[0], metadatasize);
80
 
81
static Cyg_Mempool_Sepmeta mempool1(mem[1], memsize, 8,
82
                                    metadata[1], metadatasize);
83
 
84
 
85
static void check_in_mp0(cyg_uint8 *p, cyg_int32 size)
86
{
87
    CYG_TEST_CHECK(NULL != p,
88
                   "Allocation failed");
89
    CYG_TEST_CHECK(mem[0] <= p && p+size <= mem[1],
90
                   "Block outside memory pool");
91
}
92
 
93
 
94
static void entry0( CYG_ADDRWORD data )
95
{
96
    cyg_int32 f0,f1,f2,t0;
97
    cyg_uint8 *p0, *p1;
98
    cyg_int32 most_of_mem=memsize/4*3;
99
    Cyg_Mempool_Status stat;
100
 
101
    mempool0.get_status( CYG_MEMPOOL_STAT_ORIGBASE|
102
                         CYG_MEMPOOL_STAT_BLOCKSIZE|
103
                         CYG_MEMPOOL_STAT_MAXFREE|
104
                         CYG_MEMPOOL_STAT_ORIGSIZE, stat );
105
 
106
    CYG_TEST_CHECK(mem[0] == stat.origbase, "get_status: base wrong");
107
    CYG_TEST_CHECK(memsize == stat.origsize, "get_status: size wrong");
108
 
109
    CYG_TEST_CHECK(0 < stat.maxfree && stat.maxfree <= stat.origsize,
110
                   "get_status: maxfree wildly wrong");
111
 
112
    CYG_TEST_CHECK(-1 == stat.blocksize, "blocksize wrong" );
113
 
114
    mempool0.get_status( CYG_MEMPOOL_STAT_TOTALFREE|
115
                         CYG_MEMPOOL_STAT_ARENASIZE, stat );
116
    t0 = stat.arenasize;
117
    CYG_TEST_CHECK(t0 > 0, "Negative total memory" );
118
    f0 = stat.totalfree;
119
    CYG_TEST_CHECK(f0 > 0, "Negative free memory" );
120
    CYG_TEST_CHECK(t0 <= memsize, "get_totalsize: Too much memory");
121
    CYG_TEST_CHECK(f0 <= t0 , "More memory free than possible" );
122
 
123
    mempool0.get_status( CYG_MEMPOOL_STAT_WAITING, stat );
124
    CYG_TEST_CHECK( !stat.waiting,
125
                    "Thread waiting for memory; there shouldn't be");
126
 
127
    CYG_TEST_CHECK( NULL == mempool0.try_alloc(memsize+1),
128
                    "Managed to allocate too much memory");
129
 
130
#ifdef CYGSEM_MEMALLOC_ALLOCATOR_SEPMETA_THREADAWARE
131
    p0 = mempool0.alloc(most_of_mem);
132
#else
133
    p0 = mempool0.try_alloc(most_of_mem);
134
#endif
135
    check_in_mp0(p0, most_of_mem);
136
 
137
    mempool0.get_status( CYG_MEMPOOL_STAT_TOTALFREE, stat );
138
    f1 = stat.totalfree;
139
    CYG_TEST_CHECK(f1 > 0, "Negative free memory" );
140
    CYG_TEST_CHECK(f1 < f0, "Free memory didn't decrease after allocation" );
141
 
142
    CYG_TEST_CHECK( NULL == mempool0.try_alloc(most_of_mem),
143
                    "Managed to allocate too much memory");
144
 
145
    CYG_TEST_CHECK(mempool0.free(p0, most_of_mem), "Couldn't free");
146
 
147
    mempool0.get_status( CYG_MEMPOOL_STAT_TOTALFREE, stat );
148
    f2 = stat.totalfree;
149
    CYG_TEST_CHECK(f2 > f1, "Free memory didn't increase after free" );
150
 
151
    // should be able to reallocate now memory is free
152
    p0 = mempool0.try_alloc(most_of_mem);
153
    check_in_mp0(p0, most_of_mem);
154
 
155
    p1 = mempool0.try_alloc(10);
156
    check_in_mp0(p1, 10);
157
 
158
    CYG_TEST_CHECK(p1+10 <= p0 || p1 >= p0+most_of_mem,
159
                   "Ranges of allocated memory overlap");
160
 
161
    CYG_TEST_CHECK(mempool0.free(p0, 0), "Couldn't free");
162
    CYG_TEST_CHECK(mempool0.free(p1, 10), "Couldn't free");
163
 
164
#ifdef CYGSEM_MEMALLOC_ALLOCATOR_SEPMETA_THREADAWARE
165
# ifdef CYGFUN_KERNEL_THREADS_TIMER
166
    // This shouldn't have to wait
167
    p0 = mempool0.alloc(most_of_mem,
168
        Cyg_Clock::real_time_clock->current_value() + 100000);
169
    check_in_mp0(p0, most_of_mem);
170
    p1 = mempool0.alloc(most_of_mem,
171
       Cyg_Clock::real_time_clock->current_value() + 2);
172
    CYG_TEST_CHECK(NULL == p1, "Timed alloc unexpectedly worked");
173
    p1 = mempool0.alloc(10,
174
        Cyg_Clock::real_time_clock->current_value() + 2);
175
    check_in_mp0(p1, 10);
176
 
177
    // Expect thread 1 to have run while processing previous timed
178
    // allocation.  It should therefore tbe waiting.
179
    mempool1.get_status( CYG_MEMPOOL_STAT_WAITING, stat );
180
    CYG_TEST_CHECK(stat.waiting, "There should be a thread waiting");
181
# endif
182
#endif
183
 
184
    CYG_TEST_PASS_FINISH("Sepmeta memory pool 1 OK");
185
}
186
 
187
#ifdef CYGSEM_MEMALLOC_ALLOCATOR_SEPMETA_THREADAWARE
188
static void entry1( CYG_ADDRWORD data )
189
{
190
    mempool1.alloc(memsize+1);
191
    CYG_TEST_FAIL("Oversized alloc returned");
192
}
193
#endif
194
 
195
void sepmeta1_main( void )
196
{
197
    CYG_TEST_INIT();
198
    CYG_TEST_INFO("Starting Seperate metadata pool 1 test");
199
 
200
#ifdef CYGSEM_MEMALLOC_ALLOCATOR_SEPMETA_THREADAWARE
201
    new_thread(entry0, 0);
202
    new_thread(entry1, 1);
203
 
204
    Cyg_Scheduler::start();
205
#elif defined(CYGPKG_KERNEL)
206
    new_thread(entry0, 0);
207
 
208
    Cyg_Scheduler::start();
209
#else
210
    entry0(0);
211
#endif
212
 
213
    CYG_TEST_FAIL_FINISH("Not reached");
214
}
215
 
216
externC void
217
cyg_start( void )
218
{
219
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
220
    cyg_hal_invoke_constructors();
221
#endif
222
    sepmeta1_main();
223
}
224
// EOF sepmeta1.cxx

powered by: WebSVN 2.1.0

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