Changeset 96348adc in mainline


Ignore:
Timestamp:
2006-12-12T17:24:58Z (17 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
Files:
34 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},
  • kernel/test/print/print1.c

    r34db7fa r96348adc  
    3131#define BUFFER_SIZE 32
    3232
    33 void test_print1(void)
     33char * test_print1(void)
    3434{
    3535        int retval;
     
    3737       
    3838        char buffer[BUFFER_SIZE];
    39        
    40         printf(" Printf test \n");
    4139       
    4240        printf(" text 10.8s %*.*s \n", 5, 3, "text");
     
    5250        printf("'%#llx' 64bit, '%#x' 32bit, '%#hhx' 8bit, '%#hx' 16bit, unative_t '%#zx'. '%#llx' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, nat, 0x1234567887654321ull, "Lovely string" );
    5351       
    54         printf(" Print to NULL '%s'\n",NULL);
     52        printf(" Print to NULL '%s'\n", NULL);
    5553
    5654        retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters.");
     
    6866        printf("Result is: '%s', retval = %d\n", buffer, retval);
    6967       
    70         return;
     68        return NULL;
    7169}
  • kernel/test/print/print1.def

    r34db7fa r96348adc  
     1{
     2        "print1",
     3        "Printf test",
     4        &test_print1,
     5        true
     6},
  • kernel/test/synch/rwlock1.c

    r34db7fa r96348adc  
    4141static rwlock_t rwlock;
    4242
    43 void test_rwlock1(void)
     43char * test_rwlock1(void)
    4444{
    45         printf("Read/write locks test #1\n");
    46 
    4745        rwlock_initialize(&rwlock);
    4846
     
    7472        rwlock_read_lock(&rwlock);
    7573        rwlock_read_unlock(&rwlock);
    76 
    77         printf("Test passed.\n");
     74       
     75        return NULL;
    7876}
  • kernel/test/synch/rwlock1.def

    r34db7fa r96348adc  
     1{
     2        "rwlock1",
     3        "RW-lock test 1",
     4        &test_rwlock1,
     5        true
     6},
  • kernel/test/synch/rwlock2.c

    r34db7fa r96348adc  
    4040static rwlock_t rwlock;
    4141
    42 static void writer(void *arg);
    43 static void failed(void);
    44 
    4542static void writer(void *arg)
    4643{
     
    5956}
    6057
    61 static void failed()
    62 {
    63         printf("Test failed prematurely.\n");
    64         thread_exit();
    65 }
    66 
    67 void test_rwlock2(void)
     58char * test_rwlock2(void)
    6859{
    6960        thread_t *thrd;
    7061       
    71         printf("Read/write locks test #2\n");
    72    
    7362        rwlock_initialize(&rwlock);
    7463
     
    8271                thread_ready(thrd);
    8372        else
    84                 failed();
    85 
     73                return "Could not create thread";
    8674
    8775        thread_sleep(1);
     
    9078        rwlock_read_unlock(&rwlock);
    9179        rwlock_read_unlock(&rwlock);
    92         rwlock_read_unlock(&rwlock);   
    93 
     80        rwlock_read_unlock(&rwlock);
     81       
     82        return NULL;
    9483}
  • kernel/test/synch/rwlock2.def

    r34db7fa r96348adc  
     1{
     2        "rwlock2",
     3        "RW-lock test 2",
     4        &test_rwlock2,
     5        true
     6},
  • kernel/test/synch/rwlock3.c

    r34db7fa r96348adc  
    4040static rwlock_t rwlock;
    4141
    42 static void reader(void *arg);
    43 static void failed(void);
    44 
    4542static void reader(void *arg)
    4643{
     
    5754        rwlock_write_unlock(&rwlock);
    5855        printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid);                       
    59        
    60         printf("Test passed.\n");       
    61 
    6256}
    6357
    64 static void failed(void)
    65 {
    66         printf("Test failed prematurely.\n");
    67         thread_exit();
    68 }
    69 
    70 void test_rwlock3(void)
     58char * test_rwlock3(void)
    7159{
    7260        int i;
    7361        thread_t *thrd;
    7462       
    75         printf("Read/write locks test #3\n");
    76    
    7763        rwlock_initialize(&rwlock);
    78 
    7964        rwlock_write_lock(&rwlock);
    8065       
    81         for (i=0; i<4; i++) {
     66        for (i = 0; i < 4; i++) {
    8267                thrd = thread_create(reader, NULL, TASK, 0, "reader");
    8368                if (thrd)
    8469                        thread_ready(thrd);
    8570                else
    86                         failed();
     71                        printf("Could not create reader %d\n", i);
    8772        }
    88 
    8973
    9074        thread_sleep(1);
    9175       
    9276        rwlock_write_unlock(&rwlock);
     77       
     78        return NULL;
    9379}
  • kernel/test/synch/rwlock3.def

    r34db7fa r96348adc  
     1{
     2        "rwlock3",
     3        "RW-lock test 3",
     4        &test_rwlock3,
     5        true
     6},
  • kernel/test/synch/rwlock4.c

    r34db7fa r96348adc  
    5353static uint32_t seed = 0xdeadbeef;
    5454
    55 static uint32_t random(uint32_t max);
    56 
    57 static void writer(void *arg);
    58 static void reader(void *arg);
    59 static void failed(void);
    60 
    6155static uint32_t random(uint32_t max)
    6256{
     
    6963        return rc;
    7064}
    71 
    7265
    7366static void writer(void *arg)
     
    8376                printf("cpu%d, tid %d w!\n", CPU->id, THREAD->tid);
    8477                return;
    85         };
     78        }
    8679        printf("cpu%d, tid %d w=\n", CPU->id, THREAD->tid);
    8780
     
    113106}
    114107
    115 static void failed(void)
    116 {
    117         printf("Test failed prematurely.\n");
    118         thread_exit();
    119 }
    120 
    121 void test_rwlock4(void)
     108char * test_rwlock4(void)
    122109{
    123110        context_t ctx;
    124111        uint32_t i, k;
    125112       
    126         printf("Read/write locks test #4\n");
    127    
    128113        waitq_initialize(&can_start);
    129114        rwlock_initialize(&rwlock);
    130115       
    131         for (;;) {
    132                 thread_t *thrd;
    133                
    134                 context_save(&ctx);
    135                 printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in);
    136                
    137                 k = random(7) + 1;
    138                 printf("Creating %d readers\n", k);
    139                 for (i=0; i<k; i++) {
    140                         thrd = thread_create(reader, NULL, TASK, 0, "reader");
    141                         if (thrd)
    142                                 thread_ready(thrd);
    143                         else
    144                                 failed();
    145                 }
     116        thread_t *thrd;
     117       
     118        context_save(&ctx);
     119        printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in);
     120       
     121        k = random(7) + 1;
     122        printf("Creating %d readers\n", k);
     123        for (i = 0; i < k; i++) {
     124                thrd = thread_create(reader, NULL, TASK, 0, "reader");
     125                if (thrd)
     126                        thread_ready(thrd);
     127                else
     128                        printf("Could not create reader %d\n", i);
     129        }
    146130
    147                 k = random(5) + 1;
    148                 printf("Creating %d writers\n", k);
    149                 for (i=0; i<k; i++) {
    150                         thrd = thread_create(writer, NULL, TASK, 0, "writer");
    151                         if (thrd)
    152                                 thread_ready(thrd);
    153                         else
    154                                 failed();
    155                 }
    156                
    157                 thread_usleep(20000);
    158                 waitq_wakeup(&can_start, WAKEUP_ALL);
    159         }               
    160 
     131        k = random(5) + 1;
     132        printf("Creating %d writers\n", k);
     133        for (i=0; i<k; i++) {
     134                thrd = thread_create(writer, NULL, TASK, 0, "writer");
     135                if (thrd)
     136                        thread_ready(thrd);
     137                else
     138                        printf("Could not create writer %d\n", i);
     139        }
     140       
     141        thread_usleep(20000);
     142        waitq_wakeup(&can_start, WAKEUP_ALL);
     143       
     144        return NULL;
    161145}
  • kernel/test/synch/rwlock4.def

    r34db7fa r96348adc  
     1{
     2        "rwlock4",
     3        "RW-lock test 4",
     4        &test_rwlock4,
     5        true
     6},
  • kernel/test/synch/rwlock5.c

    r34db7fa r96348adc  
    4545static atomic_t items_written;
    4646
    47 static void writer(void *arg);
    48 static void reader(void *arg);
    49 static void failed(void);
    50 
    51 void writer(void *arg)
     47static void writer(void *arg)
    5248{
    5349        thread_detach(THREAD);
     
    6056}
    6157
    62 void reader(void *arg)
     58static void reader(void *arg)
    6359{
    6460        thread_detach(THREAD);
     
    7167}
    7268
    73 void failed(void)
    74 {
    75         printf("Test failed prematurely.\n");
    76         thread_exit();
    77 }
    78 
    79 void test_rwlock5(void)
     69char * test_rwlock5(void)
    8070{
    8171        int i, j, k;
    8272        count_t readers, writers;
    8373       
    84         printf("Read/write locks test #5\n");
    85    
    8674        waitq_initialize(&can_start);
    8775        rwlock_initialize(&rwlock);
    8876       
    89         for (i=1; i<=3; i++) {
     77        for (i = 1; i <= 3; i++) {
    9078                thread_t *thrd;
    9179
     
    9381                atomic_set(&items_written, 0);
    9482
    95                 readers = i*READERS;
    96                 writers = (4-i)*WRITERS;
     83                readers = i * READERS;
     84                writers = (4 - i) * WRITERS;
    9785
    9886                printf("Creating %ld readers and %ld writers...", readers, writers);
    9987               
    100                 for (j=0; j<(READERS+WRITERS)/2; j++) {
    101                         for (k=0; k<i; k++) {
     88                for (j = 0; j < (READERS + WRITERS) / 2; j++) {
     89                        for (k = 0; k < i; k++) {
    10290                                thrd = thread_create(reader, NULL, TASK, 0, "reader");
    10391                                if (thrd)
    10492                                        thread_ready(thrd);
    10593                                else
    106                                         failed();
     94                                        printf("Could not create reader %d\n", k);
    10795                        }
    108                         for (k=0; k<(4-i); k++) {
     96                        for (k = 0; k < (4 - i); k++) {
    10997                                thrd = thread_create(writer, NULL, TASK, 0, "writer");
    11098                                if (thrd)
    11199                                        thread_ready(thrd);
    112100                                else
    113                                         failed();
     101                                        printf("Could not create writer %d\n", k);
    114102                        }
    115103                }
     
    120108                waitq_wakeup(&can_start, WAKEUP_ALL);
    121109       
    122                 while (items_read.count != readers || items_written.count != writers) {
     110                while ((items_read.count != readers) || (items_written.count != writers)) {
    123111                        printf("%zd readers remaining, %zd writers remaining, readers_in=%zd\n", readers - items_read.count, writers - items_written.count, rwlock.readers_in);
    124112                        thread_usleep(100000);
    125113                }
    126114        }
    127         printf("Test passed.\n");
     115       
     116        return NULL;
    128117}
  • kernel/test/synch/rwlock5.def

    r34db7fa r96348adc  
     1{
     2        "rwlock5",
     3        "RW-lock test 5",
     4        &test_rwlock5,
     5        true
     6},
  • kernel/test/synch/semaphore1.c

    r34db7fa r96348adc  
    4646static atomic_t items_consumed;
    4747
    48 static void consumer(void *arg);
    49 static void producer(void *arg);
    50 static void failed(void);
    51 
    5248static void producer(void *arg)
    5349{
     
    7470}
    7571
    76 static void failed(void)
    77 {
    78         printf("Test failed prematurely.\n");
    79         thread_exit();
    80 }
    81 
    82 void test_semaphore1(void)
     72char * test_semaphore1(void)
    8373{
    8474        int i, j, k;
    8575        int consumers, producers;
    8676       
    87         printf("Semaphore test #1\n");
    88    
    8977        waitq_initialize(&can_start);
    9078        semaphore_initialize(&sem, AT_ONCE);
    9179
    92 
    93         for (i=1; i<=3; i++) {
     80        for (i = 1; i <= 3; i++) {
    9481                thread_t *thrd;
    9582
     
    9885               
    9986                consumers = i * CONSUMERS;
    100                 producers = (4-i) * PRODUCERS;
     87                producers = (4 - i) * PRODUCERS;
    10188               
    10289                printf("Creating %d consumers and %d producers...", consumers, producers);
    10390       
    104                 for (j=0; j<(CONSUMERS+PRODUCERS)/2; j++) {
    105                         for (k=0; k<i; k++) {
     91                for (j = 0; j < (CONSUMERS + PRODUCERS) / 2; j++) {
     92                        for (k = 0; k < i; k++) {
    10693                                thrd = thread_create(consumer, NULL, TASK, 0, "consumer");
    10794                                if (thrd)
    10895                                        thread_ready(thrd);
    10996                                else
    110                                         failed();
     97                                        printf("could not create consumer %d\n", i);
    11198                        }
    112                         for (k=0; k<(4-i); k++) {
     99                        for (k = 0; k < (4 - i); k++) {
    113100                                thrd = thread_create(producer, NULL, TASK, 0, "producer");
    114101                                if (thrd)
    115102                                        thread_ready(thrd);
    116103                                else
    117                                         failed();
     104                                        printf("could not create producer %d\n", i);
    118105                        }
    119106                }
     
    124111                waitq_wakeup(&can_start, WAKEUP_ALL);
    125112       
    126                 while (items_consumed.count != consumers || items_produced.count != producers) {
     113                while ((items_consumed.count != consumers) || (items_produced.count != producers)) {
    127114                        printf("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count);
    128115                        thread_sleep(1);
    129116                }
    130117        }
    131         printf("Test passed.\n");
     118       
     119        return NULL;
    132120}
  • kernel/test/synch/semaphore1.def

    r34db7fa r96348adc  
     1{
     2        "semaphore1",
     3        "Semaphore test 1",
     4        &test_semaphore1,
     5        true
     6},
  • kernel/test/synch/semaphore2.c

    r34db7fa r96348adc  
    4848static uint32_t seed = 0xdeadbeef;
    4949
    50 static uint32_t random(uint32_t max);
    51 
    52 static void consumer(void *arg);
    53 static void failed(void);
    54 
    5550static uint32_t random(uint32_t max)
    5651{
     
    6358        return rc;
    6459}
    65 
    6660
    6761static void consumer(void *arg)
     
    8882}
    8983
    90 static void failed(void)
    91 {
    92         printf("Test failed prematurely.\n");
    93         thread_exit();
    94 }
    95 
    96 void test_semaphore2(void)
     84char * test_semaphore2(void)
    9785{
    9886        uint32_t i, k;
    9987       
    100         printf("Semaphore test #2\n");
    101    
    10288        waitq_initialize(&can_start);
    10389        semaphore_initialize(&sem, 5);
    10490       
    105 
     91        thread_t *thrd;
    10692       
    107         for (; ;) {
    108                 thread_t *thrd;
    109                
    110                 k = random(7) + 1;
    111                 printf("Creating %d consumers\n", k);
    112                 for (i=0; i<k; i++) {
    113                         thrd = thread_create(consumer, NULL, TASK, 0, "consumer");
    114                         if (thrd)
    115                                 thread_ready(thrd);
    116                         else
    117                                 failed();
    118                 }
    119                
    120                 thread_usleep(20000);
    121                 waitq_wakeup(&can_start, WAKEUP_ALL);
    122         }               
    123 
     93        k = random(7) + 1;
     94        printf("Creating %d consumers\n", k);
     95        for (i = 0; i < k; i++) {
     96                thrd = thread_create(consumer, NULL, TASK, 0, "consumer");
     97                if (thrd)
     98                        thread_ready(thrd);
     99                else
     100                        printf("Error creating thread\n");
     101        }
     102       
     103        thread_usleep(20000);
     104        waitq_wakeup(&can_start, WAKEUP_ALL);
     105       
     106        return NULL;
    124107}
  • kernel/test/synch/semaphore2.def

    r34db7fa r96348adc  
     1{
     2        "semaphore2",
     3        "Semaphore test 2",
     4        &test_semaphore2,
     5        true
     6},
  • kernel/test/sysinfo/sysinfo1.c

    r34db7fa r96348adc  
    3333#include <test.h>
    3434#include <sysinfo/sysinfo.h>
    35 /*
    36 static unative_t counter(sysinfo_item_t *root)
     35
     36char * test_sysinfo1(void)
    3737{
    38         static unative_t i=0;
    39         return i++;
    40 }*/
    41 
    42 void test_sysinfo1(void)
    43 {
    44 /*      sysinfo_set_item_val("Ahoj.lidi.uaaaa",NULL,9);
    45         sysinfo_set_item_val("Ahoj.lidi.ubbbb",NULL,15);
    46         sysinfo_set_item_val("Ahoj.lidi",NULL,64);
    47         sysinfo_set_item_function("Ahoj",NULL,counter);
    48         sysinfo_dump(NULL,0);
    49         sysinfo_set_item_val("Ahoj.lidi.ubbbb",NULL,75);
    50         sysinfo_dump(NULL,0);
    51         sysinfo_dump(NULL,0);
    52         sysinfo_dump(NULL,0);*/
    53         sysinfo_dump(NULL,0);
     38        sysinfo_dump(NULL, 0);
     39        return NULL;
    5440}
  • kernel/test/sysinfo/sysinfo1.def

    r34db7fa r96348adc  
     1{
     2        "sysinfo1",
     3        "Sysinfo test",
     4        &test_sysinfo1,
     5        true
     6},
  • kernel/test/test.c

    r34db7fa r96348adc  
    4343#include <fpu/sse1.def>
    4444#include <fpu/mips2.def>
    45         /*
    46         {
    47                 "falloc1",
    48                 "Frame allocator test 1",
    49                 &test_falloc1,
    50                 true
    51         },
    52         {
    53                 "falloc2",
    54                 "Frame allocator test 2",
    55                 &test_falloc2,
    56                 true
    57         },
    58         {
    59                 "mapping1",
    60                 "Mapping test",
    61                 &test_mapping1,
    62                 true
    63         },
    64         {
    65                 "slab1",
    66                 "SLAB test 1",
    67                 &test_slab1,
    68                 true
    69         },
    70         {
    71                 "slab2",
    72                 "SLAB test 2",
    73                 &test_slab2,
    74                 true
    75         },
    76         {
    77                 "purge1",
    78                 "Itanium TLB purge test",
    79                 &test_purge1,
    80                 true
    81         },
    82         {
    83                 "rwlock1",
    84                 "RW-lock test 1",
    85                 &test_rwlock1,
    86                 true
    87         },
    88         {
    89                 "rwlock2",
    90                 "RW-lock test 2",
    91                 &test_rwlock2,
    92                 true
    93         },
    94         {
    95                 "rwlock3",
    96                 "RW-lock test 3",
    97                 &test_rwlock3,
    98                 true
    99         },
    100         {
    101                 "rwlock4",
    102                 "RW-lock test 4",
    103                 &test_rwlock4,
    104                 true
    105         },
    106         {
    107                 "rwlock5",
    108                 "RW-lock test 5",
    109                 &test_rwlock5,
    110                 true
    111         },
    112         {
    113                 "semaphore1",
    114                 "Semaphore test 1",
    115                 &test_semaphore1,
    116                 true
    117         },
    118         {
    119                 "semaphore2",
    120                 "Semaphore test 2",
    121                 &test_semaphore2,
    122                 true
    123         },
    124         {
    125                 "print1",
    126                 "Printf test",
    127                 &test_print1,
    128                 true
    129         },
    130         {
    131                 "thread1",
    132                 "Thread test",
    133                 &test_thread1,
    134                 true
    135         },
    136         {
    137                 "sysinfo1",
    138                 "Sysinfo test",
    139                 &test_sysinfo1,
    140                 true
    141         },*/
     45#include <mm/falloc1.def>
     46#include <mm/falloc2.def>
     47#include <mm/mapping1.def>
     48#include <mm/slab1.def>
     49#include <mm/slab2.def>
     50#include <synch/rwlock1.def>
     51#include <synch/rwlock2.def>
     52#include <synch/rwlock3.def>
     53#include <synch/rwlock4.def>
     54#include <synch/rwlock5.def>
     55#include <synch/semaphore1.def>
     56#include <synch/semaphore2.def>
     57#include <print/print1.def>
     58#include <thread/thread1.def>
     59#include <sysinfo/sysinfo1.def>
    14260        {NULL, NULL, NULL}
    14361};
  • kernel/test/test.h

    r34db7fa r96348adc  
    5555extern char * test_sse1(void);
    5656extern char * test_mips2(void);
    57 extern void test_falloc1(void);
    58 extern void test_falloc2(void);
    59 extern void test_mapping1(void);
    60 extern void test_purge1(void);
    61 extern void test_slab1(void);
    62 extern void test_slab2(void);
    63 extern void test_rwlock1(void);
    64 extern void test_rwlock2(void);
    65 extern void test_rwlock3(void);
    66 extern void test_rwlock4(void);
    67 extern void test_rwlock5(void);
    68 extern void test_semaphore1(void);
    69 extern void test_semaphore2(void);
    70 extern void test_print1(void);
    71 extern void test_thread1(void);
    72 extern void test_sysinfo1(void);
     57extern char * test_falloc1(void);
     58extern char * test_falloc2(void);
     59extern char * test_mapping1(void);
     60extern char * test_purge1(void);
     61extern char * test_slab1(void);
     62extern char * test_slab2(void);
     63extern char * test_rwlock1(void);
     64extern char * test_rwlock2(void);
     65extern char * test_rwlock3(void);
     66extern char * test_rwlock4(void);
     67extern char * test_rwlock5(void);
     68extern char * test_semaphore1(void);
     69extern char * test_semaphore2(void);
     70extern char * test_print1(void);
     71extern char * test_thread1(void);
     72extern char * test_sysinfo1(void);
    7373
    7474extern test_t tests[];
  • kernel/test/thread/thread1.c

    r34db7fa r96348adc  
    4040#define THREADS 5
    4141
     42static atomic_t finish;
     43static atomic_t threads_finished;
     44
    4245static void threadtest(void *data)
    4346{
    44 
    4547        thread_detach(THREAD); 
    4648
    47         while (1)
    48                 printf("%d\n",(int)(THREAD->tid));
     49        while (atomic_get(&finish)) {
     50                printf("%d\n", (int) (THREAD->tid));
     51                thread_usleep(100);
     52        }
     53        atomic_inc(&threads_finished);
    4954}
    5055
    51 void test_thread1(void)
     56char * test_thread1(void)
    5257{
    53         thread_t *t;
    54         int i;
     58        unsigned int i, total = 0;
     59       
     60        atomic_set(&finish, 1);
     61        atomic_set(&threads_finished, 0);
    5562
    56         for (i=0; i<THREADS; i++) { 
    57                 if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest")))
    58                         panic("could not create thread\n");
     63        for (i = 0; i < THREADS; i++) { 
     64                thread_t *t;
     65                if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest"))) {
     66                        printf("Could not create thread %d\n", i);
     67                        break;
     68                }
    5969                thread_ready(t);
     70                total++;
    6071        }
    61         printf("ok\n");
     72       
     73        printf("Running threads for 10 seconds...\n");
     74        thread_sleep(10);
     75       
     76        atomic_set(&finish, 0);
     77        while (atomic_get(&threads_finished) < total) {
     78                printf("Threads left: %d\n", total - atomic_get(&threads_finished));
     79                thread_sleep(1);
     80        }
     81       
     82        return NULL;
    6283}
  • kernel/test/thread/thread1.def

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