comparison packages/kernel/current/tests/memfix2.cxx @ 0:3111d98ba7b3 ecos-v1_1-release

Initial commit of eCos version 1.1
author jlarmour
date Tue, 11 May 1999 11:16:07 +0000
parents
children 443894e2e912
comparison
equal deleted inserted replaced
-1:000000000000 0:3111d98ba7b3
1 //==========================================================================
2 //
3 // memfix2.cxx
4 //
5 // Fixed memory pool test 2
6 //
7 //==========================================================================
8 //####COPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 // The contents of this file are subject to the Cygnus eCos Public License
12 // Version 1.0 (the "License"); you may not use this file except in
13 // compliance with the License. You may obtain a copy of the License at
14 // http://sourceware.cygnus.com/ecos
15 //
16 // Software distributed under the License is distributed on an "AS IS"
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
18 // License for the specific language governing rights and limitations under
19 // the License.
20 //
21 // The Original Code is eCos - Embedded Cygnus Operating System, released
22 // September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Cygnus. Portions created
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved.
26 // -------------------------------------------
27 //
28 //####COPYRIGHTEND####
29 //==========================================================================
30 //#####DESCRIPTIONBEGIN####
31 //
32 // Author(s): dsm
33 // Contributors: dsm
34 // Date: 1998-06-08
35 // Description: test allocation and freeing in fixed memory pools
36 //####DESCRIPTIONEND####
37
38 #include <pkgconf/kernel.h>
39
40 #include <cyg/kernel/sched.hxx> // Cyg_Scheduler::start()
41 #include <cyg/kernel/thread.hxx> // Cyg_Thread
42 #include <cyg/kernel/thread.inl>
43 #include <cyg/kernel/sema.hxx>
44
45 #include <cyg/kernel/memfixed.hxx>
46
47 #include <cyg/infra/testcase.h>
48
49 #include <cyg/kernel/sched.inl>
50
51
52 #define NTHREADS 1
53 #include "testaux.hxx"
54
55 static const cyg_int32 memsize = 1024;
56
57 static cyg_uint8 mem[memsize];
58
59 #define NUM_PTRS 16 // Should be even
60 #define BLOCKSIZE 12
61
62 static Cyg_Mempool_Fixed mempool(mem, memsize, BLOCKSIZE);
63
64 static cyg_uint8 *ptr[NUM_PTRS];
65
66 // We make a number of passes over a table of pointers which point to
67 // blocks of allocated memory. The block is freed and a new block
68 // allocated. The order of the processing of blocks is varied.
69 static void entry( CYG_ADDRWORD data )
70 {
71 for(cyg_ucount32 passes = 0; passes < 10; passes++) {
72
73
74 // The order which the table is processed varies according to
75 // stepsize.
76 cyg_ucount8 stepsize = (passes*2 + 1) % NUM_PTRS; // odd
77
78
79 for(cyg_ucount8 c=0, i=0; c < NUM_PTRS; c++) {
80 i = (i+stepsize) % NUM_PTRS;
81 if(ptr[i]) {
82 for(cyg_ucount32 j=BLOCKSIZE;j--;) {
83 CYG_TEST_CHECK(ptr[i][j]==i, "Memory corrupted");
84 }
85 CYG_TEST_CHECK(mempool.free(ptr[i]), "bad free");
86 }
87 ptr[i] = mempool.try_alloc();
88
89 CYG_TEST_CHECK(NULL != ptr[i], "Memory pool not big enough");
90 CYG_TEST_CHECK(mem<=ptr[i] && ptr[i]+BLOCKSIZE < mem+memsize,
91 "Allocated region not within pool");
92
93 // Scribble over memory to check whether region overlaps
94 // with other regions. The contents of the memory are
95 // checked on freeing. This also tests that the memory
96 // does not overlap with allocator memory structures.
97 for(cyg_ucount32 j=BLOCKSIZE;j--;) {
98 ptr[i][j]=i;
99 }
100 }
101 }
102
103 CYG_TEST_PASS_FINISH("Fixed memory pool 2 OK");
104 }
105
106
107 void memfix2_main( void )
108 {
109 CYG_TEST_INIT();
110
111 new_thread(entry, 0);
112
113 for(cyg_ucount32 i = 0; i<NUM_PTRS; i++) {
114 ptr[i] = NULL;
115 }
116
117 Cyg_Scheduler::start();
118
119 CYG_TEST_FAIL_FINISH("Not reached");
120 }
121
122 externC void
123 cyg_start( void )
124 {
125 memfix2_main();
126 }
127 // EOF memfix1.cxx