summaryrefslogtreecommitdiff
path: root/testing/testing.c
blob: 7646b955db862b91b01b22495a0e1ccb6c153d74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <stdint.h>
#include "log.h"
#include "kmalloc.h"
#include "mount.h"

#include "lib/string/string.h"

void testing_mount_add(char *path, uint32_t t)
{
    mount m;
    memcpy(m.path,path,strlen(path)+1);
    m.type=t;
    mount_add(m);
}

void testing_get_mount(char *path)
{
    /*
    mount m;
    char *subpath=get_mount_for_path(path,&m);
    if(subpath==0)
    {
	testlog ("mount %s not found!",path);
    }
    else
    {
	testlog("mount [%s] is [%s] at [%s]",path, subpath, m.path);
    }
    */
}

void testing_mount()
{
    #ifndef FOOLOS_UNIT_TESTING
    return;
    #endif
    testlog ("= UNIT TESTING MOUNTS =");
    testing_mount_add("/",MOUNT_TYPE_EXT2);
    testing_mount_add("/pipes/",MOUNT_TYPE_PIPES);
    testing_mount_add("/pipes/input/",MOUNT_TYPE_PIPES);
    testing_mount_add("/sys/",MOUNT_TYPE_SYS);
    mount_dump();
//    testing_get_mount("pipes/input");
    testing_get_mount("/dupa");
    testing_get_mount("/pipe");
    testing_get_mount("/pipes/input");
    testing_get_mount("/pipes/in");
    testing_get_mount("/pipes/input/");
    testing_get_mount("/pipes/input/dups");
    testing_get_mount("/sys");
    testing_get_mount("/sys/ass");
    testing_get_mount("/sys/ass/bass");
    testing_get_mount("/foo/sys/ass/bass");
    while(1);
}
void testing_kmalloc_alloc(uint32_t size)
{
    uint32_t addr=kballoc(size);
    testlog("kballoc(%d) returned 0x%08x",size,addr);
}

void testing_kmalloc_alloc_free(uint32_t size)
{
    uint32_t addr=kballoc(size);
    testlog("kballoc(%d) returned 0x%08x",size,addr);
    kbfree(addr);
    testlog("kbfree(0x%08X)",addr);
}

// only free even
void testing_kmalloc_alloc_free_even(uint32_t size)
{
    uint32_t addr=kballoc(size);
    testlog("kballoc(%d) returned 0x%08x",size,addr);
    if(!(size%2))
    {
	kbfree(addr);
	testlog("kbfree(0x%08X)",addr);
    }
}

// only free first
void testing_kmalloc_alloc_two_free_first(uint32_t size)
{
    uint32_t addr1=kballoc(size);
    testlog("kballoc(%d) returned 0x%08x",size,addr1);

    uint32_t addr2=kballoc(size);
    testlog("kballoc(%d) returned 0x%08x",size,addr2);

    kbfree(addr1);
    testlog("kbfree(0x%08X)",addr1);
}

void testing_kmalloc()
{
    #ifndef FOOLOS_UNIT_TESTING
    return;
    #endif
    fixme("[TESTING] Create multiple independent tests that start from scratch");
    fixme("[TESTING] Check the test results automatically!");

    testlog("= UNIT TESTING KMALLOC =");

    testlog("* allocating blocks different sizes (1-10 blocks)");
    for(int i=0;i<10;i++)testing_kmalloc_alloc(i+1);

    testlog("* allocating and freeing different sizes (1-10 blocks)");
    for(int i=0;i<10;i++)testing_kmalloc_alloc_free(i+1);

    testlog("* allocating blocks different sizes (1-10 blocks)");
    for(int i=0;i<10;i++)testing_kmalloc_alloc(i+1);

    testlog("* allocating and freeing odd sizes only (1-10 blocks)");
    for(int i=0;i<10;i++)testing_kmalloc_alloc_free_even(i+1);

    testlog("* allocating two but freeing first only (1-10 blocks)");
    for(int i=0;i<10;i++)testing_kmalloc_alloc_two_free_first(i+1);

    testlog("* allocating two but freeing first only (10-1 blocks)");
    for(int i=9;i>=0;i--)testing_kmalloc_alloc_two_free_first(i+1);

    testlog("* allocating blocks different sizes (1-10 blocks)");
    for(int i=0;i<10;i++)testing_kmalloc_alloc(i+1);

    testlog("* allocating and freeing mega blocks");
    for(int i=0;i<10;i++)testing_kmalloc_alloc_two_free_first(255);

    testlog("* allocating two but freeing first only (1-10 blocks)");
    for(int i=0;i<10;i++)testing_kmalloc_alloc_two_free_first(255-i);

    testlog("* allocating two but freeing first only (1-10 blocks)");
    for(int i=0;i<10;i++)testing_kmalloc_alloc_two_free_first(255-i);

}