Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2027 → Rev 2028

/trunk/kernel/test/test.c
42,103 → 42,21
#include <fpu/fpu1.def>
#include <fpu/sse1.def>
#include <fpu/mips2.def>
/*
{
"falloc1",
"Frame allocator test 1",
&test_falloc1,
true
},
{
"falloc2",
"Frame allocator test 2",
&test_falloc2,
true
},
{
"mapping1",
"Mapping test",
&test_mapping1,
true
},
{
"slab1",
"SLAB test 1",
&test_slab1,
true
},
{
"slab2",
"SLAB test 2",
&test_slab2,
true
},
{
"purge1",
"Itanium TLB purge test",
&test_purge1,
true
},
{
"rwlock1",
"RW-lock test 1",
&test_rwlock1,
true
},
{
"rwlock2",
"RW-lock test 2",
&test_rwlock2,
true
},
{
"rwlock3",
"RW-lock test 3",
&test_rwlock3,
true
},
{
"rwlock4",
"RW-lock test 4",
&test_rwlock4,
true
},
{
"rwlock5",
"RW-lock test 5",
&test_rwlock5,
true
},
{
"semaphore1",
"Semaphore test 1",
&test_semaphore1,
true
},
{
"semaphore2",
"Semaphore test 2",
&test_semaphore2,
true
},
{
"print1",
"Printf test",
&test_print1,
true
},
{
"thread1",
"Thread test",
&test_thread1,
true
},
{
"sysinfo1",
"Sysinfo test",
&test_sysinfo1,
true
},*/
#include <mm/falloc1.def>
#include <mm/falloc2.def>
#include <mm/mapping1.def>
#include <mm/slab1.def>
#include <mm/slab2.def>
#include <synch/rwlock1.def>
#include <synch/rwlock2.def>
#include <synch/rwlock3.def>
#include <synch/rwlock4.def>
#include <synch/rwlock5.def>
#include <synch/semaphore1.def>
#include <synch/semaphore2.def>
#include <print/print1.def>
#include <thread/thread1.def>
#include <sysinfo/sysinfo1.def>
{NULL, NULL, NULL}
};
 
/trunk/kernel/test/synch/rwlock1.def
0,0 → 1,6
{
"rwlock1",
"RW-lock test 1",
&test_rwlock1,
true
},
/trunk/kernel/test/synch/rwlock2.def
0,0 → 1,6
{
"rwlock2",
"RW-lock test 2",
&test_rwlock2,
true
},
/trunk/kernel/test/synch/rwlock3.def
0,0 → 1,6
{
"rwlock3",
"RW-lock test 3",
&test_rwlock3,
true
},
/trunk/kernel/test/synch/semaphore1.def
0,0 → 1,6
{
"semaphore1",
"Semaphore test 1",
&test_semaphore1,
true
},
/trunk/kernel/test/synch/rwlock4.def
0,0 → 1,6
{
"rwlock4",
"RW-lock test 4",
&test_rwlock4,
true
},
/trunk/kernel/test/synch/semaphore2.def
0,0 → 1,6
{
"semaphore2",
"Semaphore test 2",
&test_semaphore2,
true
},
/trunk/kernel/test/synch/rwlock1.c
40,10 → 40,8
 
static rwlock_t rwlock;
 
void test_rwlock1(void)
char * test_rwlock1(void)
{
printf("Read/write locks test #1\n");
 
rwlock_initialize(&rwlock);
 
rwlock_write_lock(&rwlock);
73,6 → 71,6
 
rwlock_read_lock(&rwlock);
rwlock_read_unlock(&rwlock);
 
printf("Test passed.\n");
return NULL;
}
/trunk/kernel/test/synch/rwlock5.def
0,0 → 1,6
{
"rwlock5",
"RW-lock test 5",
&test_rwlock5,
true
},
/trunk/kernel/test/synch/rwlock2.c
39,9 → 39,6
 
static rwlock_t rwlock;
 
static void writer(void *arg);
static void failed(void);
 
