Changeset 96348adc in mainline for kernel/test/mm


Ignore:
Timestamp:
2006-12-12T17:24:58Z (19 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7e13972
Parents:
34db7fa
Message:

cleanup tests

Location:
kernel/test/mm
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • kernel/test/mm/falloc1.c

    r34db7fa r96348adc  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829#include <print.h>
    2930#include <test.h>
     
    3637#include <align.h>
    3738
    38 #ifdef CONFIG_BENCH
    39 #include <arch/cycle.h>
    40 #endif
    41 
    4239#define MAX_FRAMES 1024
    4340#define MAX_ORDER 8
    4441#define TEST_RUNS 2
    4542
    46 void test_falloc1(void) {
    47 #ifdef CONFIG_BENCH
    48         uint64_t t0 = get_cycle();
    49 #endif
    50         uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES*sizeof(uintptr_t), 0);
    51         int results[MAX_ORDER+1];
     43char * test_falloc1(void) {
     44        uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), 0);
     45        int results[MAX_ORDER + 1];
    5246       
    5347        int i, order, run;
     
    5549
    5650        ASSERT(TEST_RUNS > 1);
    57         ASSERT(frames != NULL)
     51        if (frames == NULL)
     52                return "Unable to allocate frames";
    5853
    5954        for (run = 0; run < TEST_RUNS; run++) {
     
    6560                               
    6661                                if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) != frames[allocated]) {
    67                                         panic("Test failed. Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10);
     62                                        printf("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10);
     63                                        return "Test failed";
    6864                                }
    6965                               
    70                                 if (frames[allocated]) {
     66                                if (frames[allocated])
    7167                                        allocated++;
    72                                 } else {
     68                                else {
    7369                                        printf("done. ");
    7470                                        break;
    7571                                }
    7672                        }
    77                
     73                       
    7874                        printf("%d blocks allocated.\n", allocated);
    7975               
    8076                        if (run) {
    81                                 if (results[order] != allocated) {
    82                                         panic("Test failed. Frame leak possible.\n");
    83                                 }
     77                                if (results[order] != allocated)
     78                                        return "Possible frame leak";
    8479                        } else
    8580                                results[order] = allocated;
    8681                       
    8782                        printf("Deallocating ... ");
    88                         for (i = 0; i < allocated; i++) {
     83                        for (i = 0; i < allocated; i++)
    8984                                frame_free(KA2PA(frames[i]));
    90                         }
    9185                        printf("done.\n");
    9286                }
     
    9589        free(frames);
    9690       
    97         printf("Test passed.\n");
    98 #ifdef CONFIG_BENCH
    99         uint64_t dt = get_cycle() - t0;
    100         printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
    101 #endif
     91        return NULL;
    10292}
    103 
  • kernel/test/mm/falloc1.def

    r34db7fa r96348adc  
     1{
     2        "falloc1",
     3        "Frame allocator test 1",
     4        &test_falloc1,
     5        true
     6},
  • kernel/test/mm/falloc2.c

    r34db7fa r96348adc  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829#include <print.h>
    2930#include <test.h>
     
    3940#include <arch.h>
    4041
    41 #ifdef CONFIG_BENCH
    42 #include <arch/cycle.h>
    43 #endif
    44 
    4542#define MAX_FRAMES 256
    4643#define MAX_ORDER 8
     
    4946#define THREADS 8
    5047
    51 static void falloc(void * arg);
    52 static void failed(void);
     48static atomic_t thread_count;
     49static atomic_t thread_fail;
    5350
    54 static atomic_t thread_count;
    55 
    56 void falloc(void * arg)
     51static void falloc(void * arg)
    5752{
    5853        int order, run, allocated, i;
     
    6156       
    6257        uintptr_t * frames =  (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), FRAME_ATOMIC);
    63         ASSERT(frames != NULL);
     58        if (frames == NULL) {
     59                printf("Thread #%d (cpu%d): Unable to allocate frames\n", THREAD->tid, CPU->id);
     60                atomic_inc(&thread_fail);
     61                atomic_dec(&thread_count);
     62                return;
     63        }
    6464       
    6565        thread_detach(THREAD);
     
    7474                                        memsetb(frames[allocated], FRAME_SIZE << order, val);
    7575                                        allocated++;
    76                                 } else {
     76                                } else
    7777                                        break;
    78                                 }
    7978                        }
    8079                        printf("Thread #%d (cpu%d): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated);
     
    8584                                        if (((uint8_t *) frames[i])[k] != val) {
    8685                                                printf("Thread #%d (cpu%d): Unexpected data (%d) in block %p offset %#zx\n", THREAD->tid, CPU->id, ((char *) frames[i])[k], frames[i], k);
    87                                                 failed();
     86                                                atomic_inc(&thread_fail);
     87                                                goto cleanup;
    8888                                        }
    8989                                }
     
    9393                }
    9494        }
    95        
     95
     96cleanup:       
    9697        free(frames);
    9798        printf("Thread #%d (cpu%d): Exiting\n", THREAD->tid, CPU->id);
     
    99100}
    100101
    101 
    102 void failed(void)
     102char * test_falloc2(void)
    103103{
    104         panic("Test failed.\n");
    105 }
    106 
    107 
    108 void test_falloc2(void)
    109 {
    110 #ifdef CONFIG_BENCH
    111         uint64_t t0 = get_cycle();
    112 #endif
    113         int i;
     104        unsigned int i;
    114105
    115106        atomic_set(&thread_count, THREADS);
     107        atomic_set(&thread_fail, 0);
    116108               
    117109        for (i = 0; i < THREADS; i++) {
    118                 thread_t * thrd;
    119                 thrd = thread_create(falloc, NULL, TASK, 0, "falloc");
    120                 if (thrd)
    121                         thread_ready(thrd);
    122                 else
    123                         failed();
     110                thread_t * thrd = thread_create(falloc, NULL, TASK, 0, "falloc");
     111                if (!thrd) {
     112                        printf("Could not create thread %d\n", i);
     113                        break;
     114                }
     115                thread_ready(thrd);
    124116        }
    125117       
    126         while (thread_count.count)
    127                 ;
    128 
    129         printf("Test passed.\n");
    130 #ifdef CONFIG_BENCH
    131         uint64_t dt = get_cycle() - t0;
    132         printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
    133 #endif
     118        while (atomic_get(&thread_count) > 0) {
     119                printf("Threads left: %d\n", atomic_get(&thread_count));
     120                thread_sleep(1);
     121        }
     122       
     123        if (atomic_get(&thread_fail) == 0)
     124                return NULL;
     125       
     126        return "Test failed";
    134127}
  • kernel/test/mm/falloc2.def

    r34db7fa r96348adc  
     1{
     2        "falloc2",
     3        "Frame allocator test 2",
     4        &test_falloc2,
     5        true
     6},
  • kernel/test/mm/mapping1.c

    r34db7fa r96348adc  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829#include <print.h>
    2930#include <test.h>
     
    3536#include <debug.h>
    3637
    37 #ifdef CONFIG_BENCH
    38 #include <arch/cycle.h>
    39 #endif
    40 
    4138#define PAGE0   0x10000000
    4239#define PAGE1   (PAGE0+PAGE_SIZE)
     
    4542#define VALUE1  0x89abcdef
    4643
    47 void test_mapping1(void)
     44char * test_mapping1(void)
    4845{
    49 #ifdef CONFIG_BENCH
    50         uint64_t t0 = get_cycle();
    51 #endif
    5246        uintptr_t frame0, frame1;
    5347        uint32_t v0, v1;
    54 
    55         printf("Memory management test mapping #1\n");
    5648
    5749        frame0 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA);
     
    8880        ASSERT(v1 == 0);
    8981       
    90         printf("Test passed.\n");
    91 #ifdef CONFIG_BENCH
    92         uint64_t dt = get_cycle() - t0;
    93         printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
    94 #endif 
     82        return NULL;   
    9583}
  • kernel/test/mm/mapping1.def

    r34db7fa r96348adc  
     1{
     2        "mapping1",
     3        "Mapping test",
     4        &test_mapping1,
     5        false
     6},
  • kernel/test/mm/purge1.c

    r34db7fa r96348adc  
    2727 */
    2828
     29#ifdef ia64
     30
    2931#include <print.h>
    3032#include <test.h>
     
    3739#include <debug.h>
    3840
    39 #ifdef ia64
    40 
    4141extern void tlb_invalidate_all(void);
    4242extern void tlb_invalidate_pages(asid_t asid, uintptr_t va, count_t cnt);
    4343
    44 void test(void)
     44char * test(void)
    4545{
    4646        tlb_entry_t entryi;
    4747        tlb_entry_t entryd;
    48 
     48       
    4949        int i;
    5050                                                                                                                                                                                                                                                                                                                                                                       
     
    8181       
    8282        /*tlb_invalidate_all();*/
    83 }
    84 
    85 #else
    86 
    87 void test_purge1(void)
    88 {
    89         printf("This test is availaible only on IA64 platform.\n");
     83       
     84        return NULL;
    9085}
    9186
  • kernel/test/mm/purge1.def

    r34db7fa r96348adc  
     1#ifdef ia64
     2{
     3        "purge1",
     4        "Itanium TLB purge test",
     5        &test_purge1,
     6        true
     7},
     8#endif
  • kernel/test/mm/slab1.c

    r34db7fa r96348adc  
    3535#include <memstr.h>
    3636
    37 #ifdef CONFIG_BENCH
    38 #include <arch/cycle.h>
    39 #endif
    40 
    4137#define VAL_COUNT   1024
    4238
     
    5248                                  SLAB_CACHE_NOMAGAZINE);       
    5349        printf("Allocating %d items...", count);
    54         for (i=0; i < count; i++) {
     50        for (i = 0; i < count; i++) {
    5551                data[i] = slab_alloc(cache, 0);
    56                 memsetb((uintptr_t)data[i], size, 0);
     52                memsetb((uintptr_t) data[i], size, 0);
    5753        }
    5854        printf("done.\n");
    5955        printf("Freeing %d items...", count);
    60         for (i=0; i < count; i++) {
     56        for (i = 0; i < count; i++) {
    6157                slab_free(cache, data[i]);
    6258        }
     
    6460
    6561        printf("Allocating %d items...", count);
    66         for (i=0; i < count; i++) {
     62        for (i = 0; i < count; i++) {
    6763                data[i] = slab_alloc(cache, 0);
    68                 memsetb((uintptr_t)data[i], size, 0);
     64                memsetb((uintptr_t) data[i], size, 0);
    6965        }
    7066        printf("done.\n");
    7167
    72         printf("Freeing %d items...", count/2);
    73         for (i=count-1; i >= count/2; i--) {
     68        printf("Freeing %d items...", count / 2);
     69        for (i = count - 1; i >= count / 2; i--) {
    7470                slab_free(cache, data[i]);
    7571        }
    7672        printf("done.\n");     
    7773
    78         printf("Allocating %d items...", count/2);
    79         for (i=count/2; i < count; i++) {
     74        printf("Allocating %d items...", count / 2);
     75        for (i = count / 2; i < count; i++) {
    8076                data[i] = slab_alloc(cache, 0);
    81                 memsetb((uintptr_t)data[i], size, 0);
     77                memsetb((uintptr_t) data[i], size, 0);
    8278        }
    8379        printf("done.\n");
    8480        printf("Freeing %d items...", count);
    85         for (i=0; i < count; i++) {
     81        for (i = 0; i < count; i++) {
    8682                slab_free(cache, data[i]);
    8783        }
     
    104100}
    105101
    106 
    107102#define THREADS     6
    108103#define THR_MEM_COUNT   1024
    109104#define THR_MEM_SIZE    128
    110105
    111 void * thr_data[THREADS][THR_MEM_COUNT];
    112 slab_cache_t *thr_cache;
    113 semaphore_t thr_sem;
     106static void * thr_data[THREADS][THR_MEM_COUNT];
     107static slab_cache_t *thr_cache;
     108static semaphore_t thr_sem;
    114109
    115110static void slabtest(void *data)
    116111{
    117         int offs = (int)(unative_t) data;
    118         int i,j;
     112        int offs = (int) (unative_t) data;
     113        int i, j;
    119114       
    120115        thread_detach(THREAD);
    121116       
    122117        printf("Starting thread #%d...\n",THREAD->tid);
    123         for (j=0; j<10; j++) {
    124                 for (i=0; i<THR_MEM_COUNT; i++)
     118        for (j = 0; j < 10; j++) {
     119                for (i = 0; i < THR_MEM_COUNT; i++)
    125120                        thr_data[offs][i] = slab_alloc(thr_cache,0);
    126                 for (i=0; i<THR_MEM_COUNT/2; i++)
     121                for (i = 0; i < THR_MEM_COUNT / 2; i++)
    127122                        slab_free(thr_cache, thr_data[offs][i]);
    128                 for (i=0; i< THR_MEM_COUNT/2; i++)
     123                for (i = 0; i < THR_MEM_COUNT / 2; i++)
    129124                        thr_data[offs][i] = slab_alloc(thr_cache, 0);
    130                 for (i=0; i<THR_MEM_COUNT;i++)
     125                for (i = 0; i < THR_MEM_COUNT; i++)
    131126                        slab_free(thr_cache, thr_data[offs][i]);
    132127        }
     
    143138                                      NULL, NULL,
    144139                                      SLAB_CACHE_NOMAGAZINE);
    145         semaphore_initialize(&thr_sem,0);
    146         for (i=0; i<THREADS; i++) { 
    147                 if (!(t = thread_create(slabtest, (void *)(unative_t)i, TASK, 0, "slabtest")))
    148                         panic("could not create thread\n");
    149                 thread_ready(t);
     140        semaphore_initialize(&thr_sem, 0);
     141        for (i = 0; i < THREADS; i++) { 
     142                if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest")))
     143                        printf("Could not create thread %d\n", i);
     144                else
     145                        thread_ready(t);
    150146        }
    151147
    152         for (i=0; i<THREADS; i++)
     148        for (i = 0; i < THREADS; i++)
    153149                semaphore_down(&thr_sem);
    154150       
     
    158154}
    159155
    160 void test_slab1(void)
     156char * test_slab1(void)
    161157{
    162 #ifdef CONFIG_BENCH
    163         uint64_t t0 = get_cycle();
    164 #endif
    165158        testsimple();
    166159        testthreads();
    167 #ifdef CONFIG_BENCH
    168         uint64_t dt = get_cycle() - t0;
    169         printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
    170 #endif
     160       
     161        return NULL;
    171162}
  • kernel/test/mm/slab1.def

    r34db7fa r96348adc  
     1{
     2        "slab1",
     3        "SLAB test 1",
     4        &test_slab1,
     5        true
     6},
  • kernel/test/mm/slab2.c

    r34db7fa r96348adc  
    3838#include <synch/mutex.h>
    3939
    40 #ifdef CONFIG_BENCH
    41 #include <arch/cycle.h>
    42 #endif
    43 
    4440#define ITEM_SIZE 256
    4541
     
    7874                olddata1 = data1;
    7975                olddata2 = data2;
    80         }while(1);
     76        } while(1);
    8177        printf("done.\n");
    8278        /* We do not have memory - now deallocate cache2 */
     
    129125static void slabtest(void *priv)
    130126{
    131         void *data=NULL, *new;
     127        void *data = NULL, *new;
    132128
    133129        thread_detach(THREAD);
     
    173169        }
    174170
    175 
    176171        printf("Thread #%d finished\n", THREAD->tid);
    177172        slab_print_list();
    178173        semaphore_up(&thr_sem);
    179174}
    180 
    181175
    182176static void multitest(int size)
     
    196190                                      0);
    197191        semaphore_initialize(&thr_sem,0);
    198         for (i=0; i<THREADS; i++) { 
     192        for (i = 0; i < THREADS; i++) { 
    199193                if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest")))
    200                         panic("could not create thread\n");
    201                 thread_ready(t);
     194                        printf("Could not create thread %d\n", i);
     195                else
     196                        thread_ready(t);
    202197        }
    203198        thread_sleep(1);
    204199        condvar_broadcast(&thread_starter);
    205200
    206         for (i=0; i<THREADS; i++)
     201        for (i = 0; i < THREADS; i++)
    207202                semaphore_down(&thr_sem);
    208203       
     
    211206}
    212207
    213 void test_slab2(void)
    214 {
    215 #ifdef CONFIG_BENCH
    216         uint64_t t0 = get_cycle();
    217 #endif
    218 
    219         printf("Running reclaim single-thread test .. pass1\n");
     208char * test_slab2(void)
     209{
     210        printf("Running reclaim single-thread test .. pass 1\n");
    220211        totalmemtest();
    221         printf("Running reclaim single-thread test .. pass2\n");
     212        printf("Running reclaim single-thread test .. pass 2\n");
    222213        totalmemtest();
    223214        printf("Reclaim test OK.\n");
     
    227218        multitest(8192);
    228219        printf("All done.\n");
    229 
    230 #ifdef CONFIG_BENCH
    231         uint64_t dt = get_cycle() - t0;
    232         printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
    233 #endif
    234 }
     220       
     221        return NULL;
     222}
  • kernel/test/mm/slab2.def

    r34db7fa r96348adc  
     1{
     2        "slab2",
     3        "SLAB test 2",
     4        &test_slab2,
     5        true
     6},
Note: See TracChangeset for help on using the changeset viewer.