Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2052 → Rev 2053

/trunk/kernel/test/synch/rwlock1.c
59,7 → 59,6
rwlock_read_unlock(&rwlock);
rwlock_read_unlock(&rwlock);
rwlock_write_lock(&rwlock);
rwlock_write_unlock(&rwlock);
 
/trunk/kernel/test/synch/rwlock2.c
38,26 → 38,27
#define WRITERS 50
 
static rwlock_t rwlock;
static bool sh_quiet;
 
static void writer(void *arg)
{
 
thread_detach(THREAD);
 
printf("Trying to lock rwlock for writing....\n");
 
if (!sh_quiet)
printf("Trying to lock rwlock for writing....\n");
rwlock_write_lock(&rwlock);
rwlock_write_unlock(&rwlock);
printf("Trying to lock rwlock for reading....\n");
if (!sh_quiet)
printf("Trying to lock rwlock for reading....\n");
rwlock_read_lock(&rwlock);
rwlock_read_unlock(&rwlock);
printf("Test passed.\n");
}
 
char * test_rwlock2(bool quiet)
{
thread_t *thrd;
sh_quiet = quiet;
rwlock_initialize(&rwlock);
 
79,5 → 80,8
rwlock_read_unlock(&rwlock);
rwlock_read_unlock(&rwlock);
thread_join(thrd);
thread_detach(thrd);
return NULL;
}
/trunk/kernel/test/synch/rwlock3.c
34,25 → 34,34
 
#include <synch/rwlock.h>
 
#define READERS 50
#define WRITERS 50
#define THREADS 4
 
static atomic_t thread_count;
static rwlock_t rwlock;
static bool sh_quiet;
 
static void reader(void *arg)
{
thread_detach(THREAD);
 
printf("cpu%d, tid %d: trying to lock rwlock for reading....\n", CPU->id, THREAD->tid);
if (!sh_quiet)
printf("cpu%d, tid %d: trying to lock rwlock for reading....\n", CPU->id, THREAD->tid);
rwlock_read_lock(&rwlock);
rwlock_read_unlock(&rwlock);
printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid);
rwlock_read_unlock(&rwlock);
if (!sh_quiet) {
printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid);
printf("cpu%d, tid %d: trying to lock rwlock for writing....\n", CPU->id, THREAD->tid);
}
 
printf("cpu%d, tid %d: trying to lock rwlock for writing....\n", CPU->id, THREAD->tid);
 
rwlock_write_lock(&rwlock);
rwlock_write_unlock(&rwlock);
printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid);
if (!sh_quiet)
printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid);
atomic_dec(&thread_count);
}
 
char * test_rwlock3(bool quiet)
59,21 → 68,29
{
int i;
thread_t *thrd;
sh_quiet = quiet;
atomic_set(&thread_count, THREADS);
rwlock_initialize(&rwlock);
rwlock_write_lock(&rwlock);
for (i = 0; i < 4; i++) {
for (i = 0; i < THREADS; i++) {
thrd = thread_create(reader, NULL, TASK, 0, "reader", false);
if (thrd)
thread_ready(thrd);
else
else if (!quiet)
printf("Could not create reader %d\n", i);
}
 
thread_sleep(1);
rwlock_write_unlock(&rwlock);
while (atomic_get(&thread_count) > 0) {
if (!quiet)
printf("Threads left: %d\n", atomic_get(&thread_count));
thread_sleep(1);
}
return NULL;
}
/trunk/kernel/test/synch/rwlock4.c
43,8 → 43,10
#define READERS 50
#define WRITERS 50
 
static atomic_t thread_count;
static rwlock_t rwlock;
static atomic_t threads_fault;
static bool sh_quiet;
 
SPINLOCK_INITIALIZE(rw_lock);
 
70,28 → 72,42
waitq_sleep(&can_start);
 
to = random(40000);
printf("cpu%d, tid %d w+ (%d)\n", CPU->id, THREAD->tid, to);
if (!sh_quiet)
printf("cpu%d, tid %d w+ (%d)\n", CPU->id, THREAD->tid, to);
rc = rwlock_write_lock_timeout(&rwlock, to);
if (SYNCH_FAILED(rc)) {
printf("cpu%d, tid %d w!\n", CPU->id, THREAD->tid);
if (!sh_quiet)
printf("cpu%d, tid %d w!\n", CPU->id, THREAD->tid);
atomic_dec(&thread_count);
return;
}
printf("cpu%d, tid %d w=\n", CPU->id, THREAD->tid);
if (!sh_quiet)
printf("cpu%d, tid %d w=\n", CPU->id, THREAD->tid);
 
if (rwlock.readers_in) {
printf("Oops.");
if (!sh_quiet)
printf("Oops.");
atomic_inc(&threads_fault);
atomic_dec(&thread_count);
return;
}
thread_usleep(random(1000000));
if (rwlock.readers_in) {
printf("Oops.");
if (!sh_quiet)
printf("Oops.");
atomic_inc(&threads_fault);
atomic_dec(&thread_count);
return;
}
 
rwlock_write_unlock(&rwlock);
printf("cpu%d, tid %d w-\n", CPU->id, THREAD->tid);
if (!sh_quiet)
printf("cpu%d, tid %d w-\n", CPU->id, THREAD->tid);
atomic_dec(&thread_count);
}
 
