Rev 2021 | Rev 2029 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2021 | Rev 2028 | ||
|---|---|---|---|
| Line 23... | Line 23... | ||
| 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 | #include <print.h> |
29 | #include <print.h> |
| 29 | #include <test.h> |
30 | #include <test.h> |
| 30 | #include <mm/page.h> |
31 | #include <mm/page.h> |
| 31 | #include <mm/frame.h> |
32 | #include <mm/frame.h> |
| 32 | #include <mm/slab.h> |
33 | #include <mm/slab.h> |
| 33 | #include <arch/mm/page.h> |
34 | #include <arch/mm/page.h> |
| 34 | #include <arch/types.h> |
35 | #include <arch/types.h> |
| 35 | #include <debug.h> |
36 | #include <debug.h> |
| 36 | #include <align.h> |
37 | #include <align.h> |
| 37 | 38 | ||
| 38 | #ifdef CONFIG_BENCH |
- | |
| 39 | #include <arch/cycle.h> |
- | |
| 40 | #endif |
- | |
| 41 | - | ||
| 42 | #define MAX_FRAMES 1024 |
39 | #define MAX_FRAMES 1024 |
| 43 | #define MAX_ORDER 8 |
40 | #define MAX_ORDER 8 |
| 44 | #define TEST_RUNS 2 |
41 | #define TEST_RUNS 2 |
| 45 | 42 | ||
| 46 | void test_falloc1(void) { |
43 | char * test_falloc1(void) { |
| 47 | #ifdef CONFIG_BENCH |
- | |
| 48 | uint64_t t0 = get_cycle(); |
- | |
| 49 | #endif |
- | |
| 50 | uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES*sizeof(uintptr_t), 0); |
44 | uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), 0); |
| 51 | int results[MAX_ORDER+1]; |
45 | int results[MAX_ORDER + 1]; |
| 52 | 46 | ||
| 53 | int i, order, run; |
47 | int i, order, run; |
| 54 | int allocated; |
48 | int allocated; |
| 55 | 49 | ||
| 56 | ASSERT(TEST_RUNS > 1); |
50 | ASSERT(TEST_RUNS > 1); |
| 57 | ASSERT(frames != NULL) |
51 | if (frames == NULL) |
| - | 52 | return "Unable to allocate frames"; |
|
| 58 | 53 | ||
| 59 | for (run = 0; run < TEST_RUNS; run++) { |
54 | for (run = 0; run < TEST_RUNS; run++) { |
| 60 | for (order = 0; order <= MAX_ORDER; order++) { |
55 | for (order = 0; order <= MAX_ORDER; order++) { |
| 61 | printf("Allocating %d frames blocks ... ", 1 << order); |
56 | printf("Allocating %d frames blocks ... ", 1 << order); |
| 62 | allocated = 0; |
57 | allocated = 0; |
| 63 | for (i = 0; i < MAX_FRAMES >> order; i++) { |
58 | for (i = 0; i < MAX_FRAMES >> order; i++) { |
| 64 | frames[allocated] = (uintptr_t) frame_alloc(order, FRAME_ATOMIC | FRAME_KA); |
59 | frames[allocated] = (uintptr_t) frame_alloc(order, FRAME_ATOMIC | FRAME_KA); |
| 65 | 60 | ||
| 66 | if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) != frames[allocated]) { |
61 | if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) != frames[allocated]) { |
| 67 | panic("Test failed. Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10); |
62 | printf("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10); |
| - | 63 | return "Test failed"; |
|
| 68 | } |
64 | } |
| 69 | 65 | ||
| 70 | if (frames[allocated]) { |
66 | if (frames[allocated]) |
| 71 | allocated++; |
67 | allocated++; |
| 72 | } else { |
68 | else { |
| 73 | printf("done. "); |
69 | printf("done. "); |
| 74 | break; |
70 | break; |
| 75 | } |
71 | } |
| 76 | } |
72 | } |
| 77 | 73 | ||
| 78 | printf("%d blocks allocated.\n", allocated); |
74 | printf("%d blocks allocated.\n", allocated); |
| 79 | 75 | ||
| 80 | if (run) { |
76 | if (run) { |
| 81 | if (results[order] != allocated) { |
77 | if (results[order] != allocated) |
| 82 | panic("Test failed. Frame leak possible.\n"); |
78 | return "Possible frame leak"; |
| 83 | } |
- | |
| 84 | } else |
79 | } else |
| 85 | results[order] = allocated; |
80 | results[order] = allocated; |
| 86 | 81 | ||
| 87 | printf("Deallocating ... "); |
82 | printf("Deallocating ... "); |
| 88 | for (i = 0; i < allocated; i++) { |
83 | for (i = 0; i < allocated; i++) |
| 89 | frame_free(KA2PA(frames[i])); |
84 | frame_free(KA2PA(frames[i])); |
| 90 | } |
- | |
| 91 | printf("done.\n"); |
85 | printf("done.\n"); |
| 92 | } |
86 | } |
| 93 | } |
87 | } |
| 94 | 88 | ||
| 95 | free(frames); |
89 | free(frames); |
| 96 | 90 | ||
| 97 | printf("Test passed.\n"); |
- | |
| 98 | #ifdef CONFIG_BENCH |
- | |
| 99 | uint64_t dt = get_cycle() - t0; |
- | |
| 100 | printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt); |
- | |
| 101 | #endif |
91 | return NULL; |
| 102 | } |
92 | } |
| 103 | - | ||