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