Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2027 → Rev 2028

/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;
}