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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        memvar2.cxx
4
//
5
//        Variable memory pool 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:          2000-06-18
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/memvar.hxx>
67
 
68
#include <cyg/infra/testcase.h>
69
 
70
static const cyg_int32 memsize = 10240;
71
 
72
static cyg_uint8 mem[memsize];
73
 
74
static Cyg_Mempool_Variable mempool(mem, memsize);
75
 
76
#define NUM_PTRS 16                     // Should be even
77
 
78
static cyg_uint8 *ptr[NUM_PTRS];
79
static cyg_int32 size[NUM_PTRS];
80
 
81
// We make a number of passes over a table of pointers which point to
82
// blocks of allocated memory.  The block is freed and a new block
83
// allocated.  The size and the order of the processing of blocks
84
// is varied.
85
static void entry( CYG_ADDRWORD data )
86
{
87
    cyg_uint32 s = 1;
88
 
89
    // The number of passes that can be successfully performed
90
    // depends on the fragmentation performance of the memory
91
    // allocator.
92
    for(cyg_ucount32 passes = 0; passes < 10; passes++) {
93
 
94
 
95
        // The order which the table is processed varies according to
96
        // stepsize.
97
        cyg_ucount8 stepsize = (passes*2 + 1) % NUM_PTRS; // odd
98
 
99
 
100
        for(cyg_ucount8 c=0, i=0; c < NUM_PTRS; c++) {
101
            i = (i+stepsize) % NUM_PTRS;
102
            if(ptr[i]) {
103
                for(cyg_ucount32 j=size[i];j--;) {
104
                    CYG_TEST_CHECK(ptr[i][j]==i, "Memory corrupted");
105
                }
106
                CYG_TEST_CHECK(mempool.free(ptr[i], size[i]),
107
                               "bad free");
108
            }
109
            s = (s*2 + 17) % 100;  // size always odds therefore non-0
110
            ptr[i] = mempool.try_alloc(s);
111
            size[i] = s;
112
 
113
            CYG_TEST_CHECK(NULL != ptr[i], "Memory pool not big enough");
114
            CYG_TEST_CHECK(mem<=ptr[i] && ptr[i]+s < mem+memsize,
115
                           "Allocated region not within pool");
116
 
117
            // Scribble over memory to check whether region overlaps
118
            // with other regions.  The contents of the memory are
119
            // checked on freeing.  This also tests that the memory
120
            // does not overlap with allocator memory structures.
121
            for(cyg_ucount32 j=size[i];j--;) {
122
                ptr[i][j]=i;
123
            }
124
        }
125
    }
126
 
127
    CYG_TEST_PASS_FINISH("Variable memory pool 2 OK");
128
}
129
 
130
 
131
void memvar2_main( void )
132
{
133
    CYG_TEST_INIT();
134
    CYG_TEST_INFO("Starting Variable memory pool 2 test");
135
 
136
    for(cyg_ucount32 i = 0; i<NUM_PTRS; i++) {
137
        ptr[i]      = NULL;
138
    }
139
 
140
#ifdef CYGPKG_KERNEL
141
    new_thread(entry, 0);
142
    Cyg_Scheduler::start();
143
#else
144
    entry(0);
145
#endif
146
 
147
    CYG_TEST_FAIL_FINISH("Not reached");
148
}
149
 
150
externC void
151
cyg_start( void )
152
{
153
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
154
    cyg_hal_invoke_constructors();
155
#endif
156
    memvar2_main();
157
}
158
// EOF memvar2.cxx

powered by: WebSVN 2.1.0

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