Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2027 → Rev 2028

/trunk/kernel/test/mm/falloc2.def
0,0 → 1,6
{
"falloc2",
"Frame allocator test 2",
&test_falloc2,
true
},
/trunk/kernel/test/mm/slab1.def
0,0 → 1,6
{
"slab1",
"SLAB test 1",
&test_slab1,
true
},
/trunk/kernel/test/mm/purge1.def
0,0 → 1,8
#ifdef ia64
{
"purge1",
"Itanium TLB purge test",
&test_purge1,
true
},
#endif
/trunk/kernel/test/mm/slab2.def
0,0 → 1,6
{
"slab2",
"SLAB test 2",
&test_slab2,
true
},
/trunk/kernel/test/mm/falloc1.c
25,6 → 25,7
* (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>
35,26 → 36,20
#include <debug.h>
#include <align.h>
 
#ifdef CONFIG_BENCH
#include <arch/cycle.h>
#endif
 
#define MAX_FRAMES 1024
#define MAX_ORDER 8
#define TEST_RUNS 2
 
void test_falloc1(void) {
#ifdef CONFIG_BENCH
uint64_t t0 = get_cycle();
#endif
uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES*sizeof(uintptr_t), 0);
int results[MAX_ORDER+1];
char * test_falloc1(void) {
uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), 0);
int results[MAX_ORDER + 1];
int i, order, run;
int allocated;
 
ASSERT(TEST_RUNS > 1);
ASSERT(frames != NULL)
if (frames == NULL)
return "Unable to allocate frames";
 
for (run = 0; run < TEST_RUNS; run++) {
for (order = 0; order <= MAX_ORDER; order++) {
64,30 → 59,29
frames[allocated] = (uintptr_t) frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) != frames[allocated]) {
panic("Test failed. Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10);
printf("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10);
return "Test failed";
}
if (frames[allocated]) {
if (frames[allocated])
allocated++;
} else {
else {
printf("done. ");
break;
}
}
printf("%d blocks allocated.\n", allocated);
if (run) {
if (results[order] != allocated) {
panic("Test failed. Frame leak possible.\n");
}
if (results[order] != allocated)
return "Possible frame leak";
} else
results[order] = allocated;
printf("Deallocating ... ");
for (i = 0; i < allocated; i++) {
for (i = 0; i < allocated; i++)
frame_free(KA2PA(frames[i]));
}
printf("done.\n");
}
}
94,10 → 88,5
 
free(frames);
printf("Test passed.\n");
#ifdef CONFIG_BENCH
uint64_t dt = get_cycle() - t0;
printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
#endif
return NULL;
}
 
/trunk/kernel/test/mm/falloc2.c
25,6 → 25,7
* (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>
38,10 → 39,6
#include <memstr.h>
#include <arch.h>
 
#ifdef CONFIG_BENCH
#include <arch/cycle.h>
#endif
 
#define MAX_FRAMES 256
#define MAX_ORDER 8
 
48,12 → 45,10
#define THREAD_RUNS 1
#define THREADS 8
 
static void falloc(void * arg);
static void failed(void);
 
static atomic_t thread_count;
static atomic_t thread_fail;
 
void falloc(void * arg)
static void falloc(void * arg)
{
int order, run, allocated, i;
uint8_t val = THREAD->tid % THREADS;
60,7 → 55,12
index_t k;
uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), FRAME_ATOMIC);
ASSERT(frames != NULL);
if (frames == NULL) {
printf("Thread #%d (cpu%d): Unable to allocate frames\n", THREAD->tid, CPU->id);
atomic_inc(&thread_fail);
atomic_dec(&thread_count);
return;
}
thread_detach(THREAD);
 
73,9 → 73,8
if (frames[allocated]) {
memsetb(frames[allocated], FRAME_SIZE << order, val);
allocated++;
} else {
} else
break;
}
}
printf("Thread #%d (cpu%d): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated);
 
84,7 → 83,8
for (k = 0; k <= ((FRAME_SIZE << order) - 1); k++) {
if (((uint8_t *) frames[i])[k] != val) {
printf("Thread #%d (cpu%d): Unexpected data (%d) in block %p offset %#zx\n", THREAD->tid, CPU->id, ((char *) frames[i])[k], frames[i], k);
failed();
atomic_inc(&thread_fail);
goto cleanup;
}
}
frame_free(KA2PA(frames[i]));
92,43 → 92,36
printf("Thread #%d (cpu%d): Finished run.\n", THREAD->tid, CPU->id);
}
}
 
