Changeset 96348adc in mainline for kernel/test/synch


Ignore:
Timestamp:
2006-12-12T17:24:58Z (19 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7e13972
Parents:
34db7fa
Message:

cleanup tests

Location:
kernel/test/synch
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • kernel/test/synch/rwlock1.c

    r34db7fa r96348adc  
    4141static rwlock_t rwlock;
    4242
    43 void test_rwlock1(void)
     43char * test_rwlock1(void)
    4444{
    45         printf("Read/write locks test #1\n");
    46 
    4745        rwlock_initialize(&rwlock);
    4846
     
    7472        rwlock_read_lock(&rwlock);
    7573        rwlock_read_unlock(&rwlock);
    76 
    77         printf("Test passed.\n");
     74       
     75        return NULL;
    7876}
  • 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  
    4040static rwlock_t rwlock;
    4141
    42 static void writer(void *arg);
    43 static void failed(void);
    44 
    4542static void writer(void *arg)
    4643{
     
    5956}
    6057
    61 static void failed()
    62 {
    63         printf("Test failed prematurely.\n");
    64         thread_exit();
    65 }
    66 
    67 void test_rwlock2(void)
     58char * test_rwlock2(void)
    6859{
    6960        thread_t *thrd;
    7061       
    71         printf("Read/write locks test #2\n");
    72    
    7362        rwlock_initialize(&rwlock);
    7463
     
    8271                thread_ready(thrd);
    8372        else
    84                 failed();
    85 
     73                return "Could not create thread";
    8674
    8775        thread_sleep(1);
     
    9078        rwlock_read_unlock(&rwlock);
    9179        rwlock_read_unlock(&rwlock);
    92         rwlock_read_unlock(&rwlock);   
    93 
     80        rwlock_read_unlock(&rwlock);
     81       
     82        return NULL;
    9483}
  • 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  
    4040static rwlock_t rwlock;
    4141
    42 static void reader(void *arg);
    43 static void failed(void);
    44 
    4542static void reader(void *arg)
    4643{
     
    5754        rwlock_write_unlock(&rwlock);
    5855        printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid);                       
    59        
    60         printf("Test passed.\n");       
    61 
    6256}
    6357
    64 static void failed(void)
    65 {
    66         printf("Test failed prematurely.\n");
    67         thread_exit();
    68 }
    69 
    70 void test_rwlock3(void)
     58char * test_rwlock3(void)
    7159{
    7260        int i;
    7361        thread_t *thrd;
    7462       
    75         printf("Read/write locks test #3\n");
    76    
    7763        rwlock_initialize(&rwlock);
    78 
    7964        rwlock_write_lock(&rwlock);
    8065       
    81         for (i=0; i<4; i++) {
     66        for (i = 0; i < 4; i++) {
    8267                thrd = thread_create(reader, NULL, TASK, 0, "reader");
    8368                if (thrd)
    8469                        thread_ready(thrd);
    8570                else
    86                         failed();
     71                        printf("Could not create reader %d\n", i);
    8772        }
    88 
    8973
    9074        thread_sleep(1);
    9175       
    9276        rwlock_write_unlock(&rwlock);
     77       
     78        return NULL;
    9379}
  • 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  
    5353static uint32_t seed = 0xdeadbeef;
    5454
    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 
    6155static uint32_t random(uint32_t max)
    6256{
     
    6963        return rc;
    7064}
    71 
    7265
    7366static void writer(void *arg)
     
    8376                printf("cpu%d, tid %d w!\n", CPU->id, THREAD->tid);
    8477                return;
    85         };
     78        }
    8679        printf("cpu%d, tid %d w=\n", CPU->id, THREAD->tid);
    8780
     
    113106}
    114107
    115 static void failed(void)
    116 {
    117         printf("Test failed prematurely.\n");
    118         thread_exit();
    119 }
    120 
    121 void test_rwlock4(void)
     108char * test_rwlock4(void)
    122109{
    123110        context_t ctx;
    124111        uint32_t i, k;
    125112       
    126         printf("Read/write locks test #4\n");
    127    
    128113        waitq_initialize(&can_start);
    129114        rwlock_initialize(&rwlock);
    130115       
    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        }
    146130
    147                 k = random(5) + 1;
    148                 printf("Creating %d writers\n", k);
    149                 for (i=0; i<k; i++) {
    150                         thrd = thread_create(writer, NULL, TASK, 0, "writer");
    151                         if (thrd)
    152                                 thread_ready(thrd);
    153                         else
    154                                 failed();
    155                 }
    156                
    157                 thread_usleep(20000);
    158                 waitq_wakeup(&can_start, WAKEUP_ALL);
    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;
    161145}
  • 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  
    4545static atomic_t items_written;
    4646
    47 static void writer(void *arg);
    48 static void reader(void *arg);
    49 static void failed(void);
    50 
    51 void writer(void *arg)
     47static void writer(void *arg)
    5248{
    5349        thread_detach(THREAD);
     
    6056}
    6157
    62 void reader(void *arg)
     58static void reader(void *arg)
    6359{
    6460        thread_detach(THREAD);
     
    7167}
    7268
    73 void failed(void)
    74 {
    75         printf("Test failed prematurely.\n");
    76         thread_exit();
    77 }
    78 
    79 void test_rwlock5(void)
     69char * test_rwlock5(void)
    8070{
    8171        int i, j, k;
    8272        count_t readers, writers;
    8373       
    84         printf("Read/write locks test #5\n");
    85    
    8674        waitq_initialize(&can_start);
    8775        rwlock_initialize(&rwlock);
    8876       
    89         for (i=1; i<=3; i++) {
     77        for (i = 1; i <= 3; i++) {
    9078                thread_t *thrd;
    9179
     
    9381                atomic_set(&items_written, 0);
    9482
    95                 readers = i*READERS;
    96                 writers = (4-i)*WRITERS;
     83                readers = i * READERS;
     84                writers = (4 - i) * WRITERS;
    9785
    9886                printf("Creating %ld readers and %ld writers...", readers, writers);
    9987               
    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++) {
    10290                                thrd = thread_create(reader, NULL, TASK, 0, "reader");
    10391                                if (thrd)
    10492                                        thread_ready(thrd);
    10593                                else
    106                                         failed();
     94                                        printf("Could not create reader %d\n", k);
    10795                        }
    108                         for (k=0; k<(4-i); k++) {
     96                        for (k = 0; k < (4 - i); k++) {
    10997                                thrd = thread_create(writer, NULL, TASK, 0, "writer");
    11098                                if (thrd)
    11199                                        thread_ready(thrd);
    112100                                else
    113                                         failed();
     101                                        printf("Could not create writer %d\n", k);
    114102                        }
    115103                }
     
    120108                waitq_wakeup(&can_start, WAKEUP_ALL);
    121109       
    122                 while (items_read.count != readers || items_written.count != writers) {
     110                while ((items_read.count != readers) || (items_written.count != writers)) {
    123111                        printf("%zd readers remaining, %zd writers remaining, readers_in=%zd\n", readers - items_read.count, writers - items_written.count, rwlock.readers_in);
    124112                        thread_usleep(100000);
    125113                }
    126114        }
    127         printf("Test passed.\n");
     115       
     116        return NULL;
    128117}
  • 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  
    4646static atomic_t items_consumed;
    4747
    48 static void consumer(void *arg);
    49 static void producer(void *arg);
    50 static void failed(void);
    51 
    5248static void producer(void *arg)
    5349{
     
    7470}
    7571
    76 static void failed(void)
    77 {
    78         printf("Test failed prematurely.\n");
    79         thread_exit();
    80 }
    81 
    82 void test_semaphore1(void)
     72char * test_semaphore1(void)
    8373{
    8474        int i, j, k;
    8575        int consumers, producers;
    8676       
    87         printf("Semaphore test #1\n");
    88    
    8977        waitq_initialize(&can_start);
    9078        semaphore_initialize(&sem, AT_ONCE);
    9179
    92 
    93         for (i=1; i<=3; i++) {
     80        for (i = 1; i <= 3; i++) {
    9481                thread_t *thrd;
    9582
     
    9885               
    9986                consumers = i * CONSUMERS;
    100                 producers = (4-i) * PRODUCERS;
     87                producers = (4 - i) * PRODUCERS;
    10188               
    10289                printf("Creating %d consumers and %d producers...", consumers, producers);
    10390       
    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++) {
    10693                                thrd = thread_create(consumer, NULL, TASK, 0, "consumer");
    10794                                if (thrd)
    10895                                        thread_ready(thrd);
    10996                                else
    110                                         failed();
     97                                        printf("could not create consumer %d\n", i);
    11198                        }
    112                         for (k=0; k<(4-i); k++) {
     99                        for (k = 0; k < (4 - i); k++) {
    113100                                thrd = thread_create(producer, NULL, TASK, 0, "producer");
    114101                                if (thrd)
    115102                                        thread_ready(thrd);
    116103                                else
    117                                         failed();
     104                                        printf("could not create producer %d\n", i);
    118105                        }
    119106                }
     
    124111                waitq_wakeup(&can_start, WAKEUP_ALL);
    125112       
    126                 while (items_consumed.count != consumers || items_produced.count != producers) {
     113                while ((items_consumed.count != consumers) || (items_produced.count != producers)) {
    127114                        printf("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count);
    128115                        thread_sleep(1);
    129116                }
    130117        }
    131         printf("Test passed.\n");
     118       
     119        return NULL;
    132120}
  • 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  
    4848static uint32_t seed = 0xdeadbeef;
    4949
    50 static uint32_t random(uint32_t max);
    51 
    52 static void consumer(void *arg);
    53 static void failed(void);
    54 
    5550static uint32_t random(uint32_t max)
    5651{
     
    6358        return rc;
    6459}
    65 
    6660
    6761static void consumer(void *arg)
     
    8882}
    8983
    90 static void failed(void)
    91 {
    92         printf("Test failed prematurely.\n");
    93         thread_exit();
    94 }
    95 
    96 void test_semaphore2(void)
     84char * test_semaphore2(void)
    9785{
    9886        uint32_t i, k;
    9987       
    100         printf("Semaphore test #2\n");
    101    
    10288        waitq_initialize(&can_start);
    10389        semaphore_initialize(&sem, 5);
    10490       
    105 
     91        thread_t *thrd;
    10692       
    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;
    124107}
  • 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.