Changeset deada67 in mainline for kernel/test/synch/rwlock4.c


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.