OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [src/] [glue/] [tests/] [test_allocpage.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#include <macros.h>
2
#include <config.h>
3
#include INC_GLUE(memory.h)
4
 
5
#include <lib/printk.h>
6
#include <lib/list.h>
7
#include <stdlib.h>
8
#include <stdio.h>
9
#include <time.h>
10
#include <string.h>
11
#include "test_allocpage.h"
12
#include "test_alloc_generic.h"
13
#include "debug.h"
14
 
15
unsigned int PAGE_ALLOCATIONS = 30;
16
unsigned int PAGE_ALLOC_SIZE_MAX = 8;
17
 
18
extern struct page_area *areas;
19
extern struct mem_cache *primary_cache;
20
 
21
extern struct mem_cache *secondary_cache;
22
extern struct mem_cache *spare_cache;
23
 
24
void print_page_area(struct page_area *ar, int areano)
25
{
26
        printf("Area starts @: 0x%x, %s, numpages: %d\n",
27
               ar->index << PAGE_BITS,
28
               (ar->used) ? "used" : "unused", ar->numpages);
29
        return;
30
}
31
 
32
void print_areas(struct page_area *ar)
33
{
34
        struct page_area *cur = ar;
35
        int areano = 1;
36
        printf("Page areas:\n-------------\n");
37
 
38
        if (!ar) {
39
                printf("None.\n");
40
                return;
41
        }
42
        print_page_area(cur, areano++);
43
        list_foreach_struct(cur, &ar->list, list) {
44
                print_page_area(cur, areano++);
45
        }
46
        return;
47
}
48
 
49
void print_cache(struct mem_cache *c, int cacheno)
50
{
51
        printf("Cache %d state:\n-------------\n", cacheno);
52
        printf("Total: %d\n", c->total);
53
        printf("Free: %d\n", c->free);
54
        printf("Start: 0x%x\n", c->start);
55
        return;
56
}
57
 
58
void print_caches(struct mem_cache *c)
59
{
60
        int caches = 1;
61
        struct mem_cache *cur = c;
62
        if (!c) {
63
                printf("None.\n");
64
                return;
65
        }
66
        print_cache(cur, caches++);
67
        list_foreach_struct(cur, &c->list, list) {
68
                print_cache(cur, caches++);
69
        }
70
        return;
71
}
72
 
73
void print_page_allocator_state(void)
74
{
75
        print_areas(areas);
76
        printf("PRIMARY:\n--------\n");
77
        print_caches(primary_cache);
78
        printf("SECONDARY:\n----------\n");
79
        print_caches(secondary_cache);
80
}
81
 
82
/* FIXME: with current default parameters (allocations = 30, sizemax = 8),
83
 * for some odd reason, we got the bug at line 280 in alloc_page.c.
84
 * Very weird. Find out why.
85
 */
86
void test_allocpage(int page_allocations, int page_alloc_size_max,
87
                    FILE *init_state, FILE *exit_state)
88
{
89
        if (!page_allocations)
90
                page_allocations = PAGE_ALLOCATIONS;
91
        if (!page_alloc_size_max)
92
                page_alloc_size_max = PAGE_ALLOC_SIZE_MAX;
93
 
94
        printf("\nPAGE ALLOCATOR TEST:====================================\n\n");
95
        test_alloc_free_random_order(page_allocations, page_alloc_size_max,
96
                                     alloc_page, free_page,
97
                                     print_page_allocator_state,
98
                                     init_state, exit_state);
99
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.