Changeset cb01e1e in mainline for kernel/test/synch


Ignore:
Timestamp:
2009-04-04T00:26:27Z (17 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a85aebd
Parents:
171f9a1
Message:

use global variable and a macro for silencing tests

Location:
kernel/test/synch
Files:
7 edited

Legend:

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

    r171f9a1 rcb01e1e  
    3636#include <synch/rwlock.h>
    3737
    38 #define READERS         50
    39 #define WRITERS         50
     38#define READERS  50
     39#define WRITERS  50
    4040
    4141static rwlock_t rwlock;
    4242
    43 char * test_rwlock1(bool quiet)
     43char *test_rwlock1(void)
    4444{
    4545        rwlock_initialize(&rwlock);
    46 
     46       
    4747        rwlock_write_lock(&rwlock);
    48         rwlock_write_unlock(&rwlock);   
    49 
    50         rwlock_read_lock(&rwlock);
    51         rwlock_read_lock(&rwlock);     
     48        rwlock_write_unlock(&rwlock);
     49       
    5250        rwlock_read_lock(&rwlock);
    5351        rwlock_read_lock(&rwlock);
    5452        rwlock_read_lock(&rwlock);
    55 
     53        rwlock_read_lock(&rwlock);
     54        rwlock_read_lock(&rwlock);
     55       
    5656        rwlock_read_unlock(&rwlock);
    57         rwlock_read_unlock(&rwlock);   
     57        rwlock_read_unlock(&rwlock);
    5858        rwlock_read_unlock(&rwlock);
    5959        rwlock_read_unlock(&rwlock);
     
    6161       
    6262        rwlock_write_lock(&rwlock);
    63         rwlock_write_unlock(&rwlock);   
    64 
     63        rwlock_write_unlock(&rwlock);
     64       
    6565        rwlock_read_lock(&rwlock);
    6666        rwlock_read_unlock(&rwlock);
    67 
     67       
    6868        rwlock_write_lock(&rwlock);
    69         rwlock_write_unlock(&rwlock);   
    70 
     69        rwlock_write_unlock(&rwlock);
     70       
    7171        rwlock_read_lock(&rwlock);
    7272        rwlock_read_unlock(&rwlock);
  • kernel/test/synch/rwlock2.c

    r171f9a1 rcb01e1e  
    3535#include <synch/rwlock.h>
    3636
    37 #define READERS         50
    38 #define WRITERS         50
     37#define READERS  50
     38#define WRITERS  50
    3939
    4040static rwlock_t rwlock;
    41 static bool sh_quiet;
    4241
    4342static void writer(void *arg)
    4443{
    45         if (!sh_quiet)
    46                 printf("Trying to lock rwlock for writing....\n");
     44        TPRINTF("Trying to lock rwlock for writing....\n");
    4745       
    4846        rwlock_write_lock(&rwlock);
    4947        rwlock_write_unlock(&rwlock);
    5048       
    51         if (!sh_quiet)
    52                 printf("Trying to lock rwlock for reading....\n");
     49        TPRINTF("Trying to lock rwlock for reading....\n");
    5350       
    5451        rwlock_read_lock(&rwlock);
    55         rwlock_read_unlock(&rwlock);   
     52        rwlock_read_unlock(&rwlock);
    5653}
    5754
    58 char * test_rwlock2(bool quiet)
     55char *test_rwlock2(void)
    5956{
    6057        thread_t *thrd;
    61         sh_quiet = quiet;
    6258       
    6359        rwlock_initialize(&rwlock);
    64 
     60       
    6561        rwlock_read_lock(&rwlock);
    6662        rwlock_read_lock(&rwlock);
    6763        rwlock_read_lock(&rwlock);
    68         rwlock_read_lock(&rwlock);     
     64        rwlock_read_lock(&rwlock);
    6965       
    7066        thrd = thread_create(writer, NULL, TASK, 0, "writer", false);
     
    7369        else
    7470                return "Could not create thread";
    75 
     71       
    7672        thread_sleep(1);
    7773       
  • kernel/test/synch/rwlock3.c

    r171f9a1 rcb01e1e  
    3535#include <synch/rwlock.h>
    3636
    37 #define THREADS 4
     37#define THREADS  4
    3838
    3939static atomic_t thread_count;
    4040static rwlock_t rwlock;
    41 static bool sh_quiet;
    4241
    4342static void reader(void *arg)
     
    4544        thread_detach(THREAD);
    4645       
    47         if (!sh_quiet)
    48                 printf("cpu%u, tid %" PRIu64 ": trying to lock rwlock for reading....\n", CPU->id, THREAD->tid);
     46        TPRINTF("cpu%u, tid %" PRIu64 ": trying to lock rwlock for reading....\n", CPU->id, THREAD->tid);
    4947       
    5048        rwlock_read_lock(&rwlock);
    5149        rwlock_read_unlock(&rwlock);
    5250       
    53         if (!sh_quiet) {
    54                 printf("cpu%u, tid %" PRIu64 ": success\n", CPU->id, THREAD->tid);             
    55                 printf("cpu%u, tid %" PRIu64 ": trying to lock rwlock for writing....\n", CPU->id, THREAD->tid);       
    56         }
    57 
     51        TPRINTF("cpu%u, tid %" PRIu64 ": success\n", CPU->id, THREAD->tid);
     52        TPRINTF("cpu%u, tid %" PRIu64 ": trying to lock rwlock for writing....\n", CPU->id, THREAD->tid);
     53       
    5854        rwlock_write_lock(&rwlock);
    5955        rwlock_write_unlock(&rwlock);
    6056       
    61         if (!sh_quiet)
    62                 printf("cpu%u, tid %" PRIu64 ": success\n", CPU->id, THREAD->tid);
     57        TPRINTF("cpu%u, tid %" PRIu64 ": success\n", CPU->id, THREAD->tid);
    6358       
    6459        atomic_dec(&thread_count);
    6560}
    6661
    67 char * test_rwlock3(bool quiet)
     62char *test_rwlock3(void)
    6863{
    6964        int i;
    7065        thread_t *thrd;
    71         sh_quiet = quiet;
    7266       
    7367        atomic_set(&thread_count, THREADS);
     
    8074                if (thrd)
    8175                        thread_ready(thrd);
    82                 else if (!quiet)
    83                         printf("Could not create reader %d\n", i);
     76                else
     77                        TPRINTF("Could not create reader %d\n", i);
    8478        }
    85 
     79       
    8680        thread_sleep(1);
    8781        rwlock_write_unlock(&rwlock);
    8882       
    8983        while (atomic_get(&thread_count) > 0) {
    90                 if (!quiet)
    91                         printf("Threads left: %ld\n", atomic_get(&thread_count));
     84                TPRINTF("Threads left: %ld\n", atomic_get(&thread_count));
    9285                thread_sleep(1);
    9386        }
  • kernel/test/synch/rwlock4.c

    r171f9a1 rcb01e1e  
    4141#include <synch/spinlock.h>
    4242
    43 #define READERS         50
    44 #define WRITERS         50
     43#define READERS  50
     44#define WRITERS  50
    4545
    4646static atomic_t thread_count;
    4747static rwlock_t rwlock;
    4848static atomic_t threads_fault;
    49 static bool sh_quiet;
    5049
    5150SPINLOCK_INITIALIZE(rw_lock);
     
    5857{
    5958        uint32_t rc;
    60 
    61         spinlock_lock(&rw_lock);       
     59       
     60        spinlock_lock(&rw_lock);
    6261        rc = seed % max;
    6362        seed = (((seed << 2) ^ (seed >> 2)) * 487) + rc;
     
    7170        thread_detach(THREAD);
    7271        waitq_sleep(&can_start);
    73 
     72       
    7473        to = random(40000);
    7574       
    76         if (!sh_quiet)
    77                 printf("cpu%u, tid %" PRIu64 " w+ (%d)\n", CPU->id, THREAD->tid, to);
     75        TPRINTF("cpu%u, tid %" PRIu64 " w+ (%d)\n", CPU->id, THREAD->tid, to);
    7876       
    7977        rc = rwlock_write_lock_timeout(&rwlock, to);
    8078        if (SYNCH_FAILED(rc)) {
    81                 if (!sh_quiet)
    82                         printf("cpu%u, tid %" PRIu64 " w!\n", CPU->id, THREAD->tid);
     79                TPRINTF("cpu%u, tid %" PRIu64 " w!\n", CPU->id, THREAD->tid);
    8380                atomic_dec(&thread_count);
    8481                return;
    8582        }
    8683       
    87         if (!sh_quiet)
    88                 printf("cpu%u, tid %" PRIu64 " w=\n", CPU->id, THREAD->tid);
    89 
     84        TPRINTF("cpu%u, tid %" PRIu64 " w=\n", CPU->id, THREAD->tid);
     85       
    9086        if (rwlock.readers_in) {
    91                 if (!sh_quiet)
    92                         printf("Oops.");
     87                TPRINTF("Oops.\n");
    9388                atomic_inc(&threads_fault);
    9489                atomic_dec(&thread_count);
    9590                return;
    9691        }
     92       
    9793        thread_usleep(random(1000000));
     94       
    9895        if (rwlock.readers_in) {
    99                 if (!sh_quiet)
    100                         printf("Oops.");       
     96                TPRINTF("Oops.\n");
    10197                atomic_inc(&threads_fault);
    10298                atomic_dec(&thread_count);
    10399                return;
    104100        }
    105 
     101       
    106102        rwlock_write_unlock(&rwlock);
    107103       
    108         if (!sh_quiet)
    109                 printf("cpu%u, tid %" PRIu64 " w-\n", CPU->id, THREAD->tid);
     104        TPRINTF("cpu%u, tid %" PRIu64 " w-\n", CPU->id, THREAD->tid);
    110105        atomic_dec(&thread_count);
    111106}
     
    119114        to = random(2000);
    120115       
    121         if (!sh_quiet)
    122                 printf("cpu%u, tid %" PRIu64 " r+ (%d)\n", CPU->id, THREAD->tid, to);
     116        TPRINTF("cpu%u, tid %" PRIu64 " r+ (%d)\n", CPU->id, THREAD->tid, to);
    123117       
    124118        rc = rwlock_read_lock_timeout(&rwlock, to);
    125119        if (SYNCH_FAILED(rc)) {
    126                 if (!sh_quiet)
    127                         printf("cpu%u, tid %" PRIu64 " r!\n", CPU->id, THREAD->tid);
     120                TPRINTF("cpu%u, tid %" PRIu64 " r!\n", CPU->id, THREAD->tid);
    128121                atomic_dec(&thread_count);
    129122                return;
    130123        }
    131124       
    132         if (!sh_quiet)
    133                 printf("cpu%u, tid %" PRIu64 " r=\n", CPU->id, THREAD->tid);
     125        TPRINTF("cpu%u, tid %" PRIu64 " r=\n", CPU->id, THREAD->tid);
    134126       
    135127        thread_usleep(30000);
    136128        rwlock_read_unlock(&rwlock);
    137129       
    138         if (!sh_quiet)
    139                 printf("cpu%u, tid %" PRIu64 " r-\n", CPU->id, THREAD->tid);
     130        TPRINTF("cpu%u, tid %" PRIu64 " r-\n", CPU->id, THREAD->tid);
    140131        atomic_dec(&thread_count);
    141132}
    142133
    143 char * test_rwlock4(bool quiet)
     134char *test_rwlock4(void)
    144135{
    145136        context_t ctx;
    146137        uint32_t i;
    147         sh_quiet = quiet;
    148138       
    149139        waitq_initialize(&can_start);
     
    159149       
    160150        context_save(&ctx);
    161         if (!quiet) {
    162                 printf("sp=%#x, readers_in=%" PRIc "\n", ctx.sp, rwlock.readers_in);
    163                 printf("Creating %" PRIu32 " readers\n", rd);
    164         }
     151        TPRINTF("sp=%#x, readers_in=%" PRIc "\n", ctx.sp, rwlock.readers_in);
     152        TPRINTF("Creating %" PRIu32 " readers\n", rd);
    165153       
    166154        for (i = 0; i < rd; i++) {
     
    168156                if (thrd)
    169157                        thread_ready(thrd);
    170                 else if (!quiet)
    171                         printf("Could not create reader %" PRIu32 "\n", i);
     158                else
     159                        TPRINTF("Could not create reader %" PRIu32 "\n", i);
    172160        }
    173 
    174         if (!quiet)
    175                 printf("Creating %" PRIu32 " writers\n", wr);
     161       
     162        TPRINTF("Creating %" PRIu32 " writers\n", wr);
    176163       
    177164        for (i = 0; i < wr; i++) {
     
    179166                if (thrd)
    180167                        thread_ready(thrd);
    181                 else if (!quiet)
    182                         printf("Could not create writer %" PRIu32 "\n", i);
     168                else
     169                        TPRINTF("Could not create writer %" PRIu32 "\n", i);
    183170        }
    184171       
     
    187174       
    188175        while (atomic_get(&thread_count) > 0) {
    189                 if (!quiet)
    190                         printf("Threads left: %ld\n", atomic_get(&thread_count));
     176                TPRINTF("Threads left: %ld\n", atomic_get(&thread_count));
    191177                thread_sleep(1);
    192178        }
  • kernel/test/synch/rwlock5.c

    r171f9a1 rcb01e1e  
    3636#include <synch/rwlock.h>
    3737
    38 #define READERS         50
    39 #define WRITERS         50
     38#define READERS  50
     39#define WRITERS  50
    4040
    4141static rwlock_t rwlock;
     
    4848{
    4949        thread_detach(THREAD);
    50 
     50       
    5151        waitq_sleep(&can_start);
    52 
     52       
    5353        rwlock_write_lock(&rwlock);
    5454        atomic_inc(&items_written);
     
    5959{
    6060        thread_detach(THREAD);
    61 
     61       
    6262        waitq_sleep(&can_start);
    6363       
     
    6767}
    6868
    69 char * test_rwlock5(bool quiet)
     69char *test_rwlock5(void)
    7070{
    7171        int i, j, k;
     
    7777        for (i = 1; i <= 3; i++) {
    7878                thread_t *thrd;
    79 
     79               
    8080                atomic_set(&items_read, 0);
    8181                atomic_set(&items_written, 0);
    82 
     82               
    8383                readers = i * READERS;
    8484                writers = (4 - i) * WRITERS;
    85 
    86                 printf("Creating %ld readers and %ld writers...", readers, writers);
     85               
     86                TPRINTF("Creating %ld readers and %ld writers...", readers, writers);
    8787               
    8888                for (j = 0; j < (READERS + WRITERS) / 2; j++) {
     
    9292                                        thread_ready(thrd);
    9393                                else
    94                                         printf("Could not create reader %d\n", k);
     94                                        TPRINTF("Could not create reader %d\n", k);
    9595                        }
    9696                        for (k = 0; k < (4 - i); k++) {
     
    9999                                        thread_ready(thrd);
    100100                                else
    101                                         printf("Could not create writer %d\n", k);
     101                                        TPRINTF("Could not create writer %d\n", k);
    102102                        }
    103103                }
    104 
    105                 printf("ok\n");
    106 
     104               
     105                TPRINTF("ok\n");
     106               
    107107                thread_sleep(1);
    108108                waitq_wakeup(&can_start, WAKEUP_ALL);
    109        
     109               
    110110                while ((items_read.count != readers) || (items_written.count != writers)) {
    111                         printf("%d readers remaining, %d writers remaining, readers_in=%d\n", readers - items_read.count, writers - items_written.count, rwlock.readers_in);
     111                        TPRINTF("%d readers remaining, %d writers remaining, readers_in=%d\n", readers - items_read.count, writers - items_written.count, rwlock.readers_in);
    112112                        thread_usleep(100000);
    113113                }
  • kernel/test/synch/semaphore1.c

    r171f9a1 rcb01e1e  
    3636#include <synch/semaphore.h>
    3737
    38 #define AT_ONCE                 3
    39 #define PRODUCERS               50
    40 #define CONSUMERS               50
     38#define AT_ONCE    3
     39#define PRODUCERS  50
     40#define CONSUMERS  50
    4141
    4242static semaphore_t sem;
     
    4848static void producer(void *arg)
    4949{
    50         thread_detach(THREAD); 
    51 
     50        thread_detach(THREAD);
     51       
    5252        waitq_sleep(&can_start);
    53            
     53       
    5454        semaphore_down(&sem);
    5555        atomic_inc(&items_produced);
     
    6060static void consumer(void *arg)
    6161{
    62         thread_detach(THREAD); 
     62        thread_detach(THREAD);
    6363       
    6464        waitq_sleep(&can_start);
     
    7070}
    7171
    72 char * test_semaphore1(bool quiet)
     72char *test_semaphore1(void)
    7373{
    7474        int i, j, k;
     
    7777        waitq_initialize(&can_start);
    7878        semaphore_initialize(&sem, AT_ONCE);
    79 
     79       
    8080        for (i = 1; i <= 3; i++) {
    8181                thread_t *thrd;
    82 
     82               
    8383                atomic_set(&items_produced, 0);
    8484                atomic_set(&items_consumed, 0);
     
    8787                producers = (4 - i) * PRODUCERS;
    8888               
    89                 printf("Creating %d consumers and %d producers...", consumers, producers);
    90        
     89                TPRINTF("Creating %d consumers and %d producers...", consumers, producers);
     90               
    9191                for (j = 0; j < (CONSUMERS + PRODUCERS) / 2; j++) {
    9292                        for (k = 0; k < i; k++) {
     
    9595                                        thread_ready(thrd);
    9696                                else
    97                                         printf("could not create consumer %d\n", i);
     97                                        TPRINTF("could not create consumer %d\n", i);
    9898                        }
    9999                        for (k = 0; k < (4 - i); k++) {
     
    102102                                        thread_ready(thrd);
    103103                                else
    104                                         printf("could not create producer %d\n", i);
     104                                        TPRINTF("could not create producer %d\n", i);
    105105                        }
    106106                }
    107 
    108                 printf("ok\n");
    109 
     107               
     108                TPRINTF("ok\n");
     109               
    110110                thread_sleep(1);
    111111                waitq_wakeup(&can_start, WAKEUP_ALL);
    112        
     112               
    113113                while ((items_consumed.count != consumers) || (items_produced.count != producers)) {
    114                         printf("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count);
     114                        TPRINTF("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count);
    115115                        thread_sleep(1);
    116116                }
  • kernel/test/synch/semaphore2.c

    r171f9a1 rcb01e1e  
    5151{
    5252        uint32_t rc;
    53 
    54         spinlock_lock(&sem_lock);       
     53       
     54        spinlock_lock(&sem_lock);
    5555        rc = seed % max;
    5656        seed = (((seed << 2) ^ (seed >> 2)) * 487) + rc;
     
    6868       
    6969        to = random(20000);
    70         printf("cpu%u, tid %" PRIu64 " down+ (%d)\n", CPU->id, THREAD->tid, to);
     70        TPRINTF("cpu%u, tid %" PRIu64 " down+ (%d)\n", CPU->id, THREAD->tid, to);
    7171        rc = semaphore_down_timeout(&sem, to);
    7272        if (SYNCH_FAILED(rc)) {
    73                 printf("cpu%u, tid %" PRIu64 " down!\n", CPU->id, THREAD->tid);
     73                TPRINTF("cpu%u, tid %" PRIu64 " down!\n", CPU->id, THREAD->tid);
    7474                return;
    7575        }
    7676       
    77         printf("cpu%u, tid %" PRIu64 " down=\n", CPU->id, THREAD->tid);
     77        TPRINTF("cpu%u, tid %" PRIu64 " down=\n", CPU->id, THREAD->tid);       
    7878        thread_usleep(random(30000));
    7979       
    8080        semaphore_up(&sem);
    81         printf("cpu%u, tid %" PRIu64 " up\n", CPU->id, THREAD->tid);
     81        TPRINTF("cpu%u, tid %" PRIu64 " up\n", CPU->id, THREAD->tid);
    8282}
    8383
    84 char * test_semaphore2(bool quiet)
     84char *test_semaphore2(void)
    8585{
    8686        uint32_t i, k;
     
    9292       
    9393        k = random(7) + 1;
    94         printf("Creating %" PRIu32 " consumers\n", k);
     94        TPRINTF("Creating %" PRIu32 " consumers\n", k);
    9595        for (i = 0; i < k; i++) {
    9696                thrd = thread_create(consumer, NULL, TASK, 0, "consumer", false);
     
    9898                        thread_ready(thrd);
    9999                else
    100                         printf("Error creating thread\n");
     100                        TPRINTF("Error creating thread\n");
    101101        }
    102102       
Note: See TracChangeset for help on using the changeset viewer.