Changeset 14e5d88 in mainline for test/mm/slab1/test.c


Ignore:
Timestamp:
2006-02-02T21:46:47Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4a5b2b0e
Parents:
086d4fd
Message:

Basic SLAB (without CPU-cache) passes test.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/mm/slab1/test.c

    r086d4fd r14e5d88  
    3030#include <mm/slab.h>
    3131#include <print.h>
     32#include <proc/thread.h>
     33#include <arch.h>
     34#include <panic.h>
    3235
    33 #define VAL_SIZE    128
    3436#define VAL_COUNT   1024
    3537
    36 void * data[16384];
     38void * data[VAL_COUNT];
    3739
    38 void test(void)
     40static void testit(int size, int count)
    3941{
    4042        slab_cache_t *cache;
    4143        int i;
    4244       
    43 
    44         printf("Creating cache.\n");
    45         cache = slab_cache_create("test_cache", VAL_SIZE, 0, NULL, NULL, SLAB_CACHE_NOMAGAZINE);
    46         printf("Destroying cache.\n");
    47         slab_cache_destroy(cache);
    48 
    49         printf("Creating cache.\n");
    50         cache = slab_cache_create("test_cache", VAL_SIZE, 0, NULL, NULL,
     45        printf("Creating cache, object size: %d.\n", size);
     46        cache = slab_cache_create("test_cache", size, 0, NULL, NULL,
    5147                                  SLAB_CACHE_NOMAGAZINE);
     48        slab_print_list();
    5249       
    53         printf("Allocating %d items...", VAL_COUNT);
    54         for (i=0; i < VAL_COUNT; i++) {
     50        printf("Allocating %d items...", count);
     51        for (i=0; i < count; i++) {
    5552                data[i] = slab_alloc(cache, 0);
    5653        }
    5754        printf("done.\n");
    58         printf("Freeing %d items...", VAL_COUNT);
    59         for (i=0; i < VAL_COUNT; i++) {
     55        printf("Freeing %d items...", count);
     56        for (i=0; i < count; i++) {
    6057                slab_free(cache, data[i]);
    6158        }
    6259        printf("done.\n");
    6360
    64         printf("Allocating %d items...", VAL_COUNT);
    65         for (i=0; i < VAL_COUNT; i++) {
     61        printf("Allocating %d items...", count);
     62        for (i=0; i < count; i++) {
    6663                data[i] = slab_alloc(cache, 0);
    6764        }
     
    6966
    7067        slab_print_list();
    71         printf("Freeing %d items...", VAL_COUNT/2);
    72         for (i=VAL_COUNT-1; i >= VAL_COUNT/2; i--) {
     68        printf("Freeing %d items...", count/2);
     69        for (i=count-1; i >= count/2; i--) {
    7370                slab_free(cache, data[i]);
    7471        }
    7572        printf("done.\n");     
    7673
    77         printf("Allocating %d items...", VAL_COUNT/2);
    78         for (i=VAL_COUNT/2; i < VAL_COUNT; i++) {
     74        printf("Allocating %d items...", count/2);
     75        for (i=count/2; i < count; i++) {
    7976                data[i] = slab_alloc(cache, 0);
    8077        }
    8178        printf("done.\n");
    82         printf("Freeing %d items...", VAL_COUNT);
    83         for (i=0; i < VAL_COUNT; i++) {
     79        printf("Freeing %d items...", count);
     80        for (i=0; i < count; i++) {
    8481                slab_free(cache, data[i]);
    8582        }
    8683        printf("done.\n");     
    87         slab_print_list();
    8884        slab_cache_destroy(cache);
    8985
    9086        printf("Test complete.\n");
    9187}
     88
     89static void testsimple(void)
     90{
     91        testit(100, VAL_COUNT);
     92        testit(200, VAL_COUNT);
     93        testit(1024, VAL_COUNT);
     94        testit(2048, 512);
     95        testit(4000, 128);
     96        testit(8192, 128);
     97        testit(16384, 128);
     98        testit(16385, 128);
     99}
     100
     101
     102#define THREADS     6
     103#define THR_MEM_COUNT   1024
     104#define THR_MEM_SIZE    128
     105
     106void * thr_data[THREADS][THR_MEM_COUNT];
     107slab_cache_t *thr_cache;
     108semaphore_t thr_sem;
     109
     110static void thread(void *data)
     111{
     112        int offs = (int)(__native) data;
     113        int i,j;
     114
     115        printf("Starting thread #%d...\n",THREAD->tid);
     116        for (j=0; j<10; j++) {
     117                for (i=0; i<THR_MEM_COUNT; i++)
     118                        thr_data[offs][i] = slab_alloc(thr_cache,0);
     119                for (i=0; i<THR_MEM_COUNT/2; i++)
     120                        slab_free(thr_cache, thr_data[offs][i]);
     121                for (i=0; i< THR_MEM_COUNT/2; i++)
     122                        thr_data[offs][i] = slab_alloc(thr_cache, 0);
     123                for (i=0; i<THR_MEM_COUNT;i++)
     124                        slab_free(thr_cache, thr_data[offs][i]);
     125        }
     126        printf("Thread #%d finished\n", THREAD->tid);
     127        slab_print_list();
     128        semaphore_up(&thr_sem);
     129}
     130
     131static void testthreads(void)
     132{
     133        thread_t *t;
     134        int i;
     135
     136        thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0,
     137                                      NULL, NULL,
     138                                      SLAB_CACHE_NOMAGAZINE);
     139        semaphore_initialize(&thr_sem,0);
     140        for (i=0; i<THREADS; i++) { 
     141                if (!(t = thread_create(thread, (void *)(__native)i, TASK, 0)))
     142                        panic("could not create thread\n");
     143                thread_ready(t);
     144        }
     145
     146        for (i=0; i<THREADS; i++)
     147                semaphore_down(&thr_sem);
     148       
     149        slab_cache_destroy(thr_cache);
     150        printf("Test complete.\n");
     151       
     152}
     153
     154void test(void)
     155{
     156        testsimple();
     157        testthreads();
     158}
Note: See TracChangeset for help on using the changeset viewer.