static void reader(void *arg)
101,49 → 117,68
waitq_sleep(&can_start);
to = random(2000);
printf("cpu%d, tid %d r+ (%d)\n", CPU->id, THREAD->tid, to);
if (!sh_quiet)
printf("cpu%d, tid %d r+ (%d)\n", CPU->id, THREAD->tid, to);
rc = rwlock_read_lock_timeout(&rwlock, to);
if (SYNCH_FAILED(rc)) {
printf("cpu%d, tid %d r!\n", CPU->id, THREAD->tid);
if (!sh_quiet)
printf("cpu%d, tid %d r!\n", CPU->id, THREAD->tid);
atomic_dec(&thread_count);
return;
}
printf("cpu%d, tid %d r=\n", CPU->id, THREAD->tid);
if (!sh_quiet)
printf("cpu%d, tid %d r=\n", CPU->id, THREAD->tid);
thread_usleep(30000);
rwlock_read_unlock(&rwlock);
printf("cpu%d, tid %d r-\n", CPU->id, THREAD->tid);
if (!sh_quiet)
printf("cpu%d, tid %d r-\n", CPU->id, THREAD->tid);
atomic_dec(&thread_count);
}
 
char * test_rwlock4(bool quiet)
{
context_t ctx;
uint32_t i, k;
uint32_t i;
sh_quiet = quiet;
waitq_initialize(&can_start);
rwlock_initialize(&rwlock);
atomic_set(&threads_fault, 0);
uint32_t rd = random(7) + 1;
uint32_t wr = random(5) + 1;
atomic_set(&thread_count, rd + wr);
thread_t *thrd;
context_save(&ctx);
printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in);
if (!quiet) {
printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in);
printf("Creating %d readers\n", rd);
}
k = random(7) + 1;
printf("Creating %d readers\n", k);
for (i = 0; i < k; i++) {
for (i = 0; i < rd; i++) {
thrd = thread_create(reader, NULL, TASK, 0, "reader", false);
if (thrd)
thread_ready(thrd);
else
else if (!quiet)
printf("Could not create reader %d\n", i);
}
 
k = random(5) + 1;
printf("Creating %d writers\n", k);
for (i = 0; i < k; i++) {
if (!quiet)
printf("Creating %d writers\n", wr);
for (i = 0; i < wr; i++) {
thrd = thread_create(writer, NULL, TASK, 0, "writer", false);
if (thrd)
thread_ready(thrd);
else
else if (!quiet)
printf("Could not create writer %d\n", i);
}
150,6 → 185,12
thread_usleep(20000);
waitq_wakeup(&can_start, WAKEUP_ALL);
while (atomic_get(&thread_count) > 0) {
if (!quiet)
printf("Threads left: %d\n", atomic_get(&thread_count));
thread_sleep(1);
}
if (atomic_get(&threads_fault) == 0)
return NULL;
/trunk/kernel/test/thread/thread1.c
40,6 → 40,7
 
static atomic_t finish;
static atomic_t threads_finished;
static bool sh_quiet;
 
static void threadtest(void *data)
{
46,7 → 47,8
thread_detach(THREAD);
 
while (atomic_get(&finish)) {
printf("%d\n", (int) (THREAD->tid));
if (!sh_quiet)
printf("%d\n", (int) (THREAD->tid));
thread_usleep(100);
}
atomic_inc(&threads_finished);
55,6 → 57,7
char * test_thread1(bool quiet)
{
unsigned int i, total = 0;
sh_quiet = quiet;
atomic_set(&finish, 1);
atomic_set(&threads_finished, 0);
62,7 → 65,8
for (i = 0; i < THREADS; i++) {
thread_t *t;
if (!(t = thread_create(threadtest, NULL, TASK, 0, "threadtest", false))) {
printf("Could not create thread %d\n", i);
if (!quiet)
printf("Could not create thread %d\n", i);
break;
}
thread_ready(t);
69,12 → 73,14
total++;
}
printf("Running threads for 10 seconds...\n");
if (!quiet)
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));
if (!quiet)
printf("Threads left: %d\n", total - atomic_get(&threads_finished));
thread_sleep(1);
}
/trunk/kernel/test/mm/falloc1.c
55,13 → 55,16
 
for (run = 0; run < TEST_RUNS; run++) {
for (order = 0; order <= MAX_ORDER; order++) {
printf("Allocating %d frames blocks ... ", 1 << order);
if (!quiet)
printf("Allocating %d frames blocks ... ", 1 << order);
allocated = 0;
for (i = 0; i < MAX_FRAMES >> order; i++) {
frames[allocated] = (uintptr_t) frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) != frames[allocated]) {
printf("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10);
if (!quiet)
printf("Block at address %p (size %dK) is not aligned\n", frames[allocated], (FRAME_SIZE << order) >> 10);
return "Test failed";
}
68,12 → 71,14
if (frames[allocated])
allocated++;
else {
printf("done. ");
if (!quiet)
printf("done. ");
break;
}
}
printf("%d blocks allocated.\n", allocated);
if (!quiet)
printf("%d blocks allocated.\n", allocated);
if (run) {
if (results[order] != allocated)
81,10 → 86,14
} else
results[order] = allocated;
printf("Deallocating ... ");
if (!quiet)
printf("Deallocating ... ");
for (i = 0; i < allocated; i++)
frame_free(KA2PA(frames[i]));
printf("done.\n");
if (!quiet)
printf("done.\n");
}
}
 
