Changeset 96348adc in mainline
- Timestamp:
- 2006-12-12T17:24:58Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7e13972
- Parents:
- 34db7fa
- Location:
- kernel/test
- Files:
-
- 34 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 }, -
kernel/test/print/print1.c
r34db7fa r96348adc 31 31 #define BUFFER_SIZE 32 32 32 33 voidtest_print1(void)33 char * test_print1(void) 34 34 { 35 35 int retval; … … 37 37 38 38 char buffer[BUFFER_SIZE]; 39 40 printf(" Printf test \n");41 39 42 40 printf(" text 10.8s %*.*s \n", 5, 3, "text"); … … 52 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" ); 53 51 54 printf(" Print to NULL '%s'\n", NULL);52 printf(" Print to NULL '%s'\n", NULL); 55 53 56 54 retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters."); … … 68 66 printf("Result is: '%s', retval = %d\n", buffer, retval); 69 67 70 return ;68 return NULL; 71 69 } -
kernel/test/print/print1.def
r34db7fa r96348adc 1 { 2 "print1", 3 "Printf test", 4 &test_print1, 5 true 6 }, -
kernel/test/synch/rwlock1.c
r34db7fa r96348adc 41 41 static rwlock_t rwlock; 42 42 43 voidtest_rwlock1(void)43 char * test_rwlock1(void) 44 44 { 45 printf("Read/write locks test #1\n");46 47 45 rwlock_initialize(&rwlock); 48 46 … … 74 72 rwlock_read_lock(&rwlock); 75 73 rwlock_read_unlock(&rwlock); 76 77 printf("Test passed.\n");74 75 return NULL; 78 76 } -
kernel/test/synch/rwlock1.def
r34db7fa r96348adc 1 { 2 "rwlock1", 3 "RW-lock test 1", 4 &test_rwlock1, 5 true 6 }, -
kernel/test/synch/rwlock2.c
r34db7fa r96348adc 40 40 static rwlock_t rwlock; 41 41 42 static void writer(void *arg);43 static void failed(void);44 45 42 static void writer(void *arg) 46 43 { … … 59 56 } 60 57 61 static void failed() 62 { 63 printf("Test failed prematurely.\n"); 64 thread_exit(); 65 } 66 67 void test_rwlock2(void) 58 char * test_rwlock2(void) 68 59 { 69 60 thread_t *thrd; 70 61 71 printf("Read/write locks test #2\n");72 73 62 rwlock_initialize(&rwlock); 74 63 … … 82 71 thread_ready(thrd); 83 72 else 84 failed(); 85 73 return "Could not create thread"; 86 74 87 75 thread_sleep(1); … … 90 78 rwlock_read_unlock(&rwlock); 91 79 rwlock_read_unlock(&rwlock); 92 rwlock_read_unlock(&rwlock); 93 80 rwlock_read_unlock(&rwlock); 81 82 return NULL; 94 83 } -
kernel/test/synch/rwlock2.def
r34db7fa r96348adc 1 { 2 "rwlock2", 3 "RW-lock test 2", 4 &test_rwlock2, 5 true 6 }, -
kernel/test/synch/rwlock3.c
r34db7fa r96348adc 40 40 static rwlock_t rwlock; 41 41 42 static void reader(void *arg);43 static void failed(void);44 45 42 static void reader(void *arg) 46 43 { … … 57 54 rwlock_write_unlock(&rwlock); 58 55 printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid); 59 60 printf("Test passed.\n");61 62 56 } 63 57 64 static void failed(void) 65 { 66 printf("Test failed prematurely.\n"); 67 thread_exit(); 68 } 69 70 void test_rwlock3(void) 58 char * test_rwlock3(void) 71 59 { 72 60 int i; 73 61 thread_t *thrd; 74 62 75 printf("Read/write locks test #3\n");76 77 63 rwlock_initialize(&rwlock); 78 79 64 rwlock_write_lock(&rwlock); 80 65 81 for (i =0; i<4; i++) {66 for (i = 0; i < 4; i++) { 82 67 thrd = thread_create(reader, NULL, TASK, 0, "reader"); 83 68 if (thrd) 84 69 thread_ready(thrd); 85 70 else 86 failed();71 printf("Could not create reader %d\n", i); 87 72 } 88 89 73 90 74 thread_sleep(1); 91 75 92 76 rwlock_write_unlock(&rwlock); 77 78 return NULL; 93 79 } -
kernel/test/synch/rwlock3.def
r34db7fa r96348adc 1 { 2 "rwlock3", 3 "RW-lock test 3", 4 &test_rwlock3, 5 true 6 }, -
kernel/test/synch/rwlock4.c
r34db7fa r96348adc 53 53 static uint32_t seed = 0xdeadbeef; 54 54 55 static uint32_t random(uint32_t max);56 57 static void writer(void *arg);58 static void reader(void *arg);59 static void failed(void);60 61 55 static uint32_t random(uint32_t max) 62 56 { … … 69 63 return rc; 70 64 } 71 72 65 73 66 static void writer(void *arg) … … 83 76 printf("cpu%d, tid %d w!\n", CPU->id, THREAD->tid); 84 77 return; 85 } ;78 } 86 79 printf("cpu%d, tid %d w=\n", CPU->id, THREAD->tid); 87 80 … … 113 106 } 114 107 115 static void failed(void) 116 { 117 printf("Test failed prematurely.\n"); 118 thread_exit(); 119 } 120 121 void test_rwlock4(void) 108 char * test_rwlock4(void) 122 109 { 123 110 context_t ctx; 124 111 uint32_t i, k; 125 112 126 printf("Read/write locks test #4\n");127 128 113 waitq_initialize(&can_start); 129 114 rwlock_initialize(&rwlock); 130 115 131 for (;;) { 132 thread_t *thrd; 133 134 context_save(&ctx); 135 printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in); 136 137 k = random(7) + 1; 138 printf("Creating %d readers\n", k); 139 for (i=0; i<k; i++) { 140 thrd = thread_create(reader, NULL, TASK, 0, "reader"); 141 if (thrd) 142 thread_ready(thrd); 143 else 144 failed(); 145 } 116 thread_t *thrd; 117 118 context_save(&ctx); 119 printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in); 120 121 k = random(7) + 1; 122 printf("Creating %d readers\n", k); 123 for (i = 0; i < k; i++) { 124 thrd = thread_create(reader, NULL, TASK, 0, "reader"); 125 if (thrd) 126 thread_ready(thrd); 127 else 128 printf("Could not create reader %d\n", i); 129 } 146 130 147 148 149 150 151 152 153 154 failed();155 156 157 158 159 }160 131 k = random(5) + 1; 132 printf("Creating %d writers\n", k); 133 for (i=0; i<k; i++) { 134 thrd = thread_create(writer, NULL, TASK, 0, "writer"); 135 if (thrd) 136 thread_ready(thrd); 137 else 138 printf("Could not create writer %d\n", i); 139 } 140 141 thread_usleep(20000); 142 waitq_wakeup(&can_start, WAKEUP_ALL); 143 144 return NULL; 161 145 } -
kernel/test/synch/rwlock4.def
r34db7fa r96348adc 1 { 2 "rwlock4", 3 "RW-lock test 4", 4 &test_rwlock4, 5 true 6 }, -
kernel/test/synch/rwlock5.c
r34db7fa r96348adc 45 45 static atomic_t items_written; 46 46 47 static void writer(void *arg); 48 static void reader(void *arg); 49 static void failed(void); 50 51 void writer(void *arg) 47 static void writer(void *arg) 52 48 { 53 49 thread_detach(THREAD); … … 60 56 } 61 57 62 void reader(void *arg)58 static void reader(void *arg) 63 59 { 64 60 thread_detach(THREAD); … … 71 67 } 72 68 73 void failed(void) 74 { 75 printf("Test failed prematurely.\n"); 76 thread_exit(); 77 } 78 79 void test_rwlock5(void) 69 char * test_rwlock5(void) 80 70 { 81 71 int i, j, k; 82 72 count_t readers, writers; 83 73 84 printf("Read/write locks test #5\n");85 86 74 waitq_initialize(&can_start); 87 75 rwlock_initialize(&rwlock); 88 76 89 for (i =1; i<=3; i++) {77 for (i = 1; i <= 3; i++) { 90 78 thread_t *thrd; 91 79 … … 93 81 atomic_set(&items_written, 0); 94 82 95 readers = i *READERS;96 writers = (4 -i)*WRITERS;83 readers = i * READERS; 84 writers = (4 - i) * WRITERS; 97 85 98 86 printf("Creating %ld readers and %ld writers...", readers, writers); 99 87 100 for (j =0; j<(READERS+WRITERS)/2; j++) {101 for (k =0; k<i; k++) {88 for (j = 0; j < (READERS + WRITERS) / 2; j++) { 89 for (k = 0; k < i; k++) { 102 90 thrd = thread_create(reader, NULL, TASK, 0, "reader"); 103 91 if (thrd) 104 92 thread_ready(thrd); 105 93 else 106 failed();94 printf("Could not create reader %d\n", k); 107 95 } 108 for (k =0; k<(4-i); k++) {96 for (k = 0; k < (4 - i); k++) { 109 97 thrd = thread_create(writer, NULL, TASK, 0, "writer"); 110 98 if (thrd) 111 99 thread_ready(thrd); 112 100 else 113 failed();101 printf("Could not create writer %d\n", k); 114 102 } 115 103 } … … 120 108 waitq_wakeup(&can_start, WAKEUP_ALL); 121 109 122 while ( items_read.count != readers || items_written.count != writers) {110 while ((items_read.count != readers) || (items_written.count != writers)) { 123 111 printf("%zd readers remaining, %zd writers remaining, readers_in=%zd\n", readers - items_read.count, writers - items_written.count, rwlock.readers_in); 124 112 thread_usleep(100000); 125 113 } 126 114 } 127 printf("Test passed.\n"); 115 116 return NULL; 128 117 } -
kernel/test/synch/rwlock5.def
r34db7fa r96348adc 1 { 2 "rwlock5", 3 "RW-lock test 5", 4 &test_rwlock5, 5 true 6 }, -
kernel/test/synch/semaphore1.c
r34db7fa r96348adc 46 46 static atomic_t items_consumed; 47 47 48 static void consumer(void *arg);49 static void producer(void *arg);50 static void failed(void);51 52 48 static void producer(void *arg) 53 49 { … … 74 70 } 75 71 76 static void failed(void) 77 { 78 printf("Test failed prematurely.\n"); 79 thread_exit(); 80 } 81 82 void test_semaphore1(void) 72 char * test_semaphore1(void) 83 73 { 84 74 int i, j, k; 85 75 int consumers, producers; 86 76 87 printf("Semaphore test #1\n");88 89 77 waitq_initialize(&can_start); 90 78 semaphore_initialize(&sem, AT_ONCE); 91 79 92 93 for (i=1; i<=3; i++) { 80 for (i = 1; i <= 3; i++) { 94 81 thread_t *thrd; 95 82 … … 98 85 99 86 consumers = i * CONSUMERS; 100 producers = (4 -i) * PRODUCERS;87 producers = (4 - i) * PRODUCERS; 101 88 102 89 printf("Creating %d consumers and %d producers...", consumers, producers); 103 90 104 for (j =0; j<(CONSUMERS+PRODUCERS)/2; j++) {105 for (k =0; k<i; k++) {91 for (j = 0; j < (CONSUMERS + PRODUCERS) / 2; j++) { 92 for (k = 0; k < i; k++) { 106 93 thrd = thread_create(consumer, NULL, TASK, 0, "consumer"); 107 94 if (thrd) 108 95 thread_ready(thrd); 109 96 else 110 failed();97 printf("could not create consumer %d\n", i); 111 98 } 112 for (k =0; k<(4-i); k++) {99 for (k = 0; k < (4 - i); k++) { 113 100 thrd = thread_create(producer, NULL, TASK, 0, "producer"); 114 101 if (thrd) 115 102 thread_ready(thrd); 116 103 else 117 failed();104 printf("could not create producer %d\n", i); 118 105 } 119 106 } … … 124 111 waitq_wakeup(&can_start, WAKEUP_ALL); 125 112 126 while ( items_consumed.count != consumers || items_produced.count != producers) {113 while ((items_consumed.count != consumers) || (items_produced.count != producers)) { 127 114 printf("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count); 128 115 thread_sleep(1); 129 116 } 130 117 } 131 printf("Test passed.\n"); 118 119 return NULL; 132 120 } -
kernel/test/synch/semaphore1.def
r34db7fa r96348adc 1 { 2 "semaphore1", 3 "Semaphore test 1", 4 &test_semaphore1, 5 true 6 }, -
kernel/test/synch/semaphore2.c
r34db7fa r96348adc 48 48 static uint32_t seed = 0xdeadbeef; 49 49 50 static uint32_t random(uint32_t max);51 52 static void consumer(void *arg);53 static void failed(void);54 55 50 static uint32_t random(uint32_t max) 56 51 { … … 63 58 return rc; 64 59 } 65 66 60 67 61 static void consumer(void *arg) … … 88 82 } 89 83 90 static void failed(void) 91 { 92 printf("Test failed prematurely.\n"); 93 thread_exit(); 94 } 95 96 void test_semaphore2(void) 84 char * test_semaphore2(void) 97 85 { 98 86 uint32_t i, k; 99 87 100 printf("Semaphore test #2\n");101 102 88 waitq_initialize(&can_start); 103 89 semaphore_initialize(&sem, 5); 104 90 105 91 thread_t *thrd; 106 92 107 for (; ;) { 108 thread_t *thrd; 109 110 k = random(7) + 1; 111 printf("Creating %d consumers\n", k); 112 for (i=0; i<k; i++) { 113 thrd = thread_create(consumer, NULL, TASK, 0, "consumer"); 114 if (thrd) 115 thread_ready(thrd); 116 else 117 failed(); 118 } 119 120 thread_usleep(20000); 121 waitq_wakeup(&can_start, WAKEUP_ALL); 122 } 123 93 k = random(7) + 1; 94 printf("Creating %d consumers\n", k); 95 for (i = 0; i < k; i++) { 96 thrd = thread_create(consumer, NULL, TASK, 0, "consumer"); 97 if (thrd) 98 thread_ready(thrd); 99 else 100 printf("Error creating thread\n"); 101 } 102 103 thread_usleep(20000); 104 waitq_wakeup(&can_start, WAKEUP_ALL); 105 106 return NULL; 124 107 } -
kernel/test/synch/semaphore2.def
r34db7fa r96348adc 1 { 2 "semaphore2", 3 "Semaphore test 2", 4 &test_semaphore2, 5 true 6 }, -
kernel/test/sysinfo/sysinfo1.c
r34db7fa r96348adc 33 33 #include <test.h> 34 34 #include <sysinfo/sysinfo.h> 35 /* 36 static unative_t counter(sysinfo_item_t *root)35 36 char * test_sysinfo1(void) 37 37 { 38 static unative_t i=0; 39 return i++; 40 }*/ 41 42 void test_sysinfo1(void) 43 { 44 /* sysinfo_set_item_val("Ahoj.lidi.uaaaa",NULL,9); 45 sysinfo_set_item_val("Ahoj.lidi.ubbbb",NULL,15); 46 sysinfo_set_item_val("Ahoj.lidi",NULL,64); 47 sysinfo_set_item_function("Ahoj",NULL,counter); 48 sysinfo_dump(NULL,0); 49 sysinfo_set_item_val("Ahoj.lidi.ubbbb",NULL,75); 50 sysinfo_dump(NULL,0); 51 sysinfo_dump(NULL,0); 52 sysinfo_dump(NULL,0);*/ 53 sysinfo_dump(NULL,0); 38 sysinfo_dump(NULL, 0); 39 return NULL; 54 40 } -
kernel/test/sysinfo/sysinfo1.def
r34db7fa r96348adc 1 { 2 "sysinfo1", 3 "Sysinfo test", 4 &test_sysinfo1, 5 true 6 }, -
kernel/test/test.c
r34db7fa r96348adc 43 43 #include <fpu/sse1.def> 44 44 #include <fpu/mips2.def> 45 /* 46 { 47 "falloc1", 48 "Frame allocator test 1", 49 &test_falloc1, 50 true 51 }, 52 { 53 "falloc2", 54 "Frame allocator test 2", 55 &test_falloc2, 56 true 57 }, 58 { 59 "mapping1", 60 "Mapping test", 61 &test_mapping1, 62 true 63 }, 64 { 65 "slab1", 66 "SLAB test 1", 67 &test_slab1, 68 true 69 }, 70 { 71 "slab2", 72 "SLAB test 2", 73 &test_slab2, 74 true 75 }, 76 { 77 "purge1", 78 "Itanium TLB purge test", 79 &test_purge1, 80 true 81 }, 82 { 83 "rwlock1", 84 "RW-lock test 1", 85 &test_rwlock1, 86 true 87 }, 88 { 89 "rwlock2", 90 "RW-lock test 2", 91 &test_rwlock2, 92 true 93 }, 94 { 95 "rwlock3", 96 "RW-lock test 3", 97 &test_rwlock3, 98 true 99 }, 100 { 101 "rwlock4", 102 "RW-lock test 4", 103 &test_rwlock4, 104 true 105 }, 106 { 107 "rwlock5", 108 "RW-lock test 5", 109 &test_rwlock5, 110 true 111 }, 112 { 113 "semaphore1", 114 "Semaphore test 1", 115 &test_semaphore1, 116 true 117 }, 118 { 119 "semaphore2", 120 "Semaphore test 2", 121 &test_semaphore2, 122 true 123 }, 124 { 125 "print1", 126 "Printf test", 127 &test_print1, 128 true 129 }, 130 { 131 "thread1", 132 "Thread test", 133 &test_thread1, 134 true 135 }, 136 { 137 "sysinfo1", 138 "Sysinfo test", 139 &test_sysinfo1, 140 true 141 },*/ 45 #include <mm/falloc1.def> 46 #include <mm/falloc2.def> 47 #include <mm/mapping1.def> 48 #include <mm/slab1.def> 49 #include <mm/slab2.def> 50 #include <synch/rwlock1.def> 51 #include <synch/rwlock2.def> 52 #include <synch/rwlock3.def> 53 #include <synch/rwlock4.def> 54 #include <synch/rwlock5.def> 55 #include <synch/semaphore1.def> 56 #include <synch/semaphore2.def> 57 #include <print/print1.def> 58 #include <thread/thread1.def> 59 #include <sysinfo/sysinfo1.def> 142 60 {NULL, NULL, NULL} 143 61 }; -
kernel/test/test.h
r34db7fa r96348adc 55 55 extern char * test_sse1(void); 56 56 extern char * test_mips2(void); 57 extern voidtest_falloc1(void);58 extern voidtest_falloc2(void);59 extern voidtest_mapping1(void);60 extern voidtest_purge1(void);61 extern voidtest_slab1(void);62 extern voidtest_slab2(void);63 extern voidtest_rwlock1(void);64 extern voidtest_rwlock2(void);65 extern voidtest_rwlock3(void);66 extern voidtest_rwlock4(void);67 extern voidtest_rwlock5(void);68 extern voidtest_semaphore1(void);69 extern voidtest_semaphore2(void);70 extern voidtest_print1(void);71 extern voidtest_thread1(void);72 extern voidtest_sysinfo1(void);57 extern char * test_falloc1(void); 58 extern char * test_falloc2(void); 59 extern char * test_mapping1(void); 60 extern char * test_purge1(void); 61 extern char * test_slab1(void); 62 extern char * test_slab2(void); 63 extern char * test_rwlock1(void); 64 extern char * test_rwlock2(void); 65 extern char * test_rwlock3(void); 66 extern char * test_rwlock4(void); 67 extern char * test_rwlock5(void); 68 extern char * test_semaphore1(void); 69 extern char * test_semaphore2(void); 70 extern char * test_print1(void); 71 extern char * test_thread1(void); 72 extern char * test_sysinfo1(void); 73 73 74 74 extern test_t tests[]; -
kernel/test/thread/thread1.c
r34db7fa r96348adc 40 40 #define THREADS 5 41 41 42 static atomic_t finish; 43 static atomic_t threads_finished; 44 42 45 static void threadtest(void *data) 43 46 { 44 45 47 thread_detach(THREAD); 46 48 47 while (1) 48 printf("%d\n",(int)(THREAD->tid)); 49 while (atomic_get(&finish)) { 50 printf("%d\n", (int) (THREAD->tid)); 51 thread_usleep(100); 52 } 53 atomic_inc(&threads_finished); 49 54 } 50 55 51 voidtest_thread1(void)56 char * test_thread1(void) 52 57 { 53 thread_t *t; 54 int i; 58 unsigned int i, total = 0; 59 60 atomic_set(&finish, 1); 61 atomic_set(&threads_finished, 0); 55 62 56 for (i=0; i<THREADS; i++) { 57 if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest"))) 58 panic("could not create thread\n"); 63 for (i = 0; i < THREADS; i++) { 64 thread_t *t; 65 if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest"))) { 66 printf("Could not create thread %d\n", i); 67 break; 68 } 59 69 thread_ready(t); 70 total++; 60 71 } 61 printf("ok\n"); 72 73 printf("Running threads for 10 seconds...\n"); 74 thread_sleep(10); 75 76 atomic_set(&finish, 0); 77 while (atomic_get(&threads_finished) < total) { 78 printf("Threads left: %d\n", total - atomic_get(&threads_finished)); 79 thread_sleep(1); 80 } 81 82 return NULL; 62 83 } -
kernel/test/thread/thread1.def
r34db7fa r96348adc 1 { 2 "thread1", 3 "Thread test", 4 &test_thread1, 5 true 6 },
Note:
See TracChangeset
for help on using the changeset viewer.