Changeset 96348adc in mainline for kernel/test/synch
- 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/synch
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
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 },
Note:
See TracChangeset
for help on using the changeset viewer.