Rev 767 | Rev 773 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 767 | Rev 768 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Ondrej Palkovsky |
2 | * Copyright (C) 2006 Ondrej Palkovsky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include <test.h> |
29 | #include <test.h> |
30 | #include <mm/slab.h> |
30 | #include <mm/slab.h> |
31 | #include <print.h> |
31 | #include <print.h> |
32 | #include <proc/thread.h> |
32 | #include <proc/thread.h> |
33 | #include <arch.h> |
33 | #include <arch.h> |
34 | #include <panic.h> |
34 | #include <panic.h> |
35 | #include <mm/frame.h> |
35 | #include <mm/frame.h> |
- | 36 | #include <memstr.h> |
|
36 | 37 | ||
37 | #define ITEM_SIZE 256 |
38 | #define ITEM_SIZE 256 |
38 | 39 | ||
39 | /** Fill memory with 2 caches, when allocation fails, |
40 | /** Fill memory with 2 caches, when allocation fails, |
40 | * free one of the caches. We should have everything in magazines, |
41 | * free one of the caches. We should have everything in magazines, |
41 | * now allocation should clean magazines and allow for full allocation. |
42 | * now allocation should clean magazines and allow for full allocation. |
42 | */ |
43 | */ |
43 | static void totalmemtest(void) |
44 | static void totalmemtest(void) |
44 | { |
45 | { |
45 | slab_cache_t *cache1; |
46 | slab_cache_t *cache1; |
46 | slab_cache_t *cache2; |
47 | slab_cache_t *cache2; |
47 | int i; |
48 | int i; |
48 | 49 | ||
49 | void *data1, *data2; |
50 | void *data1, *data2; |
50 | void *olddata1=NULL, *olddata2=NULL; |
51 | void *olddata1=NULL, *olddata2=NULL; |
51 | 52 | ||
52 | cache1 = slab_cache_create("cache1_tst", ITEM_SIZE, 0, NULL, NULL, 0); |
53 | cache1 = slab_cache_create("cache1_tst", ITEM_SIZE, 0, NULL, NULL, 0); |
53 | cache2 = slab_cache_create("cache2_tst", ITEM_SIZE, 0, NULL, NULL, 0); |
54 | cache2 = slab_cache_create("cache2_tst", ITEM_SIZE, 0, NULL, NULL, 0); |
54 | 55 | ||
55 | printf("Allocating..."); |
56 | printf("Allocating..."); |
56 | /* Use atomic alloc, so that we find end of memory */ |
57 | /* Use atomic alloc, so that we find end of memory */ |
57 | do { |
58 | do { |
58 | data1 = slab_alloc(cache1, FRAME_ATOMIC); |
59 | data1 = slab_alloc(cache1, FRAME_ATOMIC); |
59 | data2 = slab_alloc(cache2, FRAME_ATOMIC); |
60 | data2 = slab_alloc(cache2, FRAME_ATOMIC); |
60 | if (!data1 || !data2) { |
61 | if (!data1 || !data2) { |
61 | if (data1) |
62 | if (data1) |
62 | slab_free(cache1,data1); |
63 | slab_free(cache1,data1); |
63 | if (data2) |
64 | if (data2) |
64 | slab_free(cache2,data2); |
65 | slab_free(cache2,data2); |
65 | break; |
66 | break; |
66 | } |
67 | } |
67 | - | ||
- | 68 | memsetb((__address)data1, ITEM_SIZE, 0); |
|
- | 69 | memsetb((__address)data2, ITEM_SIZE, 0); |
|
68 | *((void **)data1) = olddata1; |
70 | *((void **)data1) = olddata1; |
69 | *((void **)data2) = olddata2; |
71 | *((void **)data2) = olddata2; |
70 | olddata1 = data1; |
72 | olddata1 = data1; |
71 | olddata2 = data2; |
73 | olddata2 = data2; |
72 | }while(1); |
74 | }while(1); |
73 | printf("done.\n"); |
75 | printf("done.\n"); |
74 | slab_print_list(); |
76 | slab_print_list(); |
75 | /* We do not have memory - now deallocate cache2 */ |
77 | /* We do not have memory - now deallocate cache2 */ |
76 | printf("Deallocating cache2..."); |
78 | printf("Deallocating cache2..."); |
77 | while (olddata2) { |
79 | while (olddata2) { |
78 | data2 = *((void **)olddata2); |
80 | data2 = *((void **)olddata2); |
79 | slab_free(cache2, olddata2); |
81 | slab_free(cache2, olddata2); |
80 | olddata2 = data2; |
82 | olddata2 = data2; |
81 | } |
83 | } |
82 | printf("done.\n"); |
84 | printf("done.\n"); |
83 | 85 | ||
84 | slab_print_list(); |
86 | slab_print_list(); |
85 | printf("Allocating to cache1...\n"); |
87 | printf("Allocating to cache1...\n"); |
86 | for (i=0; i<30; i++) { |
88 | for (i=0; i<30; i++) { |
87 | data1 = slab_alloc(cache1, FRAME_ATOMIC); |
89 | data1 = slab_alloc(cache1, FRAME_ATOMIC); |
88 | if (!data1) { |
90 | if (!data1) { |
89 | panic("Incorrect memory size - use another test."); |
91 | panic("Incorrect memory size - use another test."); |
90 | } |
92 | } |
- | 93 | memsetb((__address)data1, ITEM_SIZE, 0); |
|
91 | *((void **)data1) = olddata1; |
94 | *((void **)data1) = olddata1; |
92 | olddata1 = data1; |
95 | olddata1 = data1; |
93 | } |
96 | } |
94 | slab_print_list(); |
97 | slab_print_list(); |
95 | while (1) { |
98 | while (1) { |
96 | data1 = slab_alloc(cache1, FRAME_ATOMIC); |
99 | data1 = slab_alloc(cache1, FRAME_ATOMIC); |
97 | if (!data1) { |
100 | if (!data1) { |
98 | break; |
101 | break; |
99 | } |
102 | } |
- | 103 | memsetb((__address)data1, ITEM_SIZE, 0); |
|
100 | *((void **)data1) = olddata1; |
104 | *((void **)data1) = olddata1; |
101 | olddata1 = data1; |
105 | olddata1 = data1; |
102 | } |
106 | } |
103 | slab_print_list(); |
107 | slab_print_list(); |
- | 108 | printf("Deallocating cache1..."); |
|
- | 109 | while (olddata1) { |
|
- | 110 | data1 = *((void **)olddata1); |
|
- | 111 | slab_free(cache1, olddata1); |
|
- | 112 | olddata1 = data1; |
|
104 | 113 | } |
|
- | 114 | printf("done.\n"); |
|
- | 115 | slab_print_list(); |
|
- | 116 | slab_cache_destroy(cache1); |
|
- | 117 | slab_cache_destroy(cache2); |
|
105 | } |
118 | } |
106 | 119 | ||
107 | void test(void) |
120 | void test(void) |
108 | { |
121 | { |
- | 122 | printf("Running reclaim test .. pass1\n"); |
|
- | 123 | totalmemtest(); |
|
- | 124 | printf("Running reclaim test .. pass2\n"); |
|
109 | totalmemtest(); |
125 | totalmemtest(); |
- | 126 | printf("Reclaim test OK.\n"); |
|
110 | } |
127 | } |
111 | 128 |