/kernel/branches/falloc_bad/test/mm/falloc2/test.c |
---|
0,0 → 1,109 |
/* |
* Copyright (C) 2006 Sergey Bondari |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <print.h> |
#include <test.h> |
#include <mm/page.h> |
#include <mm/frame.h> |
#include <arch/mm/page.h> |
#include <arch/types.h> |
#include <arch/atomic.h> |
#include <debug.h> |
#include <proc/thread.h> |
#include <memstr.h> |
#define MAX_FRAMES 128 |
#define MAX_ORDER 3 |
#define THREAD_RUNS 2 |
#define THREADS 6 |
static void thread(void * arg); |
static void failed(void); |
static atomic_t thread_count; |
void thread(void * arg) { |
int status, order, run, allocated,i; |
__u8 val = *((__u8 *) arg); |
__address frames[MAX_FRAMES]; |
for (run=0;run<THREAD_RUNS;run++) { |
for (order=0;order<=MAX_ORDER;order++) { |
printf("Allocating %d frames blocks ... ", 1<<order); |
allocated = 0; |
for (i=0;i<MAX_FRAMES>>order;i++) { |
frames[allocated] = frame_alloc(FRAME_NON_BLOCKING | FRAME_KA,order, &status); |
if (status == 0) { |
memsetb(frames[allocated], (1 << order) * FRAME_SIZE - 1, val); |
allocated++; |
} else { |
break; |
} |
} |
printf("%d blocks alocated.\n", allocated); |
printf("Deallocating ... "); |
for (i=0;i<allocated;i++) { |
/* add memtest here */ |
frame_free(frames[i]); |
} |
printf("done.\n"); |
} |
} |
atomic_dec(&thread_count); |
} |
void failed(void) { |
panic("Test failed.\n"); |
} |
void test(void) { |
int i; |
atomic_set(&thread_count, THREADS); |
for (i=1;i<=THREADS;i++) { |
thread_t * thrd; |
thrd = thread_create(thread, &i, TASK, 0); |
if (thrd) thread_ready(thrd); else failed(); |
} |
while (thread_count.count); |
printf("Test passed\n"); |
} |
/kernel/branches/falloc_bad/test/mm/falloc1/test.c |
---|
0,0 → 1,84 |
/* |
* Copyright (C) 2006 Sergey Bondari |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <print.h> |
#include <test.h> |
#include <mm/page.h> |
#include <mm/frame.h> |
#include <arch/mm/page.h> |
#include <arch/types.h> |
#include <debug.h> |
#define MAX_FRAMES 1024 |
#define MAX_ORDER 8 |
#define TEST_RUNS 4 |
void test(void) { |
__address frames[MAX_FRAMES]; |
int results[MAX_ORDER+1]; |
int i, order, run; |
int allocated; |
int status; |
ASSERT(TEST_RUNS > 1); |
for (run=0;run<=TEST_RUNS;run++) { |
for (order=0;order<=MAX_ORDER;order++) { |
printf("Allocating %d frames blocks ... ", 1<<order); |
allocated = 0; |
for (i=0;i<MAX_FRAMES>>order;i++) { |
frames[allocated] = frame_alloc(FRAME_NON_BLOCKING,order, &status); |
if (status == 0) { |
allocated++; |
} else { |
printf("done. "); |
break; |
} |
} |
printf("%d blocks alocated.\n", allocated); |
if (run) { |
if (results[order] != allocated) { |
panic("Test failed. Frame leak possible.\n"); |
} |
} else results[order] = allocated; |
printf("Deallocating ... "); |
for (i=0;i<allocated;i++) { |
frame_free(frames[i]); |
} |
printf("done.\n"); |
} |
} |
printf("Test passed\n"); |
} |
/kernel/branches/falloc_bad/test/mm/mapping1/test.c |
---|
0,0 → 1,85 |
/* |
* Copyright (C) 2005 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <print.h> |
#include <test.h> |
#include <mm/page.h> |
#include <mm/frame.h> |
#include <mm/asid.h> |
#include <arch/mm/page.h> |
#include <arch/types.h> |
#include <debug.h> |
#define PAGE0 0x10000000 |
#define PAGE1 (PAGE0+PAGE_SIZE) |
#define VALUE0 0x01234567 |
#define VALUE1 0x89abcdef |
void test(void) |
{ |
__address frame0, frame1; |
__u32 v0, v1; |
printf("Memory management test mapping #1\n"); |
frame0 = frame_alloc(FRAME_KA, ONE_FRAME, NULL); |
frame1 = frame_alloc(FRAME_KA, ONE_FRAME, NULL); |
printf("Writing %L to physical address %P.\n", VALUE0, KA2PA(frame0)); |
*((__u32 *) frame0) = VALUE0; |
printf("Writing %L to physical address %P.\n", VALUE1, KA2PA(frame1)); |
*((__u32 *) frame1) = VALUE1; |
printf("Mapping virtual address %P to physical address %P.\n", PAGE0, KA2PA(frame0)); |
page_mapping_insert(PAGE0, ASID_KERNEL, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE, 0); |
printf("Mapping virtual address %P to physical address %P.\n", PAGE1, KA2PA(frame1)); |
page_mapping_insert(PAGE1, ASID_KERNEL, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE, 0); |
printf("Value at virtual address %P is %L.\n", PAGE0, v0 = *((__u32 *) PAGE0)); |
printf("Value at virtual address %P is %L.\n", PAGE1, v1 = *((__u32 *) PAGE1)); |
ASSERT(v0 == VALUE0); |
ASSERT(v1 == VALUE1); |
printf("Writing %X to virtual address %P.\n", 0, PAGE0); |
*((__u32 *) PAGE0) = 0; |
printf("Writing %X to virtual address %P.\n", 0, PAGE1); |
*((__u32 *) PAGE1) = 0; |
v0 = *((__u32 *) PAGE0); |
v1 = *((__u32 *) PAGE1); |
printf("Value at virtual address %P is %X.\n", PAGE0, *((__u32 *) PAGE0)); |
printf("Value at virtual address %P is %X.\n", PAGE1, *((__u32 *) PAGE1)); |
ASSERT(v0 == 0); |
ASSERT(v1 == 0); |
printf("Test passed.\n"); |
} |