Changeset cb01e1e in mainline for kernel/test/mm/slab1.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/mm/slab1.c

    r171f9a1 rcb01e1e  
    3434#include <memstr.h>
    3535
    36 #define VAL_COUNT   1024
     36#define VAL_COUNT  1024
    3737
    38 static void * data[VAL_COUNT];
     38static void *data[VAL_COUNT];
    3939
    40 static void testit(int size, int count, bool quiet)
     40static void testit(int size, int count)
    4141{
    4242        slab_cache_t *cache;
    4343        int i;
    4444       
    45         if (!quiet)
    46                 printf("Creating cache, object size: %d.\n", size);
     45        TPRINTF("Creating cache, object size: %d.\n", size);
    4746       
    4847        cache = slab_cache_create("test_cache", size, 0, NULL, NULL,
    49                                 SLAB_CACHE_NOMAGAZINE);
     48            SLAB_CACHE_NOMAGAZINE);
    5049       
    51         if (!quiet)
    52                 printf("Allocating %d items...", count);
     50        TPRINTF("Allocating %d items...", count);
    5351       
    5452        for (i = 0; i < count; i++) {
     
    5755        }
    5856       
    59         if (!quiet) {
    60                 printf("done.\n");
    61                 printf("Freeing %d items...", count);
    62         }
     57        TPRINTF("done.\n");
     58       
     59        TPRINTF("Freeing %d items...", count);
    6360       
    6461        for (i = 0; i < count; i++)
    6562                slab_free(cache, data[i]);
    6663       
    67         if (!quiet) {
    68                 printf("done.\n");
    69                 printf("Allocating %d items...", count);
    70         }
     64        TPRINTF("done.\n");
     65       
     66        TPRINTF("Allocating %d items...", count);
    7167       
    7268        for (i = 0; i < count; i++) {
     
    7571        }
    7672       
    77         if (!quiet) {
    78                 printf("done.\n");
    79                 printf("Freeing %d items...", count / 2);
    80         }
     73        TPRINTF("done.\n");
     74       
     75        TPRINTF("Freeing %d items...", count / 2);
    8176       
    8277        for (i = count - 1; i >= count / 2; i--)
    8378                slab_free(cache, data[i]);
    8479       
    85         if (!quiet) {
    86                 printf("done.\n");     
    87                 printf("Allocating %d items...", count / 2);
    88         }
     80        TPRINTF("done.\n");
     81       
     82        TPRINTF("Allocating %d items...", count / 2);
    8983       
    9084        for (i = count / 2; i < count; i++) {
     
    9387        }
    9488       
    95         if (!quiet) {
    96                 printf("done.\n");
    97                 printf("Freeing %d items...", count);
    98         }
     89        TPRINTF("done.\n");
     90       
     91        TPRINTF("Freeing %d items...", count);
    9992       
    10093        for (i = 0; i < count; i++)
    10194                slab_free(cache, data[i]);
    10295       
    103         if (!quiet)
    104                 printf("done.\n");     
     96        TPRINTF("done.\n");
     97       
    10598        slab_cache_destroy(cache);
    10699       
    107         if (!quiet)
    108                 printf("Test complete.\n");
     100        TPRINTF("Test complete.\n");
    109101}
    110102
    111 static void testsimple(bool quiet)
     103static void testsimple(void)
    112104{
    113         testit(100, VAL_COUNT, quiet);
    114         testit(200, VAL_COUNT, quiet);
    115         testit(1024, VAL_COUNT, quiet);
    116         testit(2048, 512, quiet);
    117         testit(4000, 128, quiet);
    118         testit(8192, 128, quiet);
    119         testit(16384, 128, quiet);
    120         testit(16385, 128, quiet);
     105        testit(100, VAL_COUNT);
     106        testit(200, VAL_COUNT);
     107        testit(1024, VAL_COUNT);
     108        testit(2048, 512);
     109        testit(4000, 128);
     110        testit(8192, 128);
     111        testit(16384, 128);
     112        testit(16385, 128);
    121113}
    122114
    123 #define THREADS     6
    124 #define THR_MEM_COUNT   1024
    125 #define THR_MEM_SIZE    128
     115#define THREADS        6
     116#define THR_MEM_COUNT  1024
     117#define THR_MEM_SIZE   128
    126118
    127 static void * thr_data[THREADS][THR_MEM_COUNT];
     119static void *thr_data[THREADS][THR_MEM_COUNT];
    128120static slab_cache_t *thr_cache;
    129121static semaphore_t thr_sem;
    130 static bool sh_quiet;
    131122
    132123static void slabtest(void *data)
     
    137128        thread_detach(THREAD);
    138129       
    139         if (!sh_quiet)
    140                 printf("Starting thread #%" PRIu64 "...\n", THREAD->tid);
     130        TPRINTF("Starting thread #%" PRIu64 "...\n", THREAD->tid);
    141131       
    142132        for (j = 0; j < 10; j++) {
     
    151141        }
    152142       
    153         if (!sh_quiet)
    154                 printf("Thread #%" PRIu64 " finished\n", THREAD->tid);
     143        TPRINTF("Thread #%" PRIu64 " finished\n", THREAD->tid);
    155144       
    156145        semaphore_up(&thr_sem);
    157146}
    158147
    159 static void testthreads(bool quiet)
     148static void testthreads(void)
    160149{
    161150        thread_t *t;
    162151        int i;
    163 
     152       
    164153        thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0, NULL, NULL,
    165                                         SLAB_CACHE_NOMAGAZINE);
     154            SLAB_CACHE_NOMAGAZINE);
     155       
    166156        semaphore_initialize(&thr_sem, 0);
    167157        for (i = 0; i < THREADS; i++) { 
    168158                if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest", false))) {
    169                         if (!quiet)
    170                                 printf("Could not create thread %d\n", i);
     159                        TPRINTF("Could not create thread %d\n", i);
    171160                } else
    172161                        thread_ready(t);
     
    178167        slab_cache_destroy(thr_cache);
    179168       
    180         if (!quiet)
    181                 printf("Test complete.\n");
     169        TPRINTF("Test complete.\n");
    182170}
    183171
    184 char * test_slab1(bool quiet)
     172char *test_slab1(void)
    185173{
    186         sh_quiet = quiet;
    187        
    188         testsimple(quiet);
    189         testthreads(quiet);
     174        testsimple();
     175        testthreads();
    190176       
    191177        return NULL;
Note: See TracChangeset for help on using the changeset viewer.