Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 1961 → Rev 1962

/tags/0.1.0/SPARTAN/trunk/test/synch/rwlock4/test.c
0,0 → 1,161
/*
* Copyright (C) 2001-2004 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 <test.h>
#include <arch.h>
#include <arch/atomic.h>
#include <print.h>
#include <proc/thread.h>
#include <arch/types.h>
#include <arch/context.h>
#include <context.h>
#include <panic.h>
 
#include <synch/waitq.h>
#include <synch/rwlock.h>
#include <synch/synch.h>
 
#define READERS 50
#define WRITERS 50
 
static rwlock_t rwlock;
 
static spinlock_t lock;
 
static waitq_t can_start;
 
__u32 seed = 0xdeadbeaf;
 
static __u32 random(__u32 max);
 
static void writer(void *arg);
static void reader(void *arg);
static void failed(void);
 
__u32 random(__u32 max)
{
__u32 rc;
ipl_t ipl;
 
spinlock_lock(&lock);
rc = seed % max;
seed = (((seed<<2) ^ (seed>>2)) * 487) + rc;
spinlock_unlock(&lock);
return rc;
}
 
 
void writer(void *arg)
{
int rc, to;
waitq_sleep(&can_start);
 
to = random(40000);
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);
return;
};
printf("cpu%d, tid %d w=\n", CPU->id, THREAD->tid);
 
if (rwlock.readers_in) panic("Oops.");
thread_usleep(random(1000000));
if (rwlock.readers_in) panic("Oops.");
 
rwlock_write_unlock(&rwlock);
printf("cpu%d, tid %d w-\n", CPU->id, THREAD->tid);
}
 
void reader(void *arg)
{
int rc, to;
waitq_sleep(&can_start);
to = random(2000);
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);
return;
}
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);
}
 
void failed(void)
{
printf("Test failed prematurely.\n");
thread_exit();
}
 
void test(void)
{
context_t ctx;
__u32 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);
if (thrd)
thread_ready(thrd);
else
failed();
}
 
k = random(5) + 1;
printf("Creating %d writers\n", k);
for (i=0; i<k; i++) {
thrd = thread_create(writer, NULL, TASK, 0);
if (thrd)
thread_ready(thrd);
else
failed();
}
thread_usleep(20000);
waitq_wakeup(&can_start, WAKEUP_ALL);
}
 
}
/tags/0.1.0/SPARTAN/trunk/test/synch/rwlock2/test.c
0,0 → 1,91
/*
* Copyright (C) 2001-2004 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 <test.h>
#include <arch.h>
#include <arch/atomic.h>
#include <print.h>
#include <proc/thread.h>
 
#include <synch/rwlock.h>
 
#define READERS 50
#define WRITERS 50
 
static rwlock_t rwlock;
 
static void writer(void *arg);
static void failed(void);
 
void writer(void *arg)
{
printf("Trying to lock rwlock for writing....\n");
 
rwlock_write_lock(&rwlock);
rwlock_write_unlock(&rwlock);
printf("Trying to lock rwlock for reading....\n");
rwlock_read_lock(&rwlock);
rwlock_read_unlock(&rwlock);
printf("Test passed.\n");
}
 
void failed()
{
printf("Test failed prematurely.\n");
thread_exit();
}
 
void test(void)
{
thread_t *thrd;
printf("Read/write locks test #2\n");
rwlock_initialize(&rwlock);
 
rwlock_read_lock(&rwlock);
rwlock_read_lock(&rwlock);
rwlock_read_lock(&rwlock);
rwlock_read_lock(&rwlock);
thrd = thread_create(writer, NULL, TASK, 0);
if (thrd)
thread_ready(thrd);
else
failed();
 
 
thread_sleep(1);
rwlock_read_unlock(&rwlock);
rwlock_read_unlock(&rwlock);
rwlock_read_unlock(&rwlock);
rwlock_read_unlock(&rwlock);
 
}
/tags/0.1.0/SPARTAN/trunk/test/synch/rwlock3/test.c
0,0 → 1,91
/*
* Copyright (C) 2001-2004 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 <test.h>
#include <arch.h>
#include <arch/atomic.h>
#include <print.h>
#include <proc/thread.h>
 
#include <synch/rwlock.h>
 
#define READERS 50
#define WRITERS 50
 
static rwlock_t rwlock;
 
static void reader(void *arg);
static void failed(void);
 
void reader(void *arg)
{
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);
 
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);
printf("Test passed.\n");
 
}
 
void failed(void)
{
printf("Test failed prematurely.\n");
thread_exit();
}
 
void test(void)
{
int i;
thread_t *thrd;
printf("Read/write locks test #2\n");
rwlock_initialize(&rwlock);
 
rwlock_write_lock(&rwlock);
for (i=0; i<4; i++) {
thrd = thread_create(reader, NULL, TASK, 0);
if (thrd)
thread_ready(thrd);
else
failed();
}
 
 
thread_sleep(1);
rwlock_write_unlock(&rwlock);
}
/tags/0.1.0/SPARTAN/trunk/test/synch/semaphore1/test.c
0,0 → 1,128
/*
* Copyright (C) 2001-2004 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 <test.h>
#include <arch.h>
#include <arch/atomic.h>
#include <print.h>
#include <proc/thread.h>
 
#include <synch/waitq.h>
#include <synch/semaphore.h>
 
#define AT_ONCE 3
#define PRODUCERS 50
#define CONSUMERS 50
 
static semaphore_t sem;
 
static waitq_t can_start;
static volatile int items_produced;
static volatile int items_consumed;
 
static void consumer(void *arg);
static void producer(void *arg);
static void failed(void);
 
void producer(void *arg)
{
waitq_sleep(&can_start);
semaphore_down(&sem);
atomic_inc(&items_produced);
thread_usleep(250);
semaphore_up(&sem);
}
 
void consumer(void *arg)
{
waitq_sleep(&can_start);
semaphore_down(&sem);
atomic_inc(&items_consumed);
thread_usleep(500);
semaphore_up(&sem);
}
 
void failed(void)
{
printf("Test failed prematurely.\n");
thread_exit();
}
 
void test(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++) {
thread_t *thrd;
 
items_produced = 0;
items_consumed = 0;
consumers = i * CONSUMERS;
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++) {
thrd = thread_create(consumer, NULL, TASK, 0);
if (thrd)
thread_ready(thrd);
else
failed();
}
for (k=0; k<(4-i); k++) {
thrd = thread_create(producer, NULL, TASK, 0);
if (thrd)
thread_ready(thrd);
else
failed();
}
}
 
printf("ok\n");
 
thread_sleep(1);
waitq_wakeup(&can_start, WAKEUP_ALL);
while (items_consumed != consumers || items_produced != producers) {
printf("%d consumers remaining, %d producers remaining\n", consumers - items_consumed, producers - items_produced);
thread_sleep(1);
}
}
printf("Test passed.\n");
}
/tags/0.1.0/SPARTAN/trunk/test/synch/rwlock5/test.c
0,0 → 1,124
/*
* Copyright (C) 2001-2004 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 <test.h>
#include <arch.h>
#include <arch/atomic.h>
#include <print.h>
#include <proc/thread.h>
 
#include <synch/waitq.h>
#include <synch/rwlock.h>
 
#define READERS 50
#define WRITERS 50
 
static rwlock_t rwlock;
 
static waitq_t can_start;
static volatile int items_read;
static volatile int items_written;
 
static void writer(void *arg);
static void reader(void *arg);
static void failed(void);
 
void writer(void *arg)
{
waitq_sleep(&can_start);
 
rwlock_write_lock(&rwlock);
atomic_inc(&items_written);
rwlock_write_unlock(&rwlock);
}
 
void reader(void *arg)
{
waitq_sleep(&can_start);
rwlock_read_lock(&rwlock);
atomic_inc(&items_read);
rwlock_read_unlock(&rwlock);
}
 
void failed(void)
{
printf("Test failed prematurely.\n");
thread_exit();
}
 
void test(void)
{
int i, j, k;
int readers, writers;
printf("Read/write locks test #5\n");
waitq_initialize(&can_start);
rwlock_initialize(&rwlock);
for (i=1; i<=3; i++) {
thread_t *thrd;
 
items_read = 0;
items_written = 0;
 
readers = i*READERS;
writers = (4-i)*WRITERS;
 
printf("Creating %d readers and %d writers...", readers, writers);
for (j=0; j<(READERS+WRITERS)/2; j++) {
for (k=0; k<i; k++) {
thrd = thread_create(reader, NULL, TASK, 0);
if (thrd)
thread_ready(thrd);
else
failed();
}
for (k=0; k<(4-i); k++) {
thrd = thread_create(writer, NULL, TASK, 0);
if (thrd)
thread_ready(thrd);
else
failed();
}
}
 
printf("ok\n");
 
thread_sleep(1);
waitq_wakeup(&can_start, WAKEUP_ALL);
while (items_read != readers || items_written != writers) {
printf("%d readers remaining, %d writers remaining, readers_in=%d\n", readers - items_read, writers - items_written, rwlock.readers_in);
thread_usleep(100000);
}
}
printf("Test passed.\n");
}
/tags/0.1.0/SPARTAN/trunk/test/synch/rwlock1/test.c
0,0 → 1,78
/*
* Copyright (C) 2001-2004 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 <test.h>
#include <arch.h>
#include <arch/atomic.h>
#include <print.h>
#include <proc/thread.h>
 
#include <synch/waitq.h>
#include <synch/rwlock.h>
 
#define READERS 50
#define WRITERS 50
 
static rwlock_t rwlock;
 
void test(void)
{
printf("Read/write locks test #1\n");
 
rwlock_initialize(&rwlock);
 
rwlock_write_lock(&rwlock);
rwlock_write_unlock(&rwlock);
 
rwlock_read_lock(&rwlock);
rwlock_read_lock(&rwlock);
rwlock_read_lock(&rwlock);
rwlock_read_lock(&rwlock);
rwlock_read_lock(&rwlock);
 
rwlock_read_unlock(&rwlock);
rwlock_read_unlock(&rwlock);
rwlock_read_unlock(&rwlock);
rwlock_read_unlock(&rwlock);
rwlock_read_unlock(&rwlock);
rwlock_write_lock(&rwlock);
rwlock_write_unlock(&rwlock);
 
rwlock_read_lock(&rwlock);
rwlock_read_unlock(&rwlock);
 
rwlock_write_lock(&rwlock);
rwlock_write_unlock(&rwlock);
 
rwlock_read_lock(&rwlock);
rwlock_read_unlock(&rwlock);
 
printf("Test passed.\n");
}
/tags/0.1.0/SPARTAN/trunk/test/synch/semaphore2/test.c
0,0 → 1,121
/*
* Copyright (C) 2001-2004 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 <test.h>
#include <arch.h>
#include <arch/atomic.h>
#include <print.h>
#include <proc/thread.h>
#include <arch/types.h>
#include <arch/context.h>
 
#include <synch/waitq.h>
#include <synch/semaphore.h>
#include <synch/synch.h>
 
static semaphore_t sem;
 
static spinlock_t lock;
 
static waitq_t can_start;
 
__u32 seed = 0xdeadbeaf;
 
static __u32 random(__u32 max);
 
static void consumer(void *arg);
static void failed(void);
 
__u32 random(__u32 max)
{
__u32 rc;
 
spinlock_lock(&lock);
rc = seed % max;
seed = (((seed<<2) ^ (seed>>2)) * 487) + rc;
spinlock_unlock(&lock);
return rc;
}
 
 
void consumer(void *arg)
{
int rc, to;
waitq_sleep(&can_start);
to = random(20000);
printf("cpu%d, tid %d down+ (%d)\n", CPU->id, THREAD->tid, to);
rc = semaphore_down_timeout(&sem, to);
if (SYNCH_FAILED(rc)) {
printf("cpu%d, tid %d down!\n", CPU->id, THREAD->tid);
return;
}
printf("cpu%d, tid %d down=\n", CPU->id, THREAD->tid);
thread_usleep(random(30000));
semaphore_up(&sem);
printf("cpu%d, tid %d up\n", CPU->id, THREAD->tid);
}
 
void failed(void)
{
printf("Test failed prematurely.\n");
thread_exit();
}
 
void test(void)
{
context_t ctx;
__u32 i, k;
printf("Semaphore test #2\n");
waitq_initialize(&can_start);
semaphore_initialize(&sem, 5);
 
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);
if (thrd)
thread_ready(thrd);
else
failed();
}
thread_usleep(20000);
waitq_wakeup(&can_start, WAKEUP_ALL);
}
 
}
/tags/0.1.0/SPARTAN/trunk/test/mm/mapping1/test.c
0,0 → 1,84
/*
* 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 <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);
frame1 = frame_alloc(FRAME_KA);
 
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));
map_page_to_frame(PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE, 0);
printf("Mapping virtual address %P to physical address %P.\n", PAGE1, KA2PA(frame1));
map_page_to_frame(PAGE1, 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");
}
/tags/0.1.0/SPARTAN/trunk/test/fpu/mips1/test.c
0,0 → 1,136
/*
* Copyright (C) 2005 Ondrej Palkovsky
* 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 <debug.h>
#include <panic.h>
 
#include <test.h>
#include <arch/atomic.h>
#include <proc/thread.h>
#include <time/delay.h>
 
#include <arch.h>
 
#define THREADS 50
#define DELAY 10000L
#define ATTEMPTS 5
 
static volatile int threads_ok;
static waitq_t can_start;
 
static void testit1(void *data)
{
int i;
volatile long long j;
double e,d,le,f;
int arg __attribute__((aligned(16))) = (int)((__native) data);
int after_arg __attribute__((aligned(16)));
waitq_sleep(&can_start);
 
for (i = 0; i<ATTEMPTS; i++) {
__asm__ volatile (
"mtc1 %0,$1"
:"=r"(arg)
);
 
delay(DELAY);
__asm__ volatile (
"mfc1 %0, $1"
:"=r"(after_arg)
);
if(arg != after_arg)
panic("General reg tid%d: arg(%d) != %d\n",
THREAD->tid, arg, after_arg);
}
 
atomic_inc(&threads_ok);
}
 
static void testit2(void *data)
{
int i;
volatile long long j;
double e,d,le,f;
int arg __attribute__((aligned(16))) = (int)((__native) data);
int after_arg __attribute__((aligned(16)));
waitq_sleep(&can_start);
 
for (i = 0; i<ATTEMPTS; i++) {
__asm__ volatile (
"mtc1 %0,$1"
:"=r"(arg)
);
 
scheduler();
__asm__ volatile (
"mfc1 %0,$1"
:"=r"(after_arg)
);
if(arg != after_arg)
panic("General reg tid%d: arg(%d) != %d\n",
THREAD->tid, arg, after_arg);
}
 
atomic_inc(&threads_ok);
}
 
 
void test(void)
{
thread_t *t;
int i;
 
waitq_initialize(&can_start);
 
printf("MIPS test #1\n");
printf("Creating %d threads... ", THREADS);
 
for (i=0; i<THREADS/2; i++) {
if (!(t = thread_create(testit1, (void *)((__native)i*2), TASK, 0)))
panic("could not create thread\n");
thread_ready(t);
if (!(t = thread_create(testit2, (void *)((__native)i*2+1), TASK, 0)))
panic("could not create thread\n");
thread_ready(t);
}
 
printf("ok\n");
thread_sleep(1);
waitq_wakeup(&can_start, WAKEUP_ALL);
 
while (threads_ok != THREADS)
;
printf("Test passed.\n");
}
/tags/0.1.0/SPARTAN/trunk/test/fpu/sse1/test.c
0,0 → 1,136
/*
* Copyright (C) 2005 Ondrej Palkovsky
* 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 <debug.h>
#include <panic.h>
 
#include <test.h>
#include <arch/atomic.h>
#include <proc/thread.h>
#include <time/delay.h>
 
#include <arch.h>
 
#define THREADS 50
#define DELAY 10000L
#define ATTEMPTS 5
 
static volatile int threads_ok;
static waitq_t can_start;
 
static void testit1(void *data)
{
int i;
volatile long long j;
double e,d,le,f;
int arg __attribute__((aligned(16))) = (int)((__native) data);
int after_arg __attribute__((aligned(16)));
waitq_sleep(&can_start);
 
for (i = 0; i<ATTEMPTS; i++) {
__asm__ volatile (
"movlpd %0, %%xmm2"
:"=m"(arg)
);
 
delay(DELAY);
__asm__ volatile (
"movlpd %%xmm2, %0"
:"=m"(after_arg)
);
if(arg != after_arg)
panic("tid%d: arg(%d) != %d\n",
THREAD->tid, arg, after_arg);
}
 
atomic_inc(&threads_ok);
}
 
static void testit2(void *data)
{
int i;
volatile long long j;
double e,d,le,f;
int arg __attribute__((aligned(16))) = (int)((__native) data);
int after_arg __attribute__((aligned(16)));
waitq_sleep(&can_start);
 
for (i = 0; i<ATTEMPTS; i++) {
__asm__ volatile (
"movlpd %0, %%xmm2"
:"=m"(arg)
);
 
scheduler();
__asm__ volatile (
"movlpd %%xmm2, %0"
:"=m"(after_arg)
);
if(arg != after_arg)
panic("tid%d: arg(%d) != %d\n",
THREAD->tid, arg, after_arg);
}
 
atomic_inc(&threads_ok);
}
 
 
void test(void)
{
thread_t *t;
int i;
 
waitq_initialize(&can_start);
 
printf("SSE test #1\n");
printf("Creating %d threads... ", THREADS);
 
for (i=0; i<THREADS/2; i++) {
if (!(t = thread_create(testit1, (void *)((__native)i*2), TASK, 0)))
panic("could not create thread\n");
thread_ready(t);
if (!(t = thread_create(testit2, (void *)((__native)i*2+1), TASK, 0)))
panic("could not create thread\n");
thread_ready(t);
}
 
printf("ok\n");
thread_sleep(1);
waitq_wakeup(&can_start, WAKEUP_ALL);
 
while (threads_ok != THREADS)
;
printf("Test passed.\n");
}
/tags/0.1.0/SPARTAN/trunk/test/fpu/fpu1/test.c
0,0 → 1,133
/*
* Copyright (C) 2005 Jakub Vana
* 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 <debug.h>
#include <panic.h>
 
#include <test.h>
#include <arch/atomic.h>
#include <proc/thread.h>
 
#include <arch.h>
 
#define THREADS 150*2
#define ATTEMPTS 100
 
#define E_10e8 271828182
#define PI_10e8 314159265
 
static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; }
 
static volatile int threads_ok;
static waitq_t can_start;
 
static void e(void *data)
{
int i;
double e,d,le,f;
 
waitq_sleep(&can_start);
 
for (i = 0; i<ATTEMPTS; i++) {
le=-1;
e=0;
f=1;
 
for(d=1;e!=le;d*=f,f+=1) {
le=e;
e=e+1/d;
}
 
if((int)(100000000*e)!=E_10e8)
panic("tid%d: e*10e8=%d\n", THREAD->tid, (int) 100000000*e);
}
 
atomic_inc(&threads_ok);
}
 
static void pi(void *data)
{
int i;
double lpi, pi;
double n, ab, ad;
 
waitq_sleep(&can_start);
 
 
for (i = 0; i<ATTEMPTS; i++) {
lpi = -1;
pi = 0;
 
for (n=2, ab = sqrt(2); lpi != pi; n *= 2, ab = ad) {
double sc, cd;
 
sc = sqrt(1 - (ab*ab/4));
cd = 1 - sc;
ad = sqrt(ab*ab/4 + cd*cd);
lpi = pi;
pi = 2 * n * ad;
}
 
if((int)(100000000*pi)!=PI_10e8)
panic("tid%d: pi*10e8=%d\n", THREAD->tid, (int) 100000000*pi);
}
 
atomic_inc(&threads_ok);
}
 
 
void test(void)
{
thread_t *t;
int i;
 
waitq_initialize(&can_start);
 
printf("FPU test #1\n");
printf("Creating %d threads... ", THREADS);
 
for (i=0; i<THREADS/2; i++) {
if (!(t = thread_create(e, NULL, TASK, 0)))
panic("could not create thread\n");
thread_ready(t);
if (!(t = thread_create(pi, NULL, TASK, 0)))
panic("could not create thread\n");
thread_ready(t);
}
printf("ok\n");
thread_sleep(1);
waitq_wakeup(&can_start, WAKEUP_ALL);
 
while (threads_ok != THREADS)
;
printf("Test passed.\n");
}
/tags/0.1.0/SPARTAN/trunk/test/print/print1/test.c
0,0 → 1,58
/*
* Copyright (C) 2005 Josef Cejka
* 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>
 
void test(void)
{
__u64 u64const = 0x0123456789ABCDEFLL;
double d;
printf(" Printf test \n");
printf(" Q %Q %q \n",u64const, u64const);
printf(" L %L %l \n",0x01234567 ,0x01234567);
printf(" W %W %w \n",0x0123 ,0x0123);
printf(" B %B %b \n",0x01 ,0x01);
printf(" F %F %f (123456789.987654321)\n",123456789.987654321,123456789.987654321);
printf(" F %F %f (-123456789.987654321e-10)\n",-123456789.987654321e-10,-123456789.987654321e-10);
printf(" E %E %e (123456789.987654321)\n",123456789.987654321,123456789.987654321);
printf(" E %.10E %.8e (-123456789.987654321e-12 for precision 10 & 8)\n",-123456789.987654321e-12,-123456789.987654321e-12);
printf(" E %.10E %.8e (-987654321.123456789e-12 for precision 10 & 8)\n",-987654321.123456789e-12,-987654321.123456789e-12);
printf(" E %.10E %.8e (123456789.987654321e-12 for precision 10 & 8)\n",123456789.987654321e-12,123456789.987654321e-12);
printf(" E %.10E %.8e (987654321.123456789e-12 for precision 10 & 8)\n",987654321.123456789e-12,987654321.123456789e-12);
printf(" E %.10E %.8e (-123456789.987654321e12 for precision 10 & 8)\n",-123456789.987654321e12,-123456789.987654321e12);
printf(" E %.10E %.8e (-987654321.123456789e12 for precision 10 & 8)\n",-987654321.123456789e12,-987654321.123456789e12);
printf(" E %.10E %.8e (123456789.987654321e12 for precision 10 & 8)\n",123456789.987654321e12,123456789.987654321e12);
printf(" E %.10E %.8e (987654321.123456789e12 for precision 10 & 8)\n",987654321.123456789e12,987654321.123456789e12);
u64const =0x7fffffffffffffffLL;
d =*((double *)((void *)(&u64const)));
printf(" E %.10E (NaN)\n",d);
u64const =(0xfff0000000000000LL);
d =*(double *)(void *)(&u64const);
printf(" E %.10E (-Inf)\n",d);
return;
}
/tags/0.1.0/SPARTAN/trunk/test/thread/thread1/test.c
0,0 → 1,71
/*
* Copyright (C) 2005 Jakub Vana
* 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 <debug.h>
#include <panic.h>
 
#include <test.h>
#include <arch/atomic.h>
#include <proc/thread.h>
 
#include <arch.h>
 
 
 
#define THREADS 5
 
 
static void thread(void *data)
{
while(1)
{
printf("%d\n",(int)(THREAD->tid));
scheduler();
}
}
 
 
 
void test(void)
{
thread_t *t;
int i;
 
 
 
for (i=0; i<THREADS; i++)
{
if (!(t = thread_create(thread, NULL, TASK, 0)))
panic("could not create thread\n");
thread_ready(t);
}
printf("ok\n");
}