/trunk/kernel/test/mm/falloc2.c
47,6 → 47,7
 
static atomic_t thread_count;
static atomic_t thread_fail;
static bool sh_quiet;
 
static void falloc(void * arg)
{
56,7 → 57,8
uintptr_t * frames = (uintptr_t *) malloc(MAX_FRAMES * sizeof(uintptr_t), FRAME_ATOMIC);
if (frames == NULL) {
printf("Thread #%d (cpu%d): Unable to allocate frames\n", THREAD->tid, CPU->id);
if (!sh_quiet)
printf("Thread #%d (cpu%d): Unable to allocate frames\n", THREAD->tid, CPU->id);
atomic_inc(&thread_fail);
atomic_dec(&thread_count);
return;
66,7 → 68,9
 
for (run = 0; run < THREAD_RUNS; run++) {
for (order = 0; order <= MAX_ORDER; order++) {
printf("Thread #%d (cpu%d): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order);
if (!sh_quiet)
printf("Thread #%d (cpu%d): Allocating %d frames blocks ... \n", THREAD->tid, CPU->id, 1 << order);
allocated = 0;
for (i = 0; i < (MAX_FRAMES >> order); i++) {
frames[allocated] = (uintptr_t)frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
76,13 → 80,18
} else
break;
}
printf("Thread #%d (cpu%d): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated);
 
printf("Thread #%d (cpu%d): Deallocating ... \n", THREAD->tid, CPU->id);
if (!sh_quiet)
printf("Thread #%d (cpu%d): %d blocks allocated.\n", THREAD->tid, CPU->id, allocated);
if (!sh_quiet)
printf("Thread #%d (cpu%d): Deallocating ... \n", THREAD->tid, CPU->id);
for (i = 0; i < allocated; i++) {
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);
if (!sh_quiet)
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);
atomic_inc(&thread_fail);
goto cleanup;
}
89,13 → 98,17
}
frame_free(KA2PA(frames[i]));
}
printf("Thread #%d (cpu%d): Finished run.\n", THREAD->tid, CPU->id);
if (!sh_quiet)
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);
if (!sh_quiet)
printf("Thread #%d (cpu%d): Exiting\n", THREAD->tid, CPU->id);
atomic_dec(&thread_count);
}
 
