Changeset 96348adc in mainline for kernel/test/mm
- Timestamp:
- 2006-12-12T17:24:58Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7e13972
- Parents:
- 34db7fa
- Location:
- kernel/test/mm
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/mm/falloc1.c
r34db7fa r96348adc 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 #include <print.h> 29 30 #include <test.h> … … 36 37 #include <align.h> 37 38 38 #ifdef CONFIG_BENCH39 #include <arch/cycle.h>40 #endif41 42 39 #define MAX_FRAMES 1024 43 40 #define MAX_ORDER 8 44 41 #define TEST_RUNS 2 45 42 46 void test_falloc1(void) { 47 #ifdef CONFIG_BENCH 48 uint64_t t0 = get_cycle(); 49 #endif 50 uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES*sizeof(uintptr_t), 0); 51 int results[MAX_ORDER+1]; 43 char * test_falloc1(void) { 44 uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), 0); 45 int results[MAX_ORDER + 1]; 52 46 53 47 int i, order, run; … … 55 49 56 50 ASSERT(TEST_RUNS > 1); 57 ASSERT(frames != NULL) 51 if (frames == NULL) 52 return "Unable to allocate frames"; 58 53 59 54 for (run = 0; run < TEST_RUNS; run++) { … … 65 60 66 61 if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) != frames[allocated]) { 67 panic("Test failed. Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10); 62 printf("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10); 63 return "Test failed"; 68 64 } 69 65 70 if (frames[allocated]) {66 if (frames[allocated]) 71 67 allocated++; 72 }else {68 else { 73 69 printf("done. "); 74 70 break; 75 71 } 76 72 } 77 73 78 74 printf("%d blocks allocated.\n", allocated); 79 75 80 76 if (run) { 81 if (results[order] != allocated) { 82 panic("Test failed. Frame leak possible.\n"); 83 } 77 if (results[order] != allocated) 78 return "Possible frame leak"; 84 79 } else 85 80 results[order] = allocated; 86 81 87 82 printf("Deallocating ... "); 88 for (i = 0; i < allocated; i++) {83 for (i = 0; i < allocated; i++) 89 84 frame_free(KA2PA(frames[i])); 90 }91 85 printf("done.\n"); 92 86 } … … 95 89 free(frames); 96 90 97 printf("Test passed.\n"); 98 #ifdef CONFIG_BENCH 99 uint64_t dt = get_cycle() - t0; 100 printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt); 101 #endif 91 return NULL; 102 92 } 103 -
kernel/test/mm/falloc1.def
r34db7fa r96348adc 1 { 2 "falloc1", 3 "Frame allocator test 1", 4 &test_falloc1, 5 true 6 }, -
kernel/test/mm/falloc2.c
r34db7fa r96348adc 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 #include <print.h> 29 30 #include <test.h> … … 39 40 #include <arch.h> 40 41 41 #ifdef CONFIG_BENCH42 #include <arch/cycle.h>43 #endif44 45 42 #define MAX_FRAMES 256 46 43 #define MAX_ORDER 8 … … 49 46 #define THREADS 8 50 47 51 static void falloc(void * arg);52 static void failed(void);48 static atomic_t thread_count; 49 static atomic_t thread_fail; 53 50 54 static atomic_t thread_count; 55 56 void falloc(void * arg) 51 static void falloc(void * arg) 57 52 { 58 53 int order, run, allocated, i; … … 61 56 62 57 uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), FRAME_ATOMIC); 63 ASSERT(frames != NULL); 58 if (frames == NULL) { 59 printf("Thread #%d (cpu%d): Unable to allocate frames\n", THREAD->tid, CPU->id); 60 atomic_inc(&thread_fail); 61 atomic_dec(&thread_count); 62 return; 63 } 64 64 65 65 thread_detach(THREAD); … … 74 74 memsetb(frames[allocated], FRAME_SIZE << order, val); 75 75 allocated++; 76 } else {76 } else 77 77 break; 78 }79 78 } 80 79 printf("Thread #%d (cpu%d): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated); … … 85 84 if (((uint8_t *) frames[i])[k] != val) { 86 85 printf("Thread #%d (cpu%d): Unexpected data (%d) in block %p offset %#zx\n", THREAD->tid, CPU->id, ((char *) frames[i])[k], frames[i], k); 87 failed(); 86 atomic_inc(&thread_fail); 87 goto cleanup; 88 88 } 89 89 } … … 93 93 } 94 94 } 95 95 96 cleanup: 96 97 free(frames); 97 98 printf("Thread #%d (cpu%d): Exiting\n", THREAD->tid, CPU->id); … … 99 100 } 100 101 101 102 void failed(void) 102 char * test_falloc2(void) 103 103 { 104 panic("Test failed.\n"); 105 } 106 107 108 void test_falloc2(void) 109 { 110 #ifdef CONFIG_BENCH 111 uint64_t t0 = get_cycle(); 112 #endif 113 int i; 104 unsigned int i; 114 105 115 106 atomic_set(&thread_count, THREADS); 107 atomic_set(&thread_fail, 0); 116 108 117 109 for (i = 0; i < THREADS; i++) { 118 thread_t * thrd ;119 thrd = thread_create(falloc, NULL, TASK, 0, "falloc");120 if (thrd)121 thread_ready(thrd);122 else123 failed();110 thread_t * thrd = thread_create(falloc, NULL, TASK, 0, "falloc"); 111 if (!thrd) { 112 printf("Could not create thread %d\n", i); 113 break; 114 } 115 thread_ready(thrd); 124 116 } 125 117 126 while (thread_count.count) 127 ; 128 129 printf("Test passed.\n"); 130 #ifdef CONFIG_BENCH 131 uint64_t dt = get_cycle() - t0; 132 printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt); 133 #endif 118 while (atomic_get(&thread_count) > 0) { 119 printf("Threads left: %d\n", atomic_get(&thread_count)); 120 thread_sleep(1); 121 } 122 123 if (atomic_get(&thread_fail) == 0) 124 return NULL; 125 126 return "Test failed"; 134 127 } -
kernel/test/mm/falloc2.def
r34db7fa r96348adc 1 { 2 "falloc2", 3 "Frame allocator test 2", 4 &test_falloc2, 5 true 6 }, -
kernel/test/mm/mapping1.c
r34db7fa r96348adc 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 #include <print.h> 29 30 #include <test.h> … … 35 36 #include <debug.h> 36 37 37 #ifdef CONFIG_BENCH38 #include <arch/cycle.h>39 #endif40 41 38 #define PAGE0 0x10000000 42 39 #define PAGE1 (PAGE0+PAGE_SIZE) … … 45 42 #define VALUE1 0x89abcdef 46 43 47 voidtest_mapping1(void)44 char * test_mapping1(void) 48 45 { 49 #ifdef CONFIG_BENCH50 uint64_t t0 = get_cycle();51 #endif52 46 uintptr_t frame0, frame1; 53 47 uint32_t v0, v1; 54 55 printf("Memory management test mapping #1\n");56 48 57 49 frame0 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA); … … 88 80 ASSERT(v1 == 0); 89 81 90 printf("Test passed.\n"); 91 #ifdef CONFIG_BENCH 92 uint64_t dt = get_cycle() - t0; 93 printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt); 94 #endif 82 return NULL; 95 83 } -
kernel/test/mm/mapping1.def
r34db7fa r96348adc 1 { 2 "mapping1", 3 "Mapping test", 4 &test_mapping1, 5 false 6 }, -
kernel/test/mm/purge1.c
r34db7fa r96348adc 27 27 */ 28 28 29 #ifdef ia64 30 29 31 #include <print.h> 30 32 #include <test.h> … … 37 39 #include <debug.h> 38 40 39 #ifdef ia6440 41 41 extern void tlb_invalidate_all(void); 42 42 extern void tlb_invalidate_pages(asid_t asid, uintptr_t va, count_t cnt); 43 43 44 voidtest(void)44 char * test(void) 45 45 { 46 46 tlb_entry_t entryi; 47 47 tlb_entry_t entryd; 48 48 49 49 int i; 50 50 … … 81 81 82 82 /*tlb_invalidate_all();*/ 83 } 84 85 #else 86 87 void test_purge1(void) 88 { 89 printf("This test is availaible only on IA64 platform.\n"); 83 84 return NULL; 90 85 } 91 86 -
kernel/test/mm/purge1.def
r34db7fa r96348adc 1 #ifdef ia64 2 { 3 "purge1", 4 "Itanium TLB purge test", 5 &test_purge1, 6 true 7 }, 8 #endif -
kernel/test/mm/slab1.c
r34db7fa r96348adc 35 35 #include <memstr.h> 36 36 37 #ifdef CONFIG_BENCH38 #include <arch/cycle.h>39 #endif40 41 37 #define VAL_COUNT 1024 42 38 … … 52 48 SLAB_CACHE_NOMAGAZINE); 53 49 printf("Allocating %d items...", count); 54 for (i =0; i < count; i++) {50 for (i = 0; i < count; i++) { 55 51 data[i] = slab_alloc(cache, 0); 56 memsetb((uintptr_t) data[i], size, 0);52 memsetb((uintptr_t) data[i], size, 0); 57 53 } 58 54 printf("done.\n"); 59 55 printf("Freeing %d items...", count); 60 for (i =0; i < count; i++) {56 for (i = 0; i < count; i++) { 61 57 slab_free(cache, data[i]); 62 58 } … … 64 60 65 61 printf("Allocating %d items...", count); 66 for (i =0; i < count; i++) {62 for (i = 0; i < count; i++) { 67 63 data[i] = slab_alloc(cache, 0); 68 memsetb((uintptr_t) data[i], size, 0);64 memsetb((uintptr_t) data[i], size, 0); 69 65 } 70 66 printf("done.\n"); 71 67 72 printf("Freeing %d items...", count /2);73 for (i =count-1; i >= count/2; i--) {68 printf("Freeing %d items...", count / 2); 69 for (i = count - 1; i >= count / 2; i--) { 74 70 slab_free(cache, data[i]); 75 71 } 76 72 printf("done.\n"); 77 73 78 printf("Allocating %d items...", count /2);79 for (i =count/2; i < count; i++) {74 printf("Allocating %d items...", count / 2); 75 for (i = count / 2; i < count; i++) { 80 76 data[i] = slab_alloc(cache, 0); 81 memsetb((uintptr_t) data[i], size, 0);77 memsetb((uintptr_t) data[i], size, 0); 82 78 } 83 79 printf("done.\n"); 84 80 printf("Freeing %d items...", count); 85 for (i =0; i < count; i++) {81 for (i = 0; i < count; i++) { 86 82 slab_free(cache, data[i]); 87 83 } … … 104 100 } 105 101 106 107 102 #define THREADS 6 108 103 #define THR_MEM_COUNT 1024 109 104 #define THR_MEM_SIZE 128 110 105 111 void * thr_data[THREADS][THR_MEM_COUNT];112 s lab_cache_t *thr_cache;113 s emaphore_t thr_sem;106 static void * thr_data[THREADS][THR_MEM_COUNT]; 107 static slab_cache_t *thr_cache; 108 static semaphore_t thr_sem; 114 109 115 110 static void slabtest(void *data) 116 111 { 117 int offs = (int) (unative_t) data;118 int i, j;112 int offs = (int) (unative_t) data; 113 int i, j; 119 114 120 115 thread_detach(THREAD); 121 116 122 117 printf("Starting thread #%d...\n",THREAD->tid); 123 for (j =0; j<10; j++) {124 for (i =0; i<THR_MEM_COUNT; i++)118 for (j = 0; j < 10; j++) { 119 for (i = 0; i < THR_MEM_COUNT; i++) 125 120 thr_data[offs][i] = slab_alloc(thr_cache,0); 126 for (i =0; i<THR_MEM_COUNT/2; i++)121 for (i = 0; i < THR_MEM_COUNT / 2; i++) 127 122 slab_free(thr_cache, thr_data[offs][i]); 128 for (i =0; i< THR_MEM_COUNT/2; i++)123 for (i = 0; i < THR_MEM_COUNT / 2; i++) 129 124 thr_data[offs][i] = slab_alloc(thr_cache, 0); 130 for (i =0; i<THR_MEM_COUNT;i++)125 for (i = 0; i < THR_MEM_COUNT; i++) 131 126 slab_free(thr_cache, thr_data[offs][i]); 132 127 } … … 143 138 NULL, NULL, 144 139 SLAB_CACHE_NOMAGAZINE); 145 semaphore_initialize(&thr_sem,0); 146 for (i=0; i<THREADS; i++) { 147 if (!(t = thread_create(slabtest, (void *)(unative_t)i, TASK, 0, "slabtest"))) 148 panic("could not create thread\n"); 149 thread_ready(t); 140 semaphore_initialize(&thr_sem, 0); 141 for (i = 0; i < THREADS; i++) { 142 if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest"))) 143 printf("Could not create thread %d\n", i); 144 else 145 thread_ready(t); 150 146 } 151 147 152 for (i =0; i<THREADS; i++)148 for (i = 0; i < THREADS; i++) 153 149 semaphore_down(&thr_sem); 154 150 … … 158 154 } 159 155 160 voidtest_slab1(void)156 char * test_slab1(void) 161 157 { 162 #ifdef CONFIG_BENCH163 uint64_t t0 = get_cycle();164 #endif165 158 testsimple(); 166 159 testthreads(); 167 #ifdef CONFIG_BENCH 168 uint64_t dt = get_cycle() - t0; 169 printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt); 170 #endif 160 161 return NULL; 171 162 } -
kernel/test/mm/slab1.def
r34db7fa r96348adc 1 { 2 "slab1", 3 "SLAB test 1", 4 &test_slab1, 5 true 6 }, -
kernel/test/mm/slab2.c
r34db7fa r96348adc 38 38 #include <synch/mutex.h> 39 39 40 #ifdef CONFIG_BENCH41 #include <arch/cycle.h>42 #endif43 44 40 #define ITEM_SIZE 256 45 41 … … 78 74 olddata1 = data1; 79 75 olddata2 = data2; 80 } while(1);76 } while(1); 81 77 printf("done.\n"); 82 78 /* We do not have memory - now deallocate cache2 */ … … 129 125 static void slabtest(void *priv) 130 126 { 131 void *data =NULL, *new;127 void *data = NULL, *new; 132 128 133 129 thread_detach(THREAD); … … 173 169 } 174 170 175 176 171 printf("Thread #%d finished\n", THREAD->tid); 177 172 slab_print_list(); 178 173 semaphore_up(&thr_sem); 179 174 } 180 181 175 182 176 static void multitest(int size) … … 196 190 0); 197 191 semaphore_initialize(&thr_sem,0); 198 for (i =0; i<THREADS; i++) {192 for (i = 0; i < THREADS; i++) { 199 193 if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest"))) 200 panic("could not create thread\n"); 201 thread_ready(t); 194 printf("Could not create thread %d\n", i); 195 else 196 thread_ready(t); 202 197 } 203 198 thread_sleep(1); 204 199 condvar_broadcast(&thread_starter); 205 200 206 for (i =0; i<THREADS; i++)201 for (i = 0; i < THREADS; i++) 207 202 semaphore_down(&thr_sem); 208 203 … … 211 206 } 212 207 213 void test_slab2(void) 214 { 215 #ifdef CONFIG_BENCH 216 uint64_t t0 = get_cycle(); 217 #endif 218 219 printf("Running reclaim single-thread test .. pass1\n"); 208 char * test_slab2(void) 209 { 210 printf("Running reclaim single-thread test .. pass 1\n"); 220 211 totalmemtest(); 221 printf("Running reclaim single-thread test .. pass 2\n");212 printf("Running reclaim single-thread test .. pass 2\n"); 222 213 totalmemtest(); 223 214 printf("Reclaim test OK.\n"); … … 227 218 multitest(8192); 228 219 printf("All done.\n"); 229 230 #ifdef CONFIG_BENCH 231 uint64_t dt = get_cycle() - t0; 232 printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt); 233 #endif 234 } 220 221 return NULL; 222 } -
kernel/test/mm/slab2.def
r34db7fa r96348adc 1 { 2 "slab2", 3 "SLAB test 2", 4 &test_slab2, 5 true 6 },
Note:
See TracChangeset
for help on using the changeset viewer.