Changeset deada67 in mainline for kernel/test/synch


Ignore:
Timestamp:
2006-12-19T17:54:50Z (19 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
730376d
Parents:
6536a4a9
Message:

quiet variants of tests

Location:
kernel/test/synch
Files:
4 edited

Legend:

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

    r6536a4a9 rdeada67  
    6060        rwlock_read_unlock(&rwlock);
    6161       
    62        
    6362        rwlock_write_lock(&rwlock);
    6463        rwlock_write_unlock(&rwlock);   
  • kernel/test/synch/rwlock2.c

    r6536a4a9 rdeada67  
    3939
    4040static rwlock_t rwlock;
     41static bool sh_quiet;
    4142
    4243static void writer(void *arg)
    4344{
    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       
    4948        rwlock_write_lock(&rwlock);
    5049        rwlock_write_unlock(&rwlock);
    5150       
    52         printf("Trying to lock rwlock for reading....\n");     
     51        if (!sh_quiet)
     52                printf("Trying to lock rwlock for reading....\n");
     53       
    5354        rwlock_read_lock(&rwlock);
    5455        rwlock_read_unlock(&rwlock);   
    55         printf("Test passed.\n");
    5656}
    5757
     
    5959{
    6060        thread_t *thrd;
     61        sh_quiet = quiet;
    6162       
    6263        rwlock_initialize(&rwlock);
     
    8081        rwlock_read_unlock(&rwlock);
    8182       
     83        thread_join(thrd);
     84        thread_detach(thrd);
     85       
    8286        return NULL;
    8387}
  • kernel/test/synch/rwlock3.c

    r6536a4a9 rdeada67  
    3535#include <synch/rwlock.h>
    3636
    37 #define READERS         50
    38 #define WRITERS         50
     37#define THREADS 4
    3938
     39static atomic_t thread_count;
    4040static rwlock_t rwlock;
     41static bool sh_quiet;
    4142
    4243static void reader(void *arg)
    4344{
    4445        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       
    4750        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        }
    5257
    5358        rwlock_write_lock(&rwlock);
    5459        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);
    5665}
    5766
     
    6069        int i;
    6170        thread_t *thrd;
     71        sh_quiet = quiet;
     72       
     73        atomic_set(&thread_count, THREADS);
    6274       
    6375        rwlock_initialize(&rwlock);
    6476        rwlock_write_lock(&rwlock);
    6577       
    66         for (i = 0; i < 4; i++) {
     78        for (i = 0; i < THREADS; i++) {
    6779                thrd = thread_create(reader, NULL, TASK, 0, "reader", false);
    6880                if (thrd)
    6981                        thread_ready(thrd);
    70                 else
     82                else if (!quiet)
    7183                        printf("Could not create reader %d\n", i);
    7284        }
    7385
    7486        thread_sleep(1);
     87        rwlock_write_unlock(&rwlock);
    7588       
    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        }
    7794       
    7895        return NULL;
  • kernel/test/synch/rwlock4.c

    r6536a4a9 rdeada67  
    4444#define WRITERS         50
    4545
     46static atomic_t thread_count;
    4647static rwlock_t rwlock;
    4748static atomic_t threads_fault;
     49static bool sh_quiet;
    4850
    4951SPINLOCK_INITIALIZE(rw_lock);
     
    7173
    7274        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       
    7479        rc = rwlock_write_lock_timeout(&rwlock, to);
    7580        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);
    7784                return;
    7885        }
    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);
    8089
    8190        if (rwlock.readers_in) {
    82                 printf("Oops.");
     91                if (!sh_quiet)
     92                        printf("Oops.");
    8393                atomic_inc(&threads_fault);
     94                atomic_dec(&thread_count);
    8495                return;
    8596        }
    8697        thread_usleep(random(1000000));
    8798        if (rwlock.readers_in) {
    88                 printf("Oops.");       
     99                if (!sh_quiet)
     100                        printf("Oops.");       
    89101                atomic_inc(&threads_fault);
     102                atomic_dec(&thread_count);
    90103                return;
    91104        }
    92105
    93106        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);
    95111}
    96112
     
    102118       
    103119        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       
    105124        rc = rwlock_read_lock_timeout(&rwlock, to);
    106125        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);
    108129                return;
    109130        }
    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       
    111135        thread_usleep(30000);
    112136        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);
    114141}
    115142
     
    117144{
    118145        context_t ctx;
    119         uint32_t i, k;
     146        uint32_t i;
     147        sh_quiet = quiet;
    120148       
    121149        waitq_initialize(&can_start);
     
    123151        atomic_set(&threads_fault, 0);
    124152       
     153        uint32_t rd = random(7) + 1;
     154        uint32_t wr = random(5) + 1;
     155       
     156        atomic_set(&thread_count, rd + wr);
     157       
    125158        thread_t *thrd;
    126159       
    127160        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        }
    129165       
    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++) {
    133167                thrd = thread_create(reader, NULL, TASK, 0, "reader", false);
    134168                if (thrd)
    135169                        thread_ready(thrd);
    136                 else
     170                else if (!quiet)
    137171                        printf("Could not create reader %d\n", i);
    138172        }
    139173
    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++) {
    143178                thrd = thread_create(writer, NULL, TASK, 0, "writer", false);
    144179                if (thrd)
    145180                        thread_ready(thrd);
    146                 else
     181                else if (!quiet)
    147182                        printf("Could not create writer %d\n", i);
    148183        }
     
    151186        waitq_wakeup(&can_start, WAKEUP_ALL);
    152187       
     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       
    153194        if (atomic_get(&threads_fault) == 0)
    154195                return NULL;
Note: See TracChangeset for help on using the changeset viewer.