102,6 → 115,7
char * test_falloc2(bool quiet)
{
unsigned int i;
sh_quiet = quiet;
 
atomic_set(&thread_count, THREADS);
atomic_set(&thread_fail, 0);
109,7 → 123,8
for (i = 0; i < THREADS; i++) {
thread_t * thrd = thread_create(falloc, NULL, TASK, 0, "falloc", false);
if (!thrd) {
printf("Could not create thread %d\n", i);
if (!quiet)
printf("Could not create thread %d\n", i);
break;
}
thread_ready(thrd);
116,7 → 131,8
}
while (atomic_get(&thread_count) > 0) {
printf("Threads left: %d\n", atomic_get(&thread_count));
if (!quiet)
printf("Threads left: %d\n", atomic_get(&thread_count));
thread_sleep(1);
}
/trunk/kernel/test/mm/slab1.c
37,65 → 37,87
 
static void * data[VAL_COUNT];
 
static void testit(int size, int count)
static void testit(int size, int count, bool quiet)
{
slab_cache_t *cache;
int i;
printf("Creating cache, object size: %d.\n", size);
cache = slab_cache_create("test_cache", size, 0, NULL, NULL,
SLAB_CACHE_NOMAGAZINE);
printf("Allocating %d items...", count);
if (!quiet)
printf("Creating cache, object size: %d.\n", size);
cache = slab_cache_create("test_cache", size, 0, NULL, NULL,
SLAB_CACHE_NOMAGAZINE);
if (!quiet)
printf("Allocating %d items...", count);
for (i = 0; i < count; i++) {
data[i] = slab_alloc(cache, 0);
memsetb((uintptr_t) data[i], size, 0);
}
printf("done.\n");
printf("Freeing %d items...", count);
for (i = 0; i < count; i++) {
if (!quiet) {
printf("done.\n");
printf("Freeing %d items...", count);
}
for (i = 0; i < count; i++)
slab_free(cache, data[i]);
if (!quiet) {
printf("done.\n");
printf("Allocating %d items...", count);
}
printf("done.\n");
 
printf("Allocating %d items...", count);
for (i = 0; i < count; i++) {
data[i] = slab_alloc(cache, 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--) {
if (!quiet) {
printf("done.\n");
printf("Freeing %d items...", count / 2);
}
for (i = count - 1; i >= count / 2; i--)
slab_free(cache, data[i]);
if (!quiet) {
printf("done.\n");
printf("Allocating %d items...", count / 2);
}
printf("done.\n");
 
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);
}
printf("done.\n");
printf("Freeing %d items...", count);
for (i = 0; i < count; i++) {
if (!quiet) {
printf("done.\n");
printf("Freeing %d items...", count);
}
for (i = 0; i < count; i++)
slab_free(cache, data[i]);
}
printf("done.\n");
if (!quiet)
printf("done.\n");
slab_cache_destroy(cache);
 
printf("Test complete.\n");
if (!quiet)
printf("Test complete.\n");
}
 
static void testsimple(void)
static void testsimple(bool quiet)
{
testit(100, VAL_COUNT);
testit(200, VAL_COUNT);
testit(1024, VAL_COUNT);
testit(2048, 512);
testit(4000, 128);
testit(8192, 128);
testit(16384, 128);
testit(16385, 128);
testit(100, VAL_COUNT, quiet);
testit(200, VAL_COUNT, quiet);
testit(1024, VAL_COUNT, quiet);
testit(2048, 512, quiet);
testit(4000, 128, quiet);
testit(8192, 128, quiet);
testit(16384, 128, quiet);
testit(16385, 128, quiet);
}
 
#define THREADS 6
105,6 → 127,7
static void * thr_data[THREADS][THR_MEM_COUNT];
static slab_cache_t *thr_cache;
static semaphore_t thr_sem;
static bool sh_quiet;
 
static void slabtest(void *data)
{
113,7 → 136,9
thread_detach(THREAD);
printf("Starting thread #%d...\n",THREAD->tid);
if (!sh_quiet)
printf("Starting thread #%d...\n", THREAD->tid);
for (j = 0; j < 10; j++) {
for (i = 0; i < THR_MEM_COUNT; i++)
thr_data[offs][i] = slab_alloc(thr_cache,0);
124,23 → 149,26
for (i = 0; i < THR_MEM_COUNT; i++)
slab_free(thr_cache, thr_data[offs][i]);
}
printf("Thread #%d finished\n", THREAD->tid);
if (!sh_quiet)
printf("Thread #%d finished\n", THREAD->tid);
semaphore_up(&thr_sem);
}
 
static void testthreads(void)
static void testthreads(bool quiet)
{
thread_t *t;
int i;
 
thr_cache = slab_cache_create("thread_cache", THR_MEM_SIZE, 0,
NULL, NULL,
SLAB_CACHE_NOMAGAZINE);
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", false)))
printf("Could not create thread %d\n", i);
else
if (!(t = thread_create(slabtest, (void *) (unative_t) i, TASK, 0, "slabtest", false))) {
if (!quiet)
printf("Could not create thread %d\n", i);
} else
thread_ready(t);
}
 
148,14 → 176,17
semaphore_down(&thr_sem);
slab_cache_destroy(thr_cache);
printf("Test complete.\n");
if (!quiet)
printf("Test complete.\n");
}
 
char * test_slab1(bool quiet)
{
testsimple();
testthreads();
sh_quiet = quiet;
testsimple(quiet);
testthreads(quiet);
return NULL;
}
/trunk/kernel/test/mm/slab2.c
42,7 → 42,7
* free one of the caches. We should have everything in magazines,
* now allocation should clean magazines and allow for full allocation.
*/
static void totalmemtest(void)
static void totalmemtest(bool quiet)
{
slab_cache_t *cache1;
slab_cache_t *cache2;
49,68 → 49,84
int i;
 
void *data1, *data2;
void *olddata1=NULL, *olddata2=NULL;
void *olddata1 = NULL, *olddata2 = NULL;
cache1 = slab_cache_create("cache1_tst", ITEM_SIZE, 0, NULL, NULL, 0);
cache2 = slab_cache_create("cache2_tst", ITEM_SIZE, 0, NULL, NULL, 0);
 
printf("Allocating...");
if (!quiet)
printf("Allocating...");
/* Use atomic alloc, so that we find end of memory */
do {
data1 = slab_alloc(cache1, FRAME_ATOMIC);
data2 = slab_alloc(cache2, FRAME_ATOMIC);
if (!data1 || !data2) {
if ((!data1) || (!data2)) {
if (data1)
slab_free(cache1,data1);
slab_free(cache1, data1);
if (data2)
slab_free(cache2,data2);
slab_free(cache2, data2);
break;
}
memsetb((uintptr_t)data1, ITEM_SIZE, 0);
memsetb((uintptr_t)data2, ITEM_SIZE, 0);
*((void **)data1) = olddata1;
*((void **)data2) = olddata2;
memsetb((uintptr_t) data1, ITEM_SIZE, 0);
memsetb((uintptr_t) data2, ITEM_SIZE, 0);
*((void **) data1) = olddata1;
*((void **) data2) = olddata2;
olddata1 = data1;
olddata2 = data2;
} while(1);
printf("done.\n");
} while (1);
if (!quiet) {
printf("done.\n");
printf("Deallocating cache2...");
}
/* We do not have memory - now deallocate cache2 */
printf("Deallocating cache2...");
while (olddata2) {
data2 = *((void **)olddata2);
data2 = *((void **) olddata2);
slab_free(cache2, olddata2);
olddata2 = data2;
}
printf("done.\n");
 
printf("Allocating to cache1...\n");
for (i=0; i<30; i++) {
if (!quiet) {
printf("done.\n");
printf("Allocating to cache1...\n");
}
for (i = 0; i < 30; i++) {
data1 = slab_alloc(cache1, FRAME_ATOMIC);
if (!data1) {
printf("Incorrect memory size - use another test.");
if (!quiet)
printf("Incorrect memory size - use another test.");
return;
}
memsetb((uintptr_t)data1, ITEM_SIZE, 0);
*((void **)data1) = olddata1;
memsetb((uintptr_t) data1, ITEM_SIZE, 0);
*((void **) data1) = olddata1;
olddata1 = data1;
}
while (1) {
data1 = slab_alloc(cache1, FRAME_ATOMIC);
if (!data1) {
if (!data1)
break;
}
memsetb((uintptr_t)data1, ITEM_SIZE, 0);
*((void **)data1) = olddata1;
memsetb((uintptr_t) data1, ITEM_SIZE, 0);
*((void **) data1) = olddata1;
olddata1 = data1;
}
printf("Deallocating cache1...");
if (!quiet)
printf("Deallocating cache1...");
while (olddata1) {
data1 = *((void **)olddata1);
data1 = *((void **) olddata1);
slab_free(cache1, olddata1);
olddata1 = data1;
}
printf("done.\n");
slab_print_list();
if (!quiet) {
printf("done.\n");
slab_print_list();
}
slab_cache_destroy(cache1);
slab_cache_destroy(cache2);
}
119,6 → 135,7
static semaphore_t thr_sem;
static condvar_t thread_starter;
static mutex_t starter_mutex;
static bool sh_quiet;
 
#define THREADS 8
 
125,55 → 142,69
static void slabtest(void *priv)
{
void *data = NULL, *new;
 
thread_detach(THREAD);
 
mutex_lock(&starter_mutex);
condvar_wait(&thread_starter,&starter_mutex);
mutex_unlock(&starter_mutex);
printf("Starting thread #%d...\n",THREAD->tid);
if (!sh_quiet)
printf("Starting thread #%d...\n",THREAD->tid);
 
/* Alloc all */
printf("Thread #%d allocating...\n", THREAD->tid);
if (!sh_quiet)
printf("Thread #%d allocating...\n", THREAD->tid);
while (1) {
/* Call with atomic to detect end of memory */
new = slab_alloc(thr_cache, FRAME_ATOMIC);
if (!new)
break;
*((void **)new) = data;
*((void **) new) = data;
data = new;
}
printf("Thread #%d releasing...\n", THREAD->tid);
if (!sh_quiet)
printf("Thread #%d releasing...\n", THREAD->tid);
while (data) {
new = *((void **)data);
*((void **)data) = NULL;
*((void **) data) = NULL;
slab_free(thr_cache, data);
data = new;
}
printf("Thread #%d allocating...\n", THREAD->tid);
if (!sh_quiet)
printf("Thread #%d allocating...\n", THREAD->tid);
while (1) {
/* Call with atomic to detect end of memory */
new = slab_alloc(thr_cache, FRAME_ATOMIC);
if (!new)
break;
*((void **)new) = data;
*((void **) new) = data;
data = new;
}
printf("Thread #%d releasing...\n", THREAD->tid);
if (!sh_quiet)
printf("Thread #%d releasing...\n", THREAD->tid);
while (data) {
new = *((void **)data);
*((void **)data) = NULL;
*((void **) data) = NULL;
slab_free(thr_cache, data);
data = new;
}
 
printf("Thread #%d finished\n", THREAD->tid);
if (!sh_quiet)
printf("Thread #%d finished\n", THREAD->tid);
slab_print_list();
semaphore_up(&thr_sem);
}
 
static void multitest(int size)
static void multitest(int size, bool quiet)
{
/* Start 8 threads that just allocate as much as possible,
* then release everything, then again allocate, then release
180,19 → 211,20
*/
thread_t *t;
int i;
 
printf("Running stress test with size %d\n", size);
if (!quiet)
printf("Running stress test with size %d\n", size);
condvar_initialize(&thread_starter);
mutex_initialize(&starter_mutex);
 
thr_cache = slab_cache_create("thread_cache", size, 0,
NULL, NULL,
0);
thr_cache = slab_cache_create("thread_cache", size, 0, NULL, NULL, 0);
semaphore_initialize(&thr_sem,0);
for (i = 0; i < THREADS; i++) {
if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false)))
printf("Could not create thread %d\n", i);
else
if (!(t = thread_create(slabtest, NULL, TASK, 0, "slabtest", false))) {
if (!quiet)
printf("Could not create thread %d\n", i);
} else
thread_ready(t);
}
thread_sleep(1);
202,21 → 234,26
semaphore_down(&thr_sem);
slab_cache_destroy(thr_cache);
printf("Stress test complete.\n");
if (!quiet)
printf("Stress test complete.\n");
}
 