cleanup:
free(frames);
printf("Thread #%d (cpu%d): Exiting\n", THREAD->tid, CPU->id);
atomic_dec(&thread_count);
}
 
 
void failed(void)
char * test_falloc2(void)
{
panic("Test failed.\n");
}
unsigned int i;
 
 
void test_falloc2(void)
{
#ifdef CONFIG_BENCH
uint64_t t0 = get_cycle();
#endif
int i;
 
atomic_set(&thread_count, THREADS);
atomic_set(&thread_fail, 0);
for (i = 0; i < THREADS; i++) {
thread_t * thrd;
thrd = thread_create(falloc, NULL, TASK, 0, "falloc");
if (thrd)
thread_ready(thrd);
else
failed();
thread_t * thrd = thread_create(falloc, NULL, TASK, 0, "falloc");
if (!thrd) {
printf("Could not create thread %d\n", i);
break;
}
thread_ready(thrd);
}
while (thread_count.count)
;
 
printf("Test passed.\n");
#ifdef CONFIG_BENCH
uint64_t dt = get_cycle() - t0;
printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
#endif
while (atomic_get(&thread_count) > 0) {
printf("Threads left: %d\n", atomic_get(&thread_count));
thread_sleep(1);
}
if (atomic_get(&thread_fail) == 0)
return NULL;
return "Test failed";
}
/trunk/kernel/test/mm/slab1.c
34,10 → 34,6
#include <panic.h>
#include <memstr.h>
 
#ifdef CONFIG_BENCH
#include <arch/cycle.h>
#endif
 
#define VAL_COUNT 1024
 
