Changeset 96348adc in mainline for kernel/test/mm/falloc2.c


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.