char * test_slab2(bool quiet)
{
printf("Running reclaim single-thread test .. pass 1\n");
totalmemtest();
printf("Running reclaim single-thread test .. pass 2\n");
totalmemtest();
printf("Reclaim test OK.\n");
 
multitest(128);
multitest(2048);
multitest(8192);
printf("All done.\n");
sh_quiet = quiet;
if (!quiet)
printf("Running reclaim single-thread test .. pass 1\n");
totalmemtest(quiet);
if (!quiet)
printf("Running reclaim single-thread test .. pass 2\n");
totalmemtest(quiet);
if (!quiet)
printf("Reclaim test OK.\n");
multitest(128, quiet);
multitest(2048, quiet);
multitest(8192, quiet);
return NULL;
}
/trunk/kernel/test/mm/mapping1.c
48,35 → 48,47
 
frame0 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA);
frame1 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA);
 
printf("Writing %#x to physical address %p.\n", VALUE0, KA2PA(frame0));
if (!quiet)
printf("Writing %#x to physical address %p.\n", VALUE0, KA2PA(frame0));
*((uint32_t *) frame0) = VALUE0;
printf("Writing %#x to physical address %p.\n", VALUE1, KA2PA(frame1));
if (!quiet)
printf("Writing %#x to physical address %p.\n", VALUE1, KA2PA(frame1));
*((uint32_t *) frame1) = VALUE1;
printf("Mapping virtual address %p to physical address %p.\n", PAGE0, KA2PA(frame0));
if (!quiet)
printf("Mapping virtual address %p to physical address %p.\n", PAGE0, KA2PA(frame0));
page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE);
printf("Mapping virtual address %p to physical address %p.\n", PAGE1, KA2PA(frame1));
if (!quiet)
printf("Mapping virtual address %p to physical address %p.\n", PAGE1, KA2PA(frame1));
page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE);
printf("Value at virtual address %p is %#x.\n", PAGE0, v0 = *((uint32_t *) PAGE0));
printf("Value at virtual address %p is %#x.\n", PAGE1, v1 = *((uint32_t *) PAGE1));
v0 = *((uint32_t *) PAGE0);
v1 = *((uint32_t *) PAGE1);
if (!quiet) {
printf("Value at virtual address %p is %#x.\n", PAGE0, v0);
printf("Value at virtual address %p is %#x.\n", PAGE1, v1);
}
if (v0 != VALUE0)
return "Value at v0 not equal to VALUE0";
if (v1 != VALUE1)
return "Value at v1 not equal to VALUE1";
 