static void writer(void *arg)
{
 
58,18 → 55,10
printf("Test passed.\n");
}
 
static void failed()
char * test_rwlock2(void)
{
printf("Test failed prematurely.\n");
thread_exit();
}
 
void test_rwlock2(void)
{
thread_t *thrd;
printf("Read/write locks test #2\n");
rwlock_initialize(&rwlock);
 
rwlock_read_lock(&rwlock);
81,14 → 70,14
if (thrd)
thread_ready(thrd);
else
failed();
return "Could not create thread";
 
 
thread_sleep(1);
rwlock_read_unlock(&rwlock);
rwlock_read_unlock(&rwlock);
rwlock_read_unlock(&rwlock);
rwlock_read_unlock(&rwlock);
 
rwlock_read_unlock(&rwlock);
return NULL;
}
/trunk/kernel/test/synch/rwlock3.c
39,9 → 39,6
 
static rwlock_t rwlock;
 
static void reader(void *arg);
static void failed(void);
 
static void reader(void *arg)
{
thread_detach(THREAD);
56,38 → 53,27
rwlock_write_lock(&rwlock);
rwlock_write_unlock(&rwlock);
printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid);
printf("Test passed.\n");
 
}
 
static void failed(void)
char * test_rwlock3(void)
{
printf("Test failed prematurely.\n");
thread_exit();
}
 
