Changeset cb01e1e in mainline for kernel/test/mm/slab2.c


Ignore:
Timestamp:
2009-04-04T00:26:27Z (16 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/mm/slab2.c

    r171f9a1 rcb01e1e  
    3737#include <synch/mutex.h>
    3838
    39 #define ITEM_SIZE 256
     39#define ITEM_SIZE  256
    4040
    4141/** Fill memory with 2 caches, when allocation fails,
     
    4343 *  now allocation should clean magazines and allow for full allocation.
    4444 */
    45 static void totalmemtest(bool quiet)
     45static void totalmemtest(void)
    4646{
    4747        slab_cache_t *cache1;
    4848        slab_cache_t *cache2;
    4949        int i;
    50 
     50       
    5151        void *data1, *data2;
    5252        void *olddata1 = NULL, *olddata2 = NULL;
     
    5555        cache2 = slab_cache_create("cache2_tst", ITEM_SIZE, 0, NULL, NULL, 0);
    5656       
    57         if (!quiet)
    58                 printf("Allocating...");
     57        TPRINTF("Allocating...");
    5958       
    6059        /* Use atomic alloc, so that we find end of memory */
     
    7574                olddata1 = data1;
    7675                olddata2 = data2;
    77         } while (1);
    78        
    79         if (!quiet) {
    80                 printf("done.\n");
    81                 printf("Deallocating cache2...");
    82         }
     76        } while (true);
     77       
     78        TPRINTF("done.\n");
     79       
     80        TPRINTF("Deallocating cache2...");
    8381       
    8482        /* We do not have memory - now deallocate cache2 */
     
    8987        }
    9088       
    91         if (!quiet) {
    92                 printf("done.\n");
    93                 printf("Allocating to cache1...\n");
    94         }
     89        TPRINTF("done.\n");
     90       
     91        TPRINTF("Allocating to cache1...\n");
    9592       
    9693        for (i = 0; i < 30; i++) {
    9794                data1 = slab_alloc(cache1, FRAME_ATOMIC);
    9895                if (!data1) {
    99                         if (!quiet)
    100                                 printf("Incorrect memory size - use another test.");
     96                        TPRINTF("Incorrect memory size - use another test.");
    10197                        return;
    10298                }
     
    105101                olddata1 = data1;
    106102        }
    107         while (1) {
     103        while (true) {
    108104                data1 = slab_alloc(cache1, FRAME_ATOMIC);
    109105                if (!data1)
     
    114110        }
    115111       
    116         if (!quiet)
    117                 printf("Deallocating cache1...");
     112        TPRINTF("Deallocating cache1...");
    118113       
    119114        while (olddata1) {
     
    123118        }
    124119       
    125         if (!quiet) {
    126                 printf("done.\n");
    127                 slab_print_list();
    128         }
     120        TPRINTF("done.\n");
     121       
     122        slab_print_list();
    129123       
    130124        slab_cache_destroy(cache1);
     
    136130static condvar_t thread_starter;
    137131static mutex_t starter_mutex;
    138 static bool sh_quiet;
    139 
    140 #define THREADS 8
     132
     133#define THREADS  8
    141134
    142135static void slabtest(void *priv)
     
    150143        mutex_unlock(&starter_mutex);
    151144       
    152         if (!sh_quiet)
    153                 printf("Starting thread #%" PRIu64 "...\n", THREAD->tid);
     145        TPRINTF("Starting thread #%" PRIu64 "...\n", THREAD->tid);
    154146
    155147        /* Alloc all */
    156         if (!sh_quiet)
    157                 printf("Thread #%" PRIu64 " allocating...\n", THREAD->tid);
    158        
    159         while (1) {
     148        TPRINTF("Thread #%" PRIu64 " allocating...\n", THREAD->tid);
     149       
     150        while (true) {
    160151                /* Call with atomic to detect end of memory */
    161152                new = slab_alloc(thr_cache, FRAME_ATOMIC);
     
    166157        }
    167158       
    168         if (!sh_quiet)
    169                 printf("Thread #%" PRIu64 " releasing...\n", THREAD->tid);
     159        TPRINTF("Thread #%" PRIu64 " releasing...\n", THREAD->tid);
    170160       
    171161        while (data) {
     
    176166        }
    177167       
    178         if (!sh_quiet)
    179                 printf("Thread #%" PRIu64 " allocating...\n", THREAD->tid);
    180        
    181         while (1) {
     168        TPRINTF("Thread #%" PRIu64 " allocating...\n", THREAD->tid);
     169       
     170        while (true) {
    182171                /* Call with atomic to detect end of memory */
    183172                new = slab_alloc(thr_cache, FRAME_ATOMIC);
     
    188177        }
    189178       
    190         if (!sh_quiet)
    191                 printf("Thread #%" PRIu64 " releasing...\n", THREAD->tid);
     179        TPRINTF("Thread #%" PRIu64 " releasing...\n", THREAD->tid);
    192180       
    193181        while (data) {
     
    198186        }
    199187       
    200         if (!sh_quiet)
    201                 printf("Thread #%" PRIu64 " finished\n", THREAD->tid);
     188        TPRINTF("Thread #%" PRIu64 " finished\n", THREAD->tid);
    202189       
    203190        slab_print_list();
     
    205192}
    206193
    207 static void multitest(int size, bool quiet)
     194static void multitest(int size)
    208195{
    209196        /* Start 8 threads that just allocate as much as possible,
     
    213200        int i;
    214201       
    215         if (!quiet)
    216                 printf("Running stress test with size %d\n", size);
     202        TPRINTF("Running stress test with size %d\n", size);
    217203       
    218204        condvar_initialize(&thread_starter);
    219205        mutex_initialize(&starter_mutex, MUTEX_PASSIVE);
    220 
     206       
    221207        thr_cache = slab_cache_create("thread_cache", size, 0, NULL, NULL, 0);
    222208        semaphore_initialize(&thr_sem,0);
    223209        for (i = 0; i < THREADS; i++) { 
    224210                if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false))) {
    225                         if (!quiet)
    226                                 printf("Could not create thread %d\n", i);
     211                        TPRINTF("Could not create thread %d\n", i);
    227212                } else
    228213                        thread_ready(t);
     
    230215        thread_sleep(1);
    231216        condvar_broadcast(&thread_starter);
    232 
     217       
    233218        for (i = 0; i < THREADS; i++)
    234219                semaphore_down(&thr_sem);
    235220       
    236221        slab_cache_destroy(thr_cache);
    237         if (!quiet)
    238                 printf("Stress test complete.\n");
    239 }
    240 
    241 char * test_slab2(bool quiet)
    242 {
    243         sh_quiet = quiet;
    244        
    245         if (!quiet)
    246                 printf("Running reclaim single-thread test .. pass 1\n");
    247         totalmemtest(quiet);
    248         if (!quiet)
    249                 printf("Running reclaim single-thread test .. pass 2\n");
    250         totalmemtest(quiet);
    251         if (!quiet)
    252                 printf("Reclaim test OK.\n");
    253        
    254         multitest(128, quiet);
    255         multitest(2048, quiet);
    256         multitest(8192, quiet);
     222        TPRINTF("Stress test complete.\n");
     223}
     224
     225char *test_slab2(void)
     226{
     227        TPRINTF("Running reclaim single-thread test .. pass 1\n");
     228        totalmemtest();
     229       
     230        TPRINTF("Running reclaim single-thread test .. pass 2\n");
     231        totalmemtest();
     232       
     233        TPRINTF("Reclaim test OK.\n");
     234       
     235        multitest(128);
     236        multitest(2048);
     237        multitest(8192);
    257238       
    258239        return NULL;
Note: See TracChangeset for help on using the changeset viewer.