printf("Writing %#x to virtual address %p.\n", 0, PAGE0);
if (!quiet)
printf("Writing %#x to virtual address %p.\n", 0, PAGE0);
*((uint32_t *) PAGE0) = 0;
printf("Writing %#x to virtual address %p.\n", 0, PAGE1);
if (!quiet)
printf("Writing %#x to virtual address %p.\n", 0, PAGE1);
*((uint32_t *) PAGE1) = 0;
 
v0 = *((uint32_t *) PAGE0);
v1 = *((uint32_t *) PAGE1);
printf("Value at virtual address %p is %#x.\n", PAGE0, *((uint32_t *) PAGE0));
printf("Value at virtual address %p is %#x.\n", PAGE1, *((uint32_t *) PAGE1));
if (!quiet) {
printf("Value at virtual address %p is %#x.\n", PAGE0, *((uint32_t *) PAGE0));
printf("Value at virtual address %p is %#x.\n", PAGE1, *((uint32_t *) PAGE1));
}
 
if (v0 != 0)
return "Value at v0 not equal to 0";
/trunk/kernel/test/fpu/mips2.c
45,6 → 45,7
static atomic_t threads_ok;
static atomic_t threads_fault;
static waitq_t can_start;
static bool sh_quiet;
 
static void testit1(void *data)
{
70,7 → 71,8
);
if (arg != after_arg) {
printf("General reg tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg);
if (!sh_quiet)
printf("General reg tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg);
atomic_inc(&threads_fault);
break;
}
101,7 → 103,8
);
if (arg != after_arg) {
printf("General reg tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg);
if (!sh_quiet)
printf("General reg tid%d: arg(%d) != %d\n", THREAD->tid, arg, after_arg);
atomic_inc(&threads_fault);
break;
}
113,17 → 116,21
char * test_mips2(bool quiet)
{
unsigned int i, total = 0;
sh_quiet = quiet;
waitq_initialize(&can_start);
atomic_set(&threads_ok, 0);
atomic_set(&threads_fault, 0);
printf("Creating %d threads... ", 2 * THREADS);
if (!quiet)
printf("Creating %d threads... ", 2 * THREADS);
 
for (i = 0; i < THREADS; i++) {
thread_t *t;
if (!(t = thread_create(testit1, (void *) ((unative_t) 2 * i), TASK, 0, "testit1", false))) {
printf("could not create thread %d\n", 2 * i);
if (!quiet)
printf("could not create thread %d\n", 2 * i);
break;
}
thread_ready(t);
130,19 → 137,23
total++;
if (!(t = thread_create(testit2, (void *) ((unative_t) 2 * i + 1), TASK, 0, "testit2", false))) {
printf("could not create thread %d\n", 2 * i + 1);
if (!quiet)
printf("could not create thread %d\n", 2 * i + 1);
break;
}
thread_ready(t);
total++;
}
printf("ok\n");
if (!quiet)
printf("ok\n");
thread_sleep(1);
waitq_wakeup(&can_start, WAKEUP_ALL);
while (atomic_get(&threads_ok) != total) {
printf("Threads left: %d\n", total - atomic_get(&threads_ok));
if (!quiet)
printf("Threads left: %d\n", total - atomic_get(&threads_ok));
thread_sleep(1);
}
/trunk/kernel/test/sysinfo/sysinfo1.c
34,6 → 34,7
 
char * test_sysinfo1(bool quiet)
{
sysinfo_dump(NULL, 0);
if (!quiet)
sysinfo_dump(NULL, 0);
return NULL;
}
/trunk/kernel/test/print/print1.c
32,38 → 32,40
 
char * test_print1(bool quiet)
{
int retval;
unative_t nat = 0x12345678u;
if (!quiet) {
int retval;
unative_t nat = 0x12345678u;
char buffer[BUFFER_SIZE];
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");
printf(" very long text 8.10s %8.10s \n", "very long text");
printf(" char: c '%c', 3.2c '%3.2c', -3.2c '%-3.2c', 2.3c '%2.3c', -2.3c '%-2.3c' \n",'a', 'b', 'c', 'd', 'e' );
printf(" int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",1, 1, 1, 1, 1 );
printf(" -int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",-1, -1, -1, -1, -1 );
printf(" 0xint: x '%#x', 5.3x '%#5.3x', -5.3x '%#-5.3x', 3.5x '%#3.5x', -3.5x '%#-3.5x' \n",17, 17, 17, 17, 17 );
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);
retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters.");
printf("Result is: '%s', retval = %d\n", buffer, retval);
retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters.");
printf("Result is: '%s', retval = %d\n", buffer, retval);
printf("Print short text to %d char long buffer via snprintf.\n", BUFFER_SIZE);
retval = snprintf(buffer, BUFFER_SIZE, "Short %s", "text");
printf("Result is: '%s', retval = %d\n", buffer, retval);
printf("Print long text to %d char long buffer via snprintf.\n", BUFFER_SIZE);
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);
}
char buffer[BUFFER_SIZE];
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");
printf(" very long text 8.10s %8.10s \n", "very long text");
 
printf(" char: c '%c', 3.2c '%3.2c', -3.2c '%-3.2c', 2.3c '%2.3c', -2.3c '%-2.3c' \n",'a', 'b', 'c', 'd', 'e' );
printf(" int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",1, 1, 1, 1, 1 );
printf(" -int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",-1, -1, -1, -1, -1 );
printf(" 0xint: x '%#x', 5.3x '%#5.3x', -5.3x '%#-5.3x', 3.5x '%#3.5x', -3.5x '%#-3.5x' \n",17, 17, 17, 17, 17 );
 
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);
 
retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters.");
printf("Result is: '%s', retval = %d\n", buffer, retval);
 
retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters.");
printf("Result is: '%s', retval = %d\n", buffer, retval);
printf("Print short text to %d char long buffer via snprintf.\n", BUFFER_SIZE);
retval = snprintf(buffer, BUFFER_SIZE, "Short %s", "text");
printf("Result is: '%s', retval = %d\n", buffer, retval);
printf("Print long text to %d char long buffer via snprintf.\n", BUFFER_SIZE);
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 NULL;
}