static void * data[VAL_COUNT];
51,38 → 47,38
cache = slab_cache_create("test_cache", size, 0, NULL, NULL,
SLAB_CACHE_NOMAGAZINE);
printf("Allocating %d items...", count);
for (i=0; i < count; i++) {
for (i = 0; i < count; i++) {
data[i] = slab_alloc(cache, 0);
memsetb((uintptr_t)data[i], size, 0);
memsetb((uintptr_t) data[i], size, 0);
}
printf("done.\n");
printf("Freeing %d items...", count);
for (i=0; i < count; i++) {
for (i = 0; i < count; i++) {
slab_free(cache, data[i]);
}
printf("done.\n");
 
printf("Allocating %d items...", count);
for (i=0; i < count; i++) {
for (i = 0; i < count; i++) {
data[i] = slab_alloc(cache, 0);
memsetb((uintptr_t)data[i], size, 0);
memsetb((uintptr_t) data[i], size, 0);
}
printf("done.\n");
 
printf("Freeing %d items...", count/2);
for (i=count-1; i >= count/2; i--) {
printf("Freeing %d items...", count / 2);
for (i = count - 1; i >= count / 2; i--) {
slab_free(cache, data[i]);
}
printf("done.\n");
 
printf("Allocating %d items...", count/2);
for (i=count/2; i < count; i++) {
printf("Allocating %d items...", count / 2);
for (i = count / 2; i < count; i++) {
data[i] = slab_alloc(cache, 0);
memsetb((uintptr_t)data[i], size, 0);
memsetb((uintptr_t) data[i], size, 0);
}
printf("done.\n");
printf("Freeing %d items...", count);
for (i=0; i < count; i++) {
for (i = 0; i < count; i++) {
slab_free(cache, data[i]);
}
printf("done.\n");
103,31 → 99,30
testit(16385, 128);
}
 
 
#define THREADS 6
#define THR_MEM_COUNT 1024
#define THR_MEM_SIZE 128
 
void * thr_data[THREADS][THR_MEM_COUNT];
slab_cache_t *thr_cache;
semaphore_t thr_sem;
static void * thr_data[THREADS][THR_MEM_COUNT];
static slab_cache_t *thr_cache;
static semaphore_t thr_sem;
 
static void slabtest(void *data)
{
int offs = (int)(unative_t) data;
int i,j;
int offs = (int) (unative_t) data;
int i, j;
thread_detach(THREAD);
printf("Starting thread #%d...\n",THREAD->tid);
for (j=0; j<10; j++) {
for (i=0; i<THR_MEM_COUNT; i++)
for (j = 0; j < 10; j++) {
for (i = 0; i < THR_MEM_COUNT; i++)
thr_data[offs][i] = slab_alloc(thr_cache,0);
for (i=0; i<THR_MEM_COUNT/2; i++)
for (i = 0; i < THR_MEM_COUNT / 2; i++)
slab_free(thr_cache, thr_data[offs][i]);
for (i=0; i< THR_MEM_COUNT/2; i++)
for (i = 0; i < THR_MEM_COUNT / 2; i++)
thr_data[offs][i] = slab_alloc(thr_cache, 0);
for (i=0; i<THR_MEM_COUNT;i++)
for (i = 0; i < THR_MEM_COUNT; i++)
slab_free(thr_cache, thr_data[offs][i]);
}
printf("Thread #%d finished\n", THREAD->tid);
142,14 → 137,15
thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0,
NULL, NULL,
SLAB_CACHE_NOMAGAZINE);
semaphore_initialize(&thr_sem,0);
for (i=0; i<THREADS; i++) {
if (!(t = thread_create(slabtest, (void *)(unative_t)i, TASK, 0, "slabtest")))
panic("could not create thread\n");
thread_ready(t);
semaphore_initialize(&thr_sem, 0);
for (i = 0; i < THREADS; i++) {
if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest")))
printf("Could not create thread %d\n", i);
else
thread_ready(t);
}
 
for (i=0; i<THREADS; i++)
for (i = 0; i < THREADS; i++)
semaphore_down(&thr_sem);
slab_cache_destroy(thr_cache);
157,15 → 153,10
}
 
void test_slab1(void)
char * test_slab1(void)
{
#ifdef CONFIG_BENCH
uint64_t t0 = get_cycle();
#endif
testsimple();
testthreads();
#ifdef CONFIG_BENCH
uint64_t dt = get_cycle() - t0;
printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
#endif
return NULL;
}
/trunk/kernel/test/mm/purge1.c
26,6 → 26,8
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifdef ia64
 
#include <print.h>
#include <test.h>
#include <mm/page.h>
36,16 → 38,14
#include <arch/types.h>
#include <debug.h>
 
#ifdef ia64
 
extern void tlb_invalidate_all(void);
extern void tlb_invalidate_pages(asid_t asid, uintptr_t va, count_t cnt);
 
void test(void)
char * test(void)
{
tlb_entry_t entryi;
tlb_entry_t entryd;
 
int i;
entryd.word[0] = 0;
80,13 → 80,8
tlb_invalidate_pages(8,0x0c000,14);
/*tlb_invalidate_all();*/
return NULL;
}
 
#else
 
void test_purge1(void)
{
printf("This test is availaible only on IA64 platform.\n");
}
 
#endif
/trunk/kernel/test/mm/slab2.c
37,10 → 37,6
#include <synch/condvar.h>
#include <synch/mutex.h>
 
#ifdef CONFIG_BENCH
#include <arch/cycle.h>
#endif
 
#define ITEM_SIZE 256
 
/** Fill memory with 2 caches, when allocation fails,
77,7 → 73,7
*((void **)data2) = olddata2;
olddata1 = data1;
olddata2 = data2;
}while(1);
} while(1);
printf("done.\n");
/* We do not have memory - now deallocate cache2 */
printf("Deallocating cache2...");
128,7 → 124,7
 
static void slabtest(void *priv)
{
void *data=NULL, *new;
void *data = NULL, *new;
 
thread_detach(THREAD);
 
172,13 → 168,11
data = new;
}
 
 
printf("Thread #%d finished\n", THREAD->tid);
slab_print_list();
semaphore_up(&thr_sem);
}
 
 
static void multitest(int size)
{
/* Start 8 threads that just allocate as much as possible,
195,15 → 189,16
NULL, NULL,
0);
semaphore_initialize(&thr_sem,0);
for (i=0; i<THREADS; i++) {
for (i = 0; i < THREADS; i++) {
if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest")))
panic("could not create thread\n");
thread_ready(t);
printf("Could not create thread %d\n", i);
else
thread_ready(t);
}
thread_sleep(1);
condvar_broadcast(&thread_starter);
 
for (i=0; i<THREADS; i++)
for (i = 0; i < THREADS; i++)
semaphore_down(&thr_sem);
slab_cache_destroy(thr_cache);
210,15 → 205,11
printf("Stress test complete.\n");
}
 
void test_slab2(void)
char * test_slab2(void)
{
#ifdef CONFIG_BENCH
uint64_t t0 = get_cycle();
#endif
 
printf("Running reclaim single-thread test .. pass1\n");
printf("Running reclaim single-thread test .. pass 1\n");
totalmemtest();
printf("Running reclaim single-thread test .. pass2\n");
printf("Running reclaim single-thread test .. pass 2\n");
totalmemtest();
printf("Reclaim test OK.\n");
 
226,9 → 217,6
multitest(2048);
multitest(8192);
printf("All done.\n");
 
#ifdef CONFIG_BENCH
uint64_t dt = get_cycle() - t0;
printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
#endif
return NULL;
}
/trunk/kernel/test/mm/mapping1.def
0,0 → 1,6
{
"mapping1",
"Mapping test",
&test_mapping1,
false
},
/trunk/kernel/test/mm/mapping1.c
25,6 → 25,7
* (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>
34,10 → 35,6
#include <arch/types.h>
#include <debug.h>
 
#ifdef CONFIG_BENCH
#include <arch/cycle.h>
#endif
 
#define PAGE0 0x10000000
#define PAGE1 (PAGE0+PAGE_SIZE)
 
44,16 → 41,11
#define VALUE0 0x01234567
#define VALUE1 0x89abcdef
 
void test_mapping1(void)
char * test_mapping1(void)
{
#ifdef CONFIG_BENCH
uint64_t t0 = get_cycle();
#endif
uintptr_t frame0, frame1;
uint32_t v0, v1;
 
printf("Memory management test mapping #1\n");
 
frame0 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA);
frame1 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA);
 
87,9 → 79,5
ASSERT(v0 == 0);
ASSERT(v1 == 0);
printf("Test passed.\n");
#ifdef CONFIG_BENCH
uint64_t dt = get_cycle() - t0;
printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
#endif
return NULL;
}
/trunk/kernel/test/mm/falloc1.def
0,0 → 1,6
{
"falloc1",
"Frame allocator test 1",
&test_falloc1,
true
},