Changeset deada67 in mainline
- Timestamp:
- 2006-12-19T17:54:50Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 730376d
- Parents:
- 6536a4a9
- Location:
- kernel/test
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/fpu/mips2.c
r6536a4a9 rdeada67 46 46 static atomic_t threads_fault; 47 47 static waitq_t can_start; 48 static bool sh_quiet; 48 49 49 50 static void testit1(void *data) … … 71 72 72 73 if (arg != after_arg) { 73 printf("General reg tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg); 74 if (!sh_quiet) 75 printf("General reg tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg); 74 76 atomic_inc(&threads_fault); 75 77 break; … … 102 104 103 105 if (arg != after_arg) { 104 printf("General reg tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg); 106 if (!sh_quiet) 107 printf("General reg tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg); 105 108 atomic_inc(&threads_fault); 106 109 break; … … 114 117 { 115 118 unsigned int i, total = 0; 119 sh_quiet = quiet; 116 120 117 121 waitq_initialize(&can_start); 118 122 atomic_set(&threads_ok, 0); 119 123 atomic_set(&threads_fault, 0); 120 printf("Creating %d threads... ", 2 * THREADS); 124 125 if (!quiet) 126 printf("Creating %d threads... ", 2 * THREADS); 121 127 122 128 for (i = 0; i < THREADS; i++) { … … 124 130 125 131 if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) { 126 printf("could not create thread %d\n", 2 * i); 132 if (!quiet) 133 printf("could not create thread %d\n", 2 * i); 127 134 break; 128 135 } … … 131 138 132 139 if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) { 133 printf("could not create thread %d\n", 2 * i + 1); 140 if (!quiet) 141 printf("could not create thread %d\n", 2 * i + 1); 134 142 break; 135 143 } … … 137 145 total++; 138 146 } 139 printf("ok\n"); 147 148 if (!quiet) 149 printf("ok\n"); 140 150 141 151 thread_sleep(1); … … 143 153 144 154 while (atomic_get(&threads_ok) != total) { 145 printf("Threads left: %d\n", total - atomic_get(&threads_ok)); 155 if (!quiet) 156 printf("Threads left: %d\n", total - atomic_get(&threads_ok)); 146 157 thread_sleep(1); 147 158 } -
kernel/test/mm/falloc1.c
r6536a4a9 rdeada67 56 56 for (run = 0; run < TEST_RUNS; run++) { 57 57 for (order = 0; order <= MAX_ORDER; order++) { 58 printf("Allocating %d frames blocks ... ", 1 << order); 58 if (!quiet) 59 printf("Allocating %d frames blocks ... ", 1 << order); 60 59 61 allocated = 0; 60 62 for (i = 0; i < MAX_FRAMES >> order; i++) { … … 62 64 63 65 if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) != frames[allocated]) { 64 printf("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10); 66 if (!quiet) 67 printf("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10); 65 68 return "Test failed"; 66 69 } … … 69 72 allocated++; 70 73 else { 71 printf("done. "); 74 if (!quiet) 75 printf("done. "); 72 76 break; 73 77 } 74 78 } 75 79 76 printf("%d blocks allocated.\n", allocated); 80 if (!quiet) 81 printf("%d blocks allocated.\n", allocated); 77 82 78 83 if (run) { … … 82 87 results[order] = allocated; 83 88 84 printf("Deallocating ... "); 89 if (!quiet) 90 printf("Deallocating ... "); 91 85 92 for (i = 0; i < allocated; i++) 86 93 frame_free(KA2PA(frames[i])); 87 printf("done.\n"); 94 95 if (!quiet) 96 printf("done.\n"); 88 97 } 89 98 } -
kernel/test/mm/falloc2.c
r6536a4a9 rdeada67 48 48 static atomic_t thread_count; 49 49 static atomic_t thread_fail; 50 static bool sh_quiet; 50 51 51 52 static void falloc(void * arg) … … 57 58 uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), FRAME_ATOMIC); 58 59 if (frames == NULL) { 59 printf("Thread #%d (cpu%d): Unable to allocate frames\n", THREAD->tid, CPU->id); 60 if (!sh_quiet) 61 printf("Thread #%d (cpu%d): Unable to allocate frames\n", THREAD->tid, CPU->id); 60 62 atomic_inc(&thread_fail); 61 63 atomic_dec(&thread_count); … … 67 69 for (run = 0; run < THREAD_RUNS; run++) { 68 70 for (order = 0; order <= MAX_ORDER; order++) { 69 printf("Thread #%d (cpu%d): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order); 71 if (!sh_quiet) 72 printf("Thread #%d (cpu%d): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order); 73 70 74 allocated = 0; 71 75 for (i = 0; i < (MAX_FRAMES >> order); i++) { … … 77 81 break; 78 82 } 79 printf("Thread #%d (cpu%d): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated); 80 81 printf("Thread #%d (cpu%d): Deallocating ... \n", THREAD->tid, CPU->id); 83 84 if (!sh_quiet) 85 printf("Thread #%d (cpu%d): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated); 86 87 if (!sh_quiet) 88 printf("Thread #%d (cpu%d): Deallocating ... \n", THREAD->tid, CPU->id); 89 82 90 for (i = 0; i < allocated; i++) { 83 91 for (k = 0; k <= ((FRAME_SIZE << order) - 1); k++) { 84 92 if (((uint8_t *) frames[i])[k] != val) { 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); 93 if (!sh_quiet) 94 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); 86 95 atomic_inc(&thread_fail); 87 96 goto cleanup; … … 90 99 frame_free(KA2PA(frames[i])); 91 100 } 92 printf("Thread #%d (cpu%d): Finished run.\n", THREAD->tid, CPU->id); 101 102 if (!sh_quiet) 103 printf("Thread #%d (cpu%d): Finished run.\n", THREAD->tid, CPU->id); 93 104 } 94 105 } … … 96 107 cleanup: 97 108 free(frames); 98 printf("Thread #%d (cpu%d): Exiting\n", THREAD->tid, CPU->id); 109 110 if (!sh_quiet) 111 printf("Thread #%d (cpu%d): Exiting\n", THREAD->tid, CPU->id); 99 112 atomic_dec(&thread_count); 100 113 } … … 103 116 { 104 117 unsigned int i; 118 sh_quiet = quiet; 105 119 106 120 atomic_set(&thread_count, THREADS); … … 110 124 thread_t * thrd = thread_create(falloc, NULL, TASK, 0, "falloc", false); 111 125 if (!thrd) { 112 printf("Could not create thread %d\n", i); 126 if (!quiet) 127 printf("Could not create thread %d\n", i); 113 128 break; 114 129 } … … 117 132 118 133 while (atomic_get(&thread_count) > 0) { 119 printf("Threads left: %d\n", atomic_get(&thread_count)); 134 if (!quiet) 135 printf("Threads left: %d\n", atomic_get(&thread_count)); 120 136 thread_sleep(1); 121 137 } -
kernel/test/mm/mapping1.c
r6536a4a9 rdeada67 49 49 frame0 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA); 50 50 frame1 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA); 51 52 printf("Writing %#x to physical address %p.\n", VALUE0, KA2PA(frame0)); 51 52 if (!quiet) 53 printf("Writing %#x to physical address %p.\n", VALUE0, KA2PA(frame0)); 53 54 *((uint32_t *) frame0) = VALUE0; 54 printf("Writing %#x to physical address %p.\n", VALUE1, KA2PA(frame1)); 55 if (!quiet) 56 printf("Writing %#x to physical address %p.\n", VALUE1, KA2PA(frame1)); 55 57 *((uint32_t *) frame1) = VALUE1; 56 58 57 printf("Mapping virtual address %p to physical address %p.\n", PAGE0, KA2PA(frame0)); 59 if (!quiet) 60 printf("Mapping virtual address %p to physical address %p.\n", PAGE0, KA2PA(frame0)); 58 61 page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE); 59 printf("Mapping virtual address %p to physical address %p.\n", PAGE1, KA2PA(frame1)); 62 if (!quiet) 63 printf("Mapping virtual address %p to physical address %p.\n", PAGE1, KA2PA(frame1)); 60 64 page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE); 61 65 62 printf("Value at virtual address %p is %#x.\n", PAGE0, v0 = *((uint32_t *) PAGE0)); 63 printf("Value at virtual address %p is %#x.\n", PAGE1, v1 = *((uint32_t *) PAGE1)); 66 v0 = *((uint32_t *) PAGE0); 67 v1 = *((uint32_t *) PAGE1); 68 if (!quiet) { 69 printf("Value at virtual address %p is %#x.\n", PAGE0, v0); 70 printf("Value at virtual address %p is %#x.\n", PAGE1, v1); 71 } 64 72 65 73 if (v0 != VALUE0) … … 67 75 if (v1 != VALUE1) 68 76 return "Value at v1 not equal to VALUE1"; 69 70 printf("Writing %#x to virtual address %p.\n", 0, PAGE0); 77 78 if (!quiet) 79 printf("Writing %#x to virtual address %p.\n", 0, PAGE0); 71 80 *((uint32_t *) PAGE0) = 0; 72 printf("Writing %#x to virtual address %p.\n", 0, PAGE1); 81 if (!quiet) 82 printf("Writing %#x to virtual address %p.\n", 0, PAGE1); 73 83 *((uint32_t *) PAGE1) = 0; 74 84 … … 76 86 v1 = *((uint32_t *) PAGE1); 77 87 78 printf("Value at virtual address %p is %#x.\n", PAGE0, *((uint32_t *) PAGE0)); 79 printf("Value at virtual address %p is %#x.\n", PAGE1, *((uint32_t *) PAGE1)); 88 if (!quiet) { 89 printf("Value at virtual address %p is %#x.\n", PAGE0, *((uint32_t *) PAGE0)); 90 printf("Value at virtual address %p is %#x.\n", PAGE1, *((uint32_t *) PAGE1)); 91 } 80 92 81 93 if (v0 != 0) -
kernel/test/mm/slab1.c
r6536a4a9 rdeada67 38 38 static void * data[VAL_COUNT]; 39 39 40 static void testit(int size, int count )40 static void testit(int size, int count, bool quiet) 41 41 { 42 42 slab_cache_t *cache; 43 43 int i; 44 44 45 printf("Creating cache, object size: %d.\n", size); 46 cache = slab_cache_create("test_cache", size, 0, NULL, NULL, 47 SLAB_CACHE_NOMAGAZINE); 48 printf("Allocating %d items...", count); 45 if (!quiet) 46 printf("Creating cache, object size: %d.\n", size); 47 48 cache = slab_cache_create("test_cache", size, 0, NULL, NULL, 49 SLAB_CACHE_NOMAGAZINE); 50 51 if (!quiet) 52 printf("Allocating %d items...", count); 53 49 54 for (i = 0; i < count; i++) { 50 55 data[i] = slab_alloc(cache, 0); 51 56 memsetb((uintptr_t) data[i], size, 0); 52 57 } 53 printf("done.\n"); 54 printf("Freeing %d items...", count); 55 for (i = 0; i < count; i++) { 58 59 if (!quiet) { 60 printf("done.\n"); 61 printf("Freeing %d items...", count); 62 } 63 64 for (i = 0; i < count; i++) 56 65 slab_free(cache, data[i]); 66 67 if (!quiet) { 68 printf("done.\n"); 69 printf("Allocating %d items...", count); 57 70 } 58 printf("done.\n"); 59 60 printf("Allocating %d items...", count); 71 61 72 for (i = 0; i < count; i++) { 62 73 data[i] = slab_alloc(cache, 0); 63 74 memsetb((uintptr_t) data[i], size, 0); 64 75 } 65 printf("done.\n"); 66 67 printf("Freeing %d items...", count / 2); 68 for (i = count - 1; i >= count / 2; i--) { 76 77 if (!quiet) { 78 printf("done.\n"); 79 printf("Freeing %d items...", count / 2); 80 } 81 82 for (i = count - 1; i >= count / 2; i--) 69 83 slab_free(cache, data[i]); 84 85 if (!quiet) { 86 printf("done.\n"); 87 printf("Allocating %d items...", count / 2); 70 88 } 71 printf("done.\n"); 72 73 printf("Allocating %d items...", count / 2); 89 74 90 for (i = count / 2; i < count; i++) { 75 91 data[i] = slab_alloc(cache, 0); 76 92 memsetb((uintptr_t) data[i], size, 0); 77 93 } 78 printf("done.\n"); 79 printf("Freeing %d items...", count); 80 for (i = 0; i < count; i++) { 94 95 if (!quiet) { 96 printf("done.\n"); 97 printf("Freeing %d items...", count); 98 } 99 100 for (i = 0; i < count; i++) 81 101 slab_free(cache, data[i]); 82 } 83 printf("done.\n"); 102 103 if (!quiet) 104 printf("done.\n"); 84 105 slab_cache_destroy(cache); 85 86 printf("Test complete.\n"); 106 107 if (!quiet) 108 printf("Test complete.\n"); 87 109 } 88 110 89 static void testsimple( void)111 static void testsimple(bool quiet) 90 112 { 91 testit(100, VAL_COUNT );92 testit(200, VAL_COUNT );93 testit(1024, VAL_COUNT );94 testit(2048, 512 );95 testit(4000, 128 );96 testit(8192, 128 );97 testit(16384, 128 );98 testit(16385, 128 );113 testit(100, VAL_COUNT, quiet); 114 testit(200, VAL_COUNT, quiet); 115 testit(1024, VAL_COUNT, quiet); 116 testit(2048, 512, quiet); 117 testit(4000, 128, quiet); 118 testit(8192, 128, quiet); 119 testit(16384, 128, quiet); 120 testit(16385, 128, quiet); 99 121 } 100 122 … … 106 128 static slab_cache_t *thr_cache; 107 129 static semaphore_t thr_sem; 130 static bool sh_quiet; 108 131 109 132 static void slabtest(void *data) … … 114 137 thread_detach(THREAD); 115 138 116 printf("Starting thread #%d...\n",THREAD->tid); 139 if (!sh_quiet) 140 printf("Starting thread #%d...\n", THREAD->tid); 141 117 142 for (j = 0; j < 10; j++) { 118 143 for (i = 0; i < THR_MEM_COUNT; i++) … … 125 150 slab_free(thr_cache, thr_data[offs][i]); 126 151 } 127 printf("Thread #%d finished\n", THREAD->tid); 152 153 if (!sh_quiet) 154 printf("Thread #%d finished\n", THREAD->tid); 155 128 156 semaphore_up(&thr_sem); 129 157 } 130 158 131 static void testthreads( void)159 static void testthreads(bool quiet) 132 160 { 133 161 thread_t *t; 134 162 int i; 135 163 136 thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, 137 NULL, NULL, 138 SLAB_CACHE_NOMAGAZINE); 164 thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, NULL, NULL, 165 SLAB_CACHE_NOMAGAZINE); 139 166 semaphore_initialize(&thr_sem, 0); 140 167 for (i = 0; i < THREADS; i++) { 141 if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest", false))) 142 printf("Could not create thread %d\n", i); 143 else 168 if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest", false))) { 169 if (!quiet) 170 printf("Could not create thread %d\n", i); 171 } else 144 172 thread_ready(t); 145 173 } … … 149 177 150 178 slab_cache_destroy(thr_cache); 151 printf("Test complete.\n");152 179 180 if (!quiet) 181 printf("Test complete.\n"); 153 182 } 154 183 155 184 char * test_slab1(bool quiet) 156 185 { 157 testsimple(); 158 testthreads(); 186 sh_quiet = quiet; 187 188 testsimple(quiet); 189 testthreads(quiet); 159 190 160 191 return NULL; -
kernel/test/mm/slab2.c
r6536a4a9 rdeada67 43 43 * now allocation should clean magazines and allow for full allocation. 44 44 */ 45 static void totalmemtest( void)45 static void totalmemtest(bool quiet) 46 46 { 47 47 slab_cache_t *cache1; … … 50 50 51 51 void *data1, *data2; 52 void *olddata1 =NULL, *olddata2=NULL;52 void *olddata1 = NULL, *olddata2 = NULL; 53 53 54 54 cache1 = slab_cache_create("cache1_tst", ITEM_SIZE, 0, NULL, NULL, 0); 55 55 cache2 = slab_cache_create("cache2_tst", ITEM_SIZE, 0, NULL, NULL, 0); 56 57 printf("Allocating..."); 56 57 if (!quiet) 58 printf("Allocating..."); 59 58 60 /* Use atomic alloc, so that we find end of memory */ 59 61 do { 60 62 data1 = slab_alloc(cache1, FRAME_ATOMIC); 61 63 data2 = slab_alloc(cache2, FRAME_ATOMIC); 62 if ( !data1 || !data2) {64 if ((!data1) || (!data2)) { 63 65 if (data1) 64 slab_free(cache1, data1);66 slab_free(cache1, data1); 65 67 if (data2) 66 slab_free(cache2, data2);68 slab_free(cache2, data2); 67 69 break; 68 70 } 69 memsetb((uintptr_t) data1, ITEM_SIZE, 0);70 memsetb((uintptr_t) data2, ITEM_SIZE, 0);71 *((void **) data1) = olddata1;72 *((void **) data2) = olddata2;71 memsetb((uintptr_t) data1, ITEM_SIZE, 0); 72 memsetb((uintptr_t) data2, ITEM_SIZE, 0); 73 *((void **) data1) = olddata1; 74 *((void **) data2) = olddata2; 73 75 olddata1 = data1; 74 76 olddata2 = data2; 75 } while(1); 76 printf("done.\n"); 77 } while (1); 78 79 if (!quiet) { 80 printf("done.\n"); 81 printf("Deallocating cache2..."); 82 } 83 77 84 /* We do not have memory - now deallocate cache2 */ 78 printf("Deallocating cache2...");79 85 while (olddata2) { 80 data2 = *((void **) olddata2);86 data2 = *((void **) olddata2); 81 87 slab_free(cache2, olddata2); 82 88 olddata2 = data2; 83 89 } 84 printf("done.\n"); 85 86 printf("Allocating to cache1...\n"); 87 for (i=0; i<30; i++) { 90 91 if (!quiet) { 92 printf("done.\n"); 93 printf("Allocating to cache1...\n"); 94 } 95 96 for (i = 0; i < 30; i++) { 88 97 data1 = slab_alloc(cache1, FRAME_ATOMIC); 89 98 if (!data1) { 90 printf("Incorrect memory size - use another test."); 99 if (!quiet) 100 printf("Incorrect memory size - use another test."); 91 101 return; 92 102 } 93 memsetb((uintptr_t) data1, ITEM_SIZE, 0);94 *((void **) data1) = olddata1;103 memsetb((uintptr_t) data1, ITEM_SIZE, 0); 104 *((void **) data1) = olddata1; 95 105 olddata1 = data1; 96 106 } 97 107 while (1) { 98 108 data1 = slab_alloc(cache1, FRAME_ATOMIC); 99 if (!data1) { 100 break; 101 } 102 memsetb((uintptr_t)data1, ITEM_SIZE, 0); 103 *((void **)data1) = olddata1; 104 olddata1 = data1; 105 } 106 printf("Deallocating cache1..."); 109 if (!data1) 110 break; 111 memsetb((uintptr_t) data1, ITEM_SIZE, 0); 112 *((void **) data1) = olddata1; 113 olddata1 = data1; 114 } 115 116 if (!quiet) 117 printf("Deallocating cache1..."); 118 107 119 while (olddata1) { 108 data1 = *((void **) olddata1);120 data1 = *((void **) olddata1); 109 121 slab_free(cache1, olddata1); 110 122 olddata1 = data1; 111 123 } 112 printf("done.\n"); 113 slab_print_list(); 124 125 if (!quiet) { 126 printf("done.\n"); 127 slab_print_list(); 128 } 129 114 130 slab_cache_destroy(cache1); 115 131 slab_cache_destroy(cache2); … … 120 136 static condvar_t thread_starter; 121 137 static mutex_t starter_mutex; 138 static bool sh_quiet; 122 139 123 140 #define THREADS 8 … … 126 143 { 127 144 void *data = NULL, *new; 128 145 129 146 thread_detach(THREAD); 130 147 131 148 mutex_lock(&starter_mutex); 132 149 condvar_wait(&thread_starter,&starter_mutex); 133 150 mutex_unlock(&starter_mutex); 134 135 printf("Starting thread #%d...\n",THREAD->tid); 151 152 if (!sh_quiet) 153 printf("Starting thread #%d...\n",THREAD->tid); 136 154 137 155 /* Alloc all */ 138 printf("Thread #%d allocating...\n", THREAD->tid); 156 if (!sh_quiet) 157 printf("Thread #%d allocating...\n", THREAD->tid); 158 139 159 while (1) { 140 160 /* Call with atomic to detect end of memory */ … … 142 162 if (!new) 143 163 break; 144 *((void **)new) = data; 145 data = new; 146 } 147 printf("Thread #%d releasing...\n", THREAD->tid); 164 *((void **) new) = data; 165 data = new; 166 } 167 168 if (!sh_quiet) 169 printf("Thread #%d releasing...\n", THREAD->tid); 170 148 171 while (data) { 149 172 new = *((void **)data); 150 *((void **) data) = NULL;173 *((void **) data) = NULL; 151 174 slab_free(thr_cache, data); 152 175 data = new; 153 176 } 154 printf("Thread #%d allocating...\n", THREAD->tid); 177 178 if (!sh_quiet) 179 printf("Thread #%d allocating...\n", THREAD->tid); 180 155 181 while (1) { 156 182 /* Call with atomic to detect end of memory */ … … 158 184 if (!new) 159 185 break; 160 *((void **)new) = data; 161 data = new; 162 } 163 printf("Thread #%d releasing...\n", THREAD->tid); 186 *((void **) new) = data; 187 data = new; 188 } 189 190 if (!sh_quiet) 191 printf("Thread #%d releasing...\n", THREAD->tid); 192 164 193 while (data) { 165 194 new = *((void **)data); 166 *((void **) data) = NULL;195 *((void **) data) = NULL; 167 196 slab_free(thr_cache, data); 168 197 data = new; 169 198 } 170 171 printf("Thread #%d finished\n", THREAD->tid); 199 200 if (!sh_quiet) 201 printf("Thread #%d finished\n", THREAD->tid); 202 172 203 slab_print_list(); 173 204 semaphore_up(&thr_sem); 174 205 } 175 206 176 static void multitest(int size )207 static void multitest(int size, bool quiet) 177 208 { 178 209 /* Start 8 threads that just allocate as much as possible, … … 181 212 thread_t *t; 182 213 int i; 183 184 printf("Running stress test with size %d\n", size); 214 215 if (!quiet) 216 printf("Running stress test with size %d\n", size); 217 185 218 condvar_initialize(&thread_starter); 186 219 mutex_initialize(&starter_mutex); 187 220 188 thr_cache = slab_cache_create("thread_cache", size, 0, 189 NULL, NULL, 190 0); 221 thr_cache = slab_cache_create("thread_cache", size, 0, NULL, NULL, 0); 191 222 semaphore_initialize(&thr_sem,0); 192 223 for (i = 0; i < THREADS; i++) { 193 if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false))) 194 printf("Could not create thread %d\n", i); 195 else 224 if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false))) { 225 if (!quiet) 226 printf("Could not create thread %d\n", i); 227 } else 196 228 thread_ready(t); 197 229 } … … 203 235 204 236 slab_cache_destroy(thr_cache); 205 printf("Stress test complete.\n"); 237 if (!quiet) 238 printf("Stress test complete.\n"); 206 239 } 207 240 208 241 char * test_slab2(bool quiet) 209 242 { 210 printf("Running reclaim single-thread test .. pass 1\n"); 211 totalmemtest(); 212 printf("Running reclaim single-thread test .. pass 2\n"); 213 totalmemtest(); 214 printf("Reclaim test OK.\n"); 215 216 multitest(128); 217 multitest(2048); 218 multitest(8192); 219 printf("All done.\n"); 243 sh_quiet = quiet; 244 245 if (!quiet) 246 printf("Running reclaim single-thread test .. pass 1\n"); 247 totalmemtest(quiet); 248 if (!quiet) 249 printf("Running reclaim single-thread test .. pass 2\n"); 250 totalmemtest(quiet); 251 if (!quiet) 252 printf("Reclaim test OK.\n"); 253 254 multitest(128, quiet); 255 multitest(2048, quiet); 256 multitest(8192, quiet); 220 257 221 258 return NULL; -
kernel/test/print/print1.c
r6536a4a9 rdeada67 33 33 char * test_print1(bool quiet) 34 34 { 35 int retval; 36 unative_t nat = 0x12345678u; 37 38 char buffer[BUFFER_SIZE]; 39 40 printf(" text 10.8s %*.*s \n", 5, 3, "text"); 41 printf(" very long text 10.8s %10.8s \n", "very long text"); 42 printf(" text 8.10s %8.10s \n", "text"); 43 printf(" very long text 8.10s %8.10s \n", "very long text"); 44 45 printf(" char: c '%c', 3.2c '%3.2c', -3.2c '%-3.2c', 2.3c '%2.3c', -2.3c '%-2.3c' \n",'a', 'b', 'c', 'd', 'e' ); 46 printf(" int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",1, 1, 1, 1, 1 ); 47 printf(" -int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",-1, -1, -1, -1, -1 ); 48 printf(" 0xint: x '%#x', 5.3x '%#5.3x', -5.3x '%#-5.3x', 3.5x '%#3.5x', -3.5x '%#-3.5x' \n",17, 17, 17, 17, 17 ); 49 50 printf("'%#llx' 64bit, '%#x' 32bit, '%#hhx' 8bit, '%#hx' 16bit, unative_t '%#zx'. '%#llx' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, nat, 0x1234567887654321ull, "Lovely string" ); 51 52 printf(" Print to NULL '%s'\n", NULL); 53 54 retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters."); 55 printf("Result is: '%s', retval = %d\n", buffer, retval); 56 57 retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters."); 58 printf("Result is: '%s', retval = %d\n", buffer, retval); 59 60 printf("Print short text to %d char long buffer via snprintf.\n", BUFFER_SIZE); 61 retval = snprintf(buffer, BUFFER_SIZE, "Short %s", "text"); 62 printf("Result is: '%s', retval = %d\n", buffer, retval); 63 64 printf("Print long text to %d char long buffer via snprintf.\n", BUFFER_SIZE); 65 retval = snprintf(buffer, BUFFER_SIZE, "Very long %s. This text`s length is more than %d. We are interested in the result.", "text" , BUFFER_SIZE); 66 printf("Result is: '%s', retval = %d\n", buffer, retval); 35 if (!quiet) { 36 int retval; 37 unative_t nat = 0x12345678u; 38 39 char buffer[BUFFER_SIZE]; 40 41 printf(" text 10.8s %*.*s \n", 5, 3, "text"); 42 printf(" very long text 10.8s %10.8s \n", "very long text"); 43 printf(" text 8.10s %8.10s \n", "text"); 44 printf(" very long text 8.10s %8.10s \n", "very long text"); 45 46 printf(" char: c '%c', 3.2c '%3.2c', -3.2c '%-3.2c', 2.3c '%2.3c', -2.3c '%-2.3c' \n",'a', 'b', 'c', 'd', 'e' ); 47 printf(" int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",1, 1, 1, 1, 1 ); 48 printf(" -int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",-1, -1, -1, -1, -1 ); 49 printf(" 0xint: x '%#x', 5.3x '%#5.3x', -5.3x '%#-5.3x', 3.5x '%#3.5x', -3.5x '%#-3.5x' \n",17, 17, 17, 17, 17 ); 50 51 printf("'%#llx' 64bit, '%#x' 32bit, '%#hhx' 8bit, '%#hx' 16bit, unative_t '%#zx'. '%#llx' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, nat, 0x1234567887654321ull, "Lovely string" ); 52 53 printf(" Print to NULL '%s'\n", NULL); 54 55 retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters."); 56 printf("Result is: '%s', retval = %d\n", buffer, retval); 57 58 retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters."); 59 printf("Result is: '%s', retval = %d\n", buffer, retval); 60 61 printf("Print short text to %d char long buffer via snprintf.\n", BUFFER_SIZE); 62 retval = snprintf(buffer, BUFFER_SIZE, "Short %s", "text"); 63 printf("Result is: '%s', retval = %d\n", buffer, retval); 64 65 printf("Print long text to %d char long buffer via snprintf.\n", BUFFER_SIZE); 66 retval = snprintf(buffer, BUFFER_SIZE, "Very long %s. This text`s length is more than %d. We are interested in the result.", "text" , BUFFER_SIZE); 67 printf("Result is: '%s', retval = %d\n", buffer, retval); 68 } 67 69 68 70 return NULL; -
kernel/test/synch/rwlock1.c
r6536a4a9 rdeada67 60 60 rwlock_read_unlock(&rwlock); 61 61 62 63 62 rwlock_write_lock(&rwlock); 64 63 rwlock_write_unlock(&rwlock); -
kernel/test/synch/rwlock2.c
r6536a4a9 rdeada67 39 39 40 40 static rwlock_t rwlock; 41 static bool sh_quiet; 41 42 42 43 static void writer(void *arg) 43 44 { 44 45 thread_detach(THREAD); 46 47 printf("Trying to lock rwlock for writing....\n"); 48 45 if (!sh_quiet) 46 printf("Trying to lock rwlock for writing....\n"); 47 49 48 rwlock_write_lock(&rwlock); 50 49 rwlock_write_unlock(&rwlock); 51 50 52 printf("Trying to lock rwlock for reading....\n"); 51 if (!sh_quiet) 52 printf("Trying to lock rwlock for reading....\n"); 53 53 54 rwlock_read_lock(&rwlock); 54 55 rwlock_read_unlock(&rwlock); 55 printf("Test passed.\n");56 56 } 57 57 … … 59 59 { 60 60 thread_t *thrd; 61 sh_quiet = quiet; 61 62 62 63 rwlock_initialize(&rwlock); … … 80 81 rwlock_read_unlock(&rwlock); 81 82 83 thread_join(thrd); 84 thread_detach(thrd); 85 82 86 return NULL; 83 87 } -
kernel/test/synch/rwlock3.c
r6536a4a9 rdeada67 35 35 #include <synch/rwlock.h> 36 36 37 #define READERS 50 38 #define WRITERS 50 37 #define THREADS 4 39 38 39 static atomic_t thread_count; 40 40 static rwlock_t rwlock; 41 static bool sh_quiet; 41 42 42 43 static void reader(void *arg) 43 44 { 44 45 thread_detach(THREAD); 45 46 printf("cpu%d, tid %d: trying to lock rwlock for reading....\n", CPU->id, THREAD->tid); 46 47 if (!sh_quiet) 48 printf("cpu%d, tid %d: trying to lock rwlock for reading....\n", CPU->id, THREAD->tid); 49 47 50 rwlock_read_lock(&rwlock); 48 rwlock_read_unlock(&rwlock); 49 printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid); 50 51 printf("cpu%d, tid %d: trying to lock rwlock for writing....\n", CPU->id, THREAD->tid); 51 rwlock_read_unlock(&rwlock); 52 53 if (!sh_quiet) { 54 printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid); 55 printf("cpu%d, tid %d: trying to lock rwlock for writing....\n", CPU->id, THREAD->tid); 56 } 52 57 53 58 rwlock_write_lock(&rwlock); 54 59 rwlock_write_unlock(&rwlock); 55 printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid); 60 61 if (!sh_quiet) 62 printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid); 63 64 atomic_dec(&thread_count); 56 65 } 57 66 … … 60 69 int i; 61 70 thread_t *thrd; 71 sh_quiet = quiet; 72 73 atomic_set(&thread_count, THREADS); 62 74 63 75 rwlock_initialize(&rwlock); 64 76 rwlock_write_lock(&rwlock); 65 77 66 for (i = 0; i < 4; i++) {78 for (i = 0; i < THREADS; i++) { 67 79 thrd = thread_create(reader, NULL, TASK, 0, "reader", false); 68 80 if (thrd) 69 81 thread_ready(thrd); 70 else 82 else if (!quiet) 71 83 printf("Could not create reader %d\n", i); 72 84 } 73 85 74 86 thread_sleep(1); 87 rwlock_write_unlock(&rwlock); 75 88 76 rwlock_write_unlock(&rwlock); 89 while (atomic_get(&thread_count) > 0) { 90 if (!quiet) 91 printf("Threads left: %d\n", atomic_get(&thread_count)); 92 thread_sleep(1); 93 } 77 94 78 95 return NULL; -
kernel/test/synch/rwlock4.c
r6536a4a9 rdeada67 44 44 #define WRITERS 50 45 45 46 static atomic_t thread_count; 46 47 static rwlock_t rwlock; 47 48 static atomic_t threads_fault; 49 static bool sh_quiet; 48 50 49 51 SPINLOCK_INITIALIZE(rw_lock); … … 71 73 72 74 to = random(40000); 73 printf("cpu%d, tid %d w+ (%d)\n", CPU->id, THREAD->tid, to); 75 76 if (!sh_quiet) 77 printf("cpu%d, tid %d w+ (%d)\n", CPU->id, THREAD->tid, to); 78 74 79 rc = rwlock_write_lock_timeout(&rwlock, to); 75 80 if (SYNCH_FAILED(rc)) { 76 printf("cpu%d, tid %d w!\n", CPU->id, THREAD->tid); 81 if (!sh_quiet) 82 printf("cpu%d, tid %d w!\n", CPU->id, THREAD->tid); 83 atomic_dec(&thread_count); 77 84 return; 78 85 } 79 printf("cpu%d, tid %d w=\n", CPU->id, THREAD->tid); 86 87 if (!sh_quiet) 88 printf("cpu%d, tid %d w=\n", CPU->id, THREAD->tid); 80 89 81 90 if (rwlock.readers_in) { 82 printf("Oops."); 91 if (!sh_quiet) 92 printf("Oops."); 83 93 atomic_inc(&threads_fault); 94 atomic_dec(&thread_count); 84 95 return; 85 96 } 86 97 thread_usleep(random(1000000)); 87 98 if (rwlock.readers_in) { 88 printf("Oops."); 99 if (!sh_quiet) 100 printf("Oops."); 89 101 atomic_inc(&threads_fault); 102 atomic_dec(&thread_count); 90 103 return; 91 104 } 92 105 93 106 rwlock_write_unlock(&rwlock); 94 printf("cpu%d, tid %d w-\n", CPU->id, THREAD->tid); 107 108 if (!sh_quiet) 109 printf("cpu%d, tid %d w-\n", CPU->id, THREAD->tid); 110 atomic_dec(&thread_count); 95 111 } 96 112 … … 102 118 103 119 to = random(2000); 104 printf("cpu%d, tid %d r+ (%d)\n", CPU->id, THREAD->tid, to); 120 121 if (!sh_quiet) 122 printf("cpu%d, tid %d r+ (%d)\n", CPU->id, THREAD->tid, to); 123 105 124 rc = rwlock_read_lock_timeout(&rwlock, to); 106 125 if (SYNCH_FAILED(rc)) { 107 printf("cpu%d, tid %d r!\n", CPU->id, THREAD->tid); 126 if (!sh_quiet) 127 printf("cpu%d, tid %d r!\n", CPU->id, THREAD->tid); 128 atomic_dec(&thread_count); 108 129 return; 109 130 } 110 printf("cpu%d, tid %d r=\n", CPU->id, THREAD->tid); 131 132 if (!sh_quiet) 133 printf("cpu%d, tid %d r=\n", CPU->id, THREAD->tid); 134 111 135 thread_usleep(30000); 112 136 rwlock_read_unlock(&rwlock); 113 printf("cpu%d, tid %d r-\n", CPU->id, THREAD->tid); 137 138 if (!sh_quiet) 139 printf("cpu%d, tid %d r-\n", CPU->id, THREAD->tid); 140 atomic_dec(&thread_count); 114 141 } 115 142 … … 117 144 { 118 145 context_t ctx; 119 uint32_t i, k; 146 uint32_t i; 147 sh_quiet = quiet; 120 148 121 149 waitq_initialize(&can_start); … … 123 151 atomic_set(&threads_fault, 0); 124 152 153 uint32_t rd = random(7) + 1; 154 uint32_t wr = random(5) + 1; 155 156 atomic_set(&thread_count, rd + wr); 157 125 158 thread_t *thrd; 126 159 127 160 context_save(&ctx); 128 printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in); 161 if (!quiet) { 162 printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in); 163 printf("Creating %d readers\n", rd); 164 } 129 165 130 k = random(7) + 1; 131 printf("Creating %d readers\n", k); 132 for (i = 0; i < k; i++) { 166 for (i = 0; i < rd; i++) { 133 167 thrd = thread_create(reader, NULL, TASK, 0, "reader", false); 134 168 if (thrd) 135 169 thread_ready(thrd); 136 else 170 else if (!quiet) 137 171 printf("Could not create reader %d\n", i); 138 172 } 139 173 140 k = random(5) + 1; 141 printf("Creating %d writers\n", k); 142 for (i = 0; i < k; i++) { 174 if (!quiet) 175 printf("Creating %d writers\n", wr); 176 177 for (i = 0; i < wr; i++) { 143 178 thrd = thread_create(writer, NULL, TASK, 0, "writer", false); 144 179 if (thrd) 145 180 thread_ready(thrd); 146 else 181 else if (!quiet) 147 182 printf("Could not create writer %d\n", i); 148 183 } … … 151 186 waitq_wakeup(&can_start, WAKEUP_ALL); 152 187 188 while (atomic_get(&thread_count) > 0) { 189 if (!quiet) 190 printf("Threads left: %d\n", atomic_get(&thread_count)); 191 thread_sleep(1); 192 } 193 153 194 if (atomic_get(&threads_fault) == 0) 154 195 return NULL; -
kernel/test/sysinfo/sysinfo1.c
r6536a4a9 rdeada67 35 35 char * test_sysinfo1(bool quiet) 36 36 { 37 sysinfo_dump(NULL, 0); 37 if (!quiet) 38 sysinfo_dump(NULL, 0); 38 39 return NULL; 39 40 } -
kernel/test/thread/thread1.c
r6536a4a9 rdeada67 41 41 static atomic_t finish; 42 42 static atomic_t threads_finished; 43 static bool sh_quiet; 43 44 44 45 static void threadtest(void *data) … … 47 48 48 49 while (atomic_get(&finish)) { 49 printf("%d\n", (int) (THREAD->tid)); 50 if (!sh_quiet) 51 printf("%d\n", (int) (THREAD->tid)); 50 52 thread_usleep(100); 51 53 } … … 56 58 { 57 59 unsigned int i, total = 0; 60 sh_quiet = quiet; 58 61 59 62 atomic_set(&finish, 1); … … 63 66 thread_t *t; 64 67 if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest", false))) { 65 printf("Could not create thread %d\n", i); 68 if (!quiet) 69 printf("Could not create thread %d\n", i); 66 70 break; 67 71 } … … 70 74 } 71 75 72 printf("Running threads for 10 seconds...\n"); 76 if (!quiet) 77 printf("Running threads for 10 seconds...\n"); 73 78 thread_sleep(10); 74 79 75 80 atomic_set(&finish, 0); 76 81 while (atomic_get(&threads_finished) < total) { 77 printf("Threads left: %d\n", total - atomic_get(&threads_finished)); 82 if (!quiet) 83 printf("Threads left: %d\n", total - atomic_get(&threads_finished)); 78 84 thread_sleep(1); 79 85 }
Note:
See TracChangeset
for help on using the changeset viewer.