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


Ignore:
Timestamp:
2009-04-04T00:26:27Z (15 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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        }
Note: See TracChangeset for help on using the changeset viewer.