[f275cb3] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Sergey Bondari
|
---|
[f275cb3] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 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
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 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
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 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
|
---|
| 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
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
[96348adc] | 28 |
|
---|
[f275cb3] | 29 | #include <test.h>
|
---|
| 30 | #include <mm/page.h>
|
---|
| 31 | #include <mm/frame.h>
|
---|
| 32 | #include <arch/mm/page.h>
|
---|
[d99c1d2] | 33 | #include <typedefs.h>
|
---|
[4a2f4bb] | 34 | #include <align.h>
|
---|
[aafed15] | 35 | #include <stdlib.h>
|
---|
[f275cb3] | 36 |
|
---|
[b0c2075] | 37 | #define MAX_FRAMES 1024
|
---|
[cb01e1e] | 38 | #define MAX_ORDER 8
|
---|
| 39 | #define TEST_RUNS 2
|
---|
[f275cb3] | 40 |
|
---|
[abfc9f3] | 41 | const char *test_falloc1(void)
|
---|
| 42 | {
|
---|
[7e13972] | 43 | if (TEST_RUNS < 2)
|
---|
| 44 | return "Test is compiled with TEST_RUNS < 2";
|
---|
[a35b458] | 45 |
|
---|
[abfc9f3] | 46 | uintptr_t *frames = (uintptr_t *)
|
---|
[11b285d] | 47 | malloc(MAX_FRAMES * sizeof(uintptr_t));
|
---|
[96348adc] | 48 | if (frames == NULL)
|
---|
| 49 | return "Unable to allocate frames";
|
---|
[a35b458] | 50 |
|
---|
[b0c2075] | 51 | unsigned int results[MAX_FRAMES + 1];
|
---|
[a35b458] | 52 |
|
---|
[abfc9f3] | 53 | for (unsigned int run = 0; run < TEST_RUNS; run++) {
|
---|
[b0c2075] | 54 | for (size_t count = 1; count <= MAX_FRAMES; count++) {
|
---|
| 55 | size_t bytes = FRAMES2SIZE(count);
|
---|
[a35b458] | 56 |
|
---|
[b0c2075] | 57 | TPRINTF("Allocating %zu frames blocks (%zu bytes) ... ",
|
---|
| 58 | count, bytes);
|
---|
[a35b458] | 59 |
|
---|
[abfc9f3] | 60 | unsigned int allocated = 0;
|
---|
[b0c2075] | 61 | for (unsigned int i = 0; i < (MAX_FRAMES / count); i++) {
|
---|
[cd3b380] | 62 | frames[allocated] = frame_alloc(count, FRAME_ATOMIC, 0);
|
---|
| 63 | if (frames[allocated]) {
|
---|
[f275cb3] | 64 | allocated++;
|
---|
[cd3b380] | 65 | } else {
|
---|
[cb01e1e] | 66 | TPRINTF("done. ");
|
---|
[f275cb3] | 67 | break;
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
[a35b458] | 70 |
|
---|
[cb01e1e] | 71 | TPRINTF("%d blocks allocated.\n", allocated);
|
---|
[a35b458] | 72 |
|
---|
[b0c2075] | 73 | if (run > 0) {
|
---|
| 74 | if (results[count] != allocated)
|
---|
[96348adc] | 75 | return "Possible frame leak";
|
---|
[4a2f4bb] | 76 | } else
|
---|
[b0c2075] | 77 | results[count] = allocated;
|
---|
[a35b458] | 78 |
|
---|
[cb01e1e] | 79 | TPRINTF("Deallocating ... ");
|
---|
[a35b458] | 80 |
|
---|
[abfc9f3] | 81 | for (unsigned int i = 0; i < allocated; i++)
|
---|
[cd3b380] | 82 | frame_free(frames[i], count);
|
---|
[a35b458] | 83 |
|
---|
[cb01e1e] | 84 | TPRINTF("done.\n");
|
---|
[f275cb3] | 85 | }
|
---|
| 86 | }
|
---|
[a35b458] | 87 |
|
---|
[1093620] | 88 | free(frames);
|
---|
[a35b458] | 89 |
|
---|
[96348adc] | 90 | return NULL;
|
---|
[f275cb3] | 91 | }
|
---|