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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [mm0/] [mm/] [test.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * These functions here do run-time checks on all fields
3
 * of tasks, vmas, and vm objects to see that they
4
 * have expected values.
5
 *
6
 * Copyright (C) 2008 Bahadir Balban
7
 */
8
 
9
#include <vm_area.h>
10
#include <mmap.h>
11
#include <shm.h>
12
#include <globals.h>
13
 
14
struct vm_statistics {
15
        int tasks;              /* All tasks counted on the system */
16
        int vm_objects;         /* All objects counted on the system */
17
        int shadow_objects;     /* Shadows counted by hand (well almost!) */
18
        int shadows_referred;   /* Shadows that objects say they have */
19
        int file_objects;       /* Objects that are found to be files */
20
        int vm_files;           /* All files counted on the system */
21
        int shm_files;          /* SHM files counted */
22
        int boot_files;         /* Boot files counted */
23
        int vfs_files;          /* VFS files counted */
24
        int devzero;            /* Devzero count, must be 1 */
25
};
26
 
27
/* Count links in objects link list, and compare with nlinks */
28
int vm_object_test_link_count(struct vm_object *vmo)
29
{
30
        int links = 0;
31
        struct vm_obj_link *l;
32
 
33
        list_foreach_struct(l, &vmo->link_list, linkref)
34
                links++;
35
 
36
        BUG_ON(links != vmo->nlinks);
37
        return 0;
38
}
39
 
40
int vm_object_test_shadow_count(struct vm_object *vmo)
41
{
42
        struct vm_object *sh;
43
        int shadows = 0;
44
 
45
        list_foreach_struct(sh, &vmo->shdw_list, shref)
46
                shadows++;
47
 
48
        BUG_ON(shadows != vmo->shadows);
49
        return 0;
50
}
51
 
52
/* TODO:
53
 * Add checking that total open file descriptors are
54
 * equal to total opener count of all files
55
 */
56
#if defined (DEBUG_FAULT_HANDLING)
57
int mm0_test_global_vm_integrity(void)
58
{
59
        struct tcb *task;
60
        struct vm_object *vmo;
61
        struct vm_statistics vmstat;
62
        struct vm_file *f;
63
 
64
 
65
        memset(&vmstat, 0, sizeof(vmstat));
66
 
67
        /* Count all shadow and file objects */
68
        list_foreach_struct(vmo, &global_vm_objects.list, list) {
69
                vmstat.shadows_referred += vmo->shadows;
70
                if (vmo->flags & VM_OBJ_SHADOW)
71
                        vmstat.shadow_objects++;
72
                if (vmo->flags & VM_OBJ_FILE)
73
                        vmstat.file_objects++;
74
                vmstat.vm_objects++;
75
                vm_object_test_shadow_count(vmo);
76
                vm_object_test_link_count(vmo);
77
        }
78
 
79
        /* Count all registered vmfiles */
80
        list_foreach_struct(f, &global_vm_files.list, list) {
81
                vmstat.vm_files++;
82
                if (f->type == VM_FILE_SHM)
83
                        vmstat.shm_files++;
84
                else if (f->type == VM_FILE_VFS)
85
                        vmstat.vfs_files++;
86
                else if (f->type == VM_FILE_DEVZERO)
87
                        vmstat.devzero++;
88
                else BUG();
89
        }
90
 
91
        if (vmstat.vm_files != global_vm_files.total) {
92
                printf("Total counted files don't match "
93
                       "global_vm_files total\n");
94
                BUG();
95
        }
96
 
97
        if (vmstat.vm_objects != global_vm_objects.total) {
98
                printf("Total counted vm_objects don't "
99
                       "match global_vm_objects total\n");
100
                BUG();
101
        }
102
 
103
        /* Total file objects must be equal to total vm files */
104
        if (vmstat.vm_files != vmstat.file_objects) {
105
                printf("\nTotal files don't match total file objects.\n");
106
                printf("vm files:\n");
107
                vm_print_files(&global_vm_files.list);
108
                printf("\nvm objects:\n");
109
                vm_print_objects(&global_vm_objects.list);
110
                printf("\n");
111
                BUG();
112
        }
113
 
114
        /* Counted and referred shadows must match */
115
        BUG_ON(vmstat.shadow_objects != vmstat.shadows_referred);
116
 
117
        /* Count all tasks */
118
        list_foreach_struct(task, &global_tasks.list, list)
119
                vmstat.tasks++;
120
 
121
        if (vmstat.tasks != global_tasks.total) {
122
                printf("Total counted tasks don't match global_tasks total\n");
123
                BUG();
124
        }
125
        return 0;
126
}
127
#else /* End of DEBUG_FAULT_HANDLING */
128
 
129
int mm0_test_global_vm_integrity(void) { return 0; }
130
 
131
#endif /* End of !DEBUG_FAULT_HANDLING */

powered by: WebSVN 2.1.0

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