void test_rwlock3(void)
{
int i;
thread_t *thrd;
printf("Read/write locks test #3\n");
rwlock_initialize(&rwlock);
 
rwlock_write_lock(&rwlock);
for (i=0; i<4; i++) {
for (i = 0; i < 4; i++) {
thrd = thread_create(reader, NULL, TASK, 0, "reader");
if (thrd)
thread_ready(thrd);
else
failed();
printf("Could not create reader %d\n", i);
}
 
 
thread_sleep(1);
rwlock_write_unlock(&rwlock);
return NULL;
}
/trunk/kernel/test/synch/semaphore1.c
45,10 → 45,6
static atomic_t items_produced;
static atomic_t items_consumed;
 
static void consumer(void *arg);
static void producer(void *arg);
static void failed(void);
 
static void producer(void *arg)
{
thread_detach(THREAD);
73,24 → 69,15
semaphore_up(&sem);
}
 
static void failed(void)
char * test_semaphore1(void)
{
printf("Test failed prematurely.\n");
thread_exit();
}
 
void test_semaphore1(void)
{
int i, j, k;
int consumers, producers;
printf("Semaphore test #1\n");
waitq_initialize(&can_start);
semaphore_initialize(&sem, AT_ONCE);
 
 
for (i=1; i<=3; i++) {
for (i = 1; i <= 3; i++) {
thread_t *thrd;
 
atomic_set(&items_produced, 0);
97,24 → 84,24
atomic_set(&items_consumed, 0);
consumers = i * CONSUMERS;
producers = (4-i) * PRODUCERS;
producers = (4 - i) * PRODUCERS;
printf("Creating %d consumers and %d producers...", consumers, producers);
for (j=0; j<(CONSUMERS+PRODUCERS)/2; j++) {
for (k=0; k<i; k++) {
for (j = 0; j < (CONSUMERS + PRODUCERS) / 2; j++) {
for (k = 0; k < i; k++) {
thrd = thread_create(consumer, NULL, TASK, 0, "consumer");
if (thrd)
thread_ready(thrd);
else
failed();
printf("could not create consumer %d\n", i);
}
for (k=0; k<(4-i); k++) {
for (k = 0; k < (4 - i); k++) {
thrd = thread_create(producer, NULL, TASK, 0, "producer");
if (thrd)
thread_ready(thrd);
else
failed();
printf("could not create producer %d\n", i);
}
}
 
123,10 → 110,11
thread_sleep(1);
waitq_wakeup(&can_start, WAKEUP_ALL);
while (items_consumed.count != consumers || items_produced.count != producers) {
while ((items_consumed.count != consumers) || (items_produced.count != producers)) {
printf("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count);
thread_sleep(1);
}
}
printf("Test passed.\n");
return NULL;
}
/trunk/kernel/test/synch/rwlock4.c
52,12 → 52,6
 
static uint32_t seed = 0xdeadbeef;
 
static uint32_t random(uint32_t max);
 
static void writer(void *arg);
static void reader(void *arg);
static void failed(void);
 
static uint32_t random(uint32_t max)
{
uint32_t rc;
69,7 → 63,6
return rc;
}
 
 
static void writer(void *arg)
{
int rc, to;
82,7 → 75,7
if (SYNCH_FAILED(rc)) {
printf("cpu%d, tid %d w!\n", CPU->id, THREAD->tid);
return;
};
}
printf("cpu%d, tid %d w=\n", CPU->id, THREAD->tid);
 
if (rwlock.readers_in) panic("Oops.");
112,50 → 105,41
printf("cpu%d, tid %d r-\n", CPU->id, THREAD->tid);
}
 
static void failed(void)
char * test_rwlock4(void)
{
printf("Test failed prematurely.\n");
thread_exit();
}
 
void test_rwlock4(void)
{
context_t ctx;
uint32_t i, k;
printf("Read/write locks test #4\n");
waitq_initialize(&can_start);
rwlock_initialize(&rwlock);
for (;;) {
thread_t *thrd;
context_save(&ctx);
printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in);
k = random(7) + 1;
printf("Creating %d readers\n", k);
for (i=0; i<k; i++) {
thrd = thread_create(reader, NULL, TASK, 0, "reader");
if (thrd)
thread_ready(thrd);
else
failed();
}
thread_t *thrd;
context_save(&ctx);
printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in);
k = random(7) + 1;
printf("Creating %d readers\n", k);
for (i = 0; i < k; i++) {
thrd = thread_create(reader, NULL, TASK, 0, "reader");
if (thrd)
thread_ready(thrd);
else
printf("Could not create reader %d\n", i);
}
 
k = random(5) + 1;
printf("Creating %d writers\n", k);
for (i=0; i<k; i++) {
thrd = thread_create(writer, NULL, TASK, 0, "writer");
if (thrd)
thread_ready(thrd);
else
failed();
}
thread_usleep(20000);
waitq_wakeup(&can_start, WAKEUP_ALL);
}
 
k = random(5) + 1;
printf("Creating %d writers\n", k);
for (i=0; i<k; i++) {
thrd = thread_create(writer, NULL, TASK, 0, "writer");
if (thrd)
thread_ready(thrd);
else
printf("Could not create writer %d\n", i);
}
thread_usleep(20000);
waitq_wakeup(&can_start, WAKEUP_ALL);
return NULL;
}
/trunk/kernel/test/synch/semaphore2.c
47,11 → 47,6
 
static uint32_t seed = 0xdeadbeef;
 
static uint32_t random(uint32_t max);
 
static void consumer(void *arg);
static void failed(void);
 
static uint32_t random(uint32_t max)
{
uint32_t rc;
63,7 → 58,6
return rc;
}
 
 
static void consumer(void *arg)
{
int rc, to;
87,38 → 81,27
printf("cpu%d, tid %d up\n", CPU->id, THREAD->tid);
}
 
static void failed(void)
char * test_semaphore2(void)
{
printf("Test failed prematurely.\n");
thread_exit();
}
 
void test_semaphore2(void)
{
uint32_t i, k;
printf("Semaphore test #2\n");
waitq_initialize(&can_start);
semaphore_initialize(&sem, 5);
 
thread_t *thrd;
for (; ;) {
thread_t *thrd;
k = random(7) + 1;
printf("Creating %d consumers\n", k);
for (i=0; i<k; i++) {
thrd = thread_create(consumer, NULL, TASK, 0, "consumer");
if (thrd)
thread_ready(thrd);
else
failed();
}
thread_usleep(20000);
waitq_wakeup(&can_start, WAKEUP_ALL);
}
 
k = random(7) + 1;
printf("Creating %d consumers\n", k);
for (i = 0; i < k; i++) {
thrd = thread_create(consumer, NULL, TASK, 0, "consumer");
if (thrd)
thread_ready(thrd);
else
printf("Error creating thread\n");
}
thread_usleep(20000);
waitq_wakeup(&can_start, WAKEUP_ALL);
return NULL;
}
/trunk/kernel/test/synch/rwlock5.c
44,11 → 44,7
static atomic_t items_read;
static atomic_t items_written;
 
static void writer(void *arg);
static void reader(void *arg);
static void failed(void);
 
void writer(void *arg)
static void writer(void *arg)
{
thread_detach(THREAD);
 
59,7 → 55,7
rwlock_write_unlock(&rwlock);
}
 
void reader(void *arg)
static void reader(void *arg)
{
thread_detach(THREAD);
 
70,47 → 66,39
rwlock_read_unlock(&rwlock);
}
 
void failed(void)
char * test_rwlock5(void)
{
printf("Test failed prematurely.\n");
thread_exit();
}
 
void test_rwlock5(void)
{
int i, j, k;
count_t readers, writers;
printf("Read/write locks test #5\n");
waitq_initialize(&can_start);
rwlock_initialize(&rwlock);
for (i=1; i<=3; i++) {
for (i = 1; i <= 3; i++) {
thread_t *thrd;
 
atomic_set(&items_read, 0);
atomic_set(&items_written, 0);
 
readers = i*READERS;
writers = (4-i)*WRITERS;
readers = i * READERS;
writers = (4 - i) * WRITERS;
 
printf("Creating %ld readers and %ld writers...", readers, writers);
for (j=0; j<(READERS+WRITERS)/2; j++) {
for (k=0; k<i; k++) {
for (j = 0; j < (READERS + WRITERS) / 2; j++) {
for (k = 0; k < i; k++) {
thrd = thread_create(reader, NULL, TASK, 0, "reader");
if (thrd)
thread_ready(thrd);
else
failed();
printf("Could not create reader %d\n", k);
}
for (k=0; k<(4-i); k++) {
for (k = 0; k < (4 - i); k++) {
thrd = thread_create(writer, NULL, TASK, 0, "writer");
if (thrd)
thread_ready(thrd);
else
failed();
printf("Could not create writer %d\n", k);
}
}
 
119,10 → 107,11
thread_sleep(1);
waitq_wakeup(&can_start, WAKEUP_ALL);
while (items_read.count != readers || items_written.count != writers) {
while ((items_read.count != readers) || (items_written.count != writers)) {
printf("%zd readers remaining, %zd writers remaining, readers_in=%zd\n", readers - items_read.count, writers - items_written.count, rwlock.readers_in);
thread_usleep(100000);
}
}
printf("Test passed.\n");
return NULL;
}
/trunk/kernel/test/test.h
54,22 → 54,22
extern char * test_fpu1(void);
extern char * test_sse1(void);
extern char * test_mips2(void);
extern void test_falloc1(void);
extern void test_falloc2(void);
extern void test_mapping1(void);
extern void test_purge1(void);
extern void test_slab1(void);
extern void test_slab2(void);
extern void test_rwlock1(void);
extern void test_rwlock2(void);
extern void test_rwlock3(void);
extern void test_rwlock4(void);
extern void test_rwlock5(void);
extern void test_semaphore1(void);
extern void test_semaphore2(void);
extern void test_print1(void);
extern void test_thread1(void);
extern void test_sysinfo1(void);
extern char * test_falloc1(void);
extern char * test_falloc2(void);
extern char * test_mapping1(void);
extern char * test_purge1(void);
extern char * test_slab1(void);
extern char * test_slab2(void);
extern char * test_rwlock1(void);
extern char * test_rwlock2(void);
extern char * test_rwlock3(void);
extern char * test_rwlock4(void);
extern char * test_rwlock5(void);
extern char * test_semaphore1(void);
extern char * test_semaphore2(void);
extern char * test_print1(void);
extern char * test_thread1(void);
extern char * test_sysinfo1(void);
 
extern test_t tests[];
 
/trunk/kernel/test/thread/thread1.def
0,0 → 1,6
{
"thread1",
"Thread test",
&test_thread1,
true
},
/trunk/kernel/test/thread/thread1.c
39,24 → 39,45
 
#define THREADS 5
 
static atomic_t finish;
static atomic_t threads_finished;
 
static void threadtest(void *data)
{
 
thread_detach(THREAD);
 
while (1)
printf("%d\n",(int)(THREAD->tid));
while (atomic_get(&finish)) {
printf("%d\n", (int) (THREAD->tid));
thread_usleep(100);
}
atomic_inc(&threads_finished);
}
 
void test_thread1(void)
char * test_thread1(void)
{
thread_t *t;
int i;
unsigned int i, total = 0;
atomic_set(&finish, 1);
atomic_set(&threads_finished, 0);
 
for (i=0; i<THREADS; i++) {
if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest")))
panic("could not create thread\n");
for (i = 0; i < THREADS; i++) {
thread_t *t;
if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest"))) {
printf("Could not create thread %d\n", i);
break;
}
thread_ready(t);
total++;
}
printf("ok\n");
printf("Running threads for 10 seconds...\n");
thread_sleep(10);
atomic_set(&finish, 0);
while (atomic_get(&threads_finished) < total) {
printf("Threads left: %d\n", total - atomic_get(&threads_finished));
thread_sleep(1);
}
return NULL;
}
/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
},
/trunk/kernel/test/sysinfo/sysinfo1.def
0,0 → 1,6
{
"sysinfo1",
"Sysinfo test",
&test_sysinfo1,
true
},
/trunk/kernel/test/sysinfo/sysinfo1.c
32,23 → 32,9
 
#include <test.h>
#include <sysinfo/sysinfo.h>
/*
static unative_t counter(sysinfo_item_t *root)
{
static unative_t i=0;
return i++;
}*/
 
void test_sysinfo1(void)
char * test_sysinfo1(void)
{
/* sysinfo_set_item_val("Ahoj.lidi.uaaaa",NULL,9);
sysinfo_set_item_val("Ahoj.lidi.ubbbb",NULL,15);
sysinfo_set_item_val("Ahoj.lidi",NULL,64);
sysinfo_set_item_function("Ahoj",NULL,counter);
sysinfo_dump(NULL,0);
sysinfo_set_item_val("Ahoj.lidi.ubbbb",NULL,75);
sysinfo_dump(NULL,0);
sysinfo_dump(NULL,0);
sysinfo_dump(NULL,0);*/
sysinfo_dump(NULL,0);
sysinfo_dump(NULL, 0);
return NULL;
}
/trunk/kernel/test/print/print1.def
0,0 → 1,6
{
"print1",
"Printf test",
&test_print1,
true
},
/trunk/kernel/test/print/print1.c
30,7 → 30,7
 
#define BUFFER_SIZE 32
 
void test_print1(void)
char * test_print1(void)
{
int retval;
unative_t nat = 0x12345678u;
37,8 → 37,6
char buffer[BUFFER_SIZE];
printf(" Printf test \n");
printf(" text 10.8s %*.*s \n", 5, 3, "text");
printf(" very long text 10.8s %10.8s \n", "very long text");
printf(" text 8.10s %8.10s \n", "text");
51,7 → 49,7
 
printf("'%#llx' 64bit, '%#x' 32bit, '%#hhx' 8bit, '%#hx' 16bit, unative_t '%#zx'. '%#llx' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, nat, 0x1234567887654321ull, "Lovely string" );
printf(" Print to NULL '%s'\n",NULL);
printf(" Print to NULL '%s'\n", NULL);
 
retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters.");
printf("Result is: '%s', retval = %d\n", buffer, retval);
67,5 → 65,5
retval = snprintf(buffer, BUFFER_SIZE, "Very long %s. This text`s length is more than %d. We are interested in the result.", "text" , BUFFER_SIZE);
printf("Result is: '%s', retval = %d\n", buffer, retval);
return;
return NULL;
}