Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2019 → Rev 2020

/trunk/kernel/test/test.c
38,8 → 38,33
{
"atomic1",
"Test atomic operations",
&test_atomic1
&test_atomic1,
true
},
{
"btree1",
"Test B-tree operations",
&test_btree1,
true
},
{
"mips1",
"MIPS debug test",
&test_mips1,
true
},
{
"fault1",
"Write to NULL (maybe page fault)",
&test_fault1,
false
},
{
"fpu1",
"Intel FPU test",
&test_fpu1,
true
},
{NULL, NULL, NULL}
};
 
/trunk/kernel/test/btree/btree1/test.c
File deleted
/trunk/kernel/test/btree/btree1.c
0,0 → 1,170
/*
* Copyright (C) 2006 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 <print.h>
#include <adt/btree.h>
#include <debug.h>
 
#ifdef CONFIG_BENCH
#include <arch/cycle.h>
#endif
 
void *data = (void *) 0xdeadbeef;
 
void test_btree1(void)
{
#ifdef CONFIG_BENCH
uint64_t t0 = get_cycle();
#endif
btree_t t;
int i;
 
btree_create(&t);
 
printf("Inserting keys.\n");
btree_insert(&t, 19, data, NULL);
btree_insert(&t, 20, data, NULL);
btree_insert(&t, 21, data, NULL);
btree_insert(&t, 0, data, NULL);
btree_insert(&t, 25, data, NULL);
btree_insert(&t, 22, data, NULL);
btree_insert(&t, 26, data, NULL);
btree_insert(&t, 23, data, NULL);
btree_insert(&t, 24, data, NULL);
btree_insert(&t, 5, data, NULL);
btree_insert(&t, 1, data, NULL);
btree_insert(&t, 4, data, NULL);
btree_insert(&t, 28, data, NULL);
btree_insert(&t, 29, data, NULL);
btree_insert(&t, 7, data, NULL);
btree_insert(&t, 8, data, NULL);
btree_insert(&t, 9, data, NULL);
btree_insert(&t, 17, data, NULL);
btree_insert(&t, 18, data, NULL);
btree_insert(&t, 2, data, NULL);
btree_insert(&t, 3, data, NULL);
btree_insert(&t, 6, data, NULL);
btree_insert(&t, 10, data, NULL);
btree_insert(&t, 11, data, NULL);
btree_insert(&t, 12, data, NULL);
btree_insert(&t, 13, data, NULL);
btree_insert(&t, 14, data, NULL);
btree_insert(&t, 15, data, NULL);
btree_insert(&t, 16, data, NULL);
btree_insert(&t, 27, data, NULL);
 
for (i = 30; i < 50; i++)
btree_insert(&t, i, data, NULL);
for (i = 100; i >= 50; i--)
btree_insert(&t, i, data, NULL);
 
btree_print(&t);
printf("Removing keys.\n");
btree_remove(&t, 50, NULL);
btree_remove(&t, 49, NULL);
btree_remove(&t, 51, NULL);
btree_remove(&t, 46, NULL);
btree_remove(&t, 45, NULL);
btree_remove(&t, 48, NULL);
btree_remove(&t, 53, NULL);
btree_remove(&t, 47, NULL);
btree_remove(&t, 52, NULL);
btree_remove(&t, 54, NULL);
btree_remove(&t, 65, NULL);
btree_remove(&t, 60, NULL);
btree_remove(&t, 99, NULL);
btree_remove(&t, 97, NULL);
btree_remove(&t, 57, NULL);
btree_remove(&t, 58, NULL);
btree_remove(&t, 61, NULL);
btree_remove(&t, 64, NULL);
btree_remove(&t, 56, NULL);
btree_remove(&t, 41, NULL);
 
for (i = 5; i < 20; i++)
btree_remove(&t, i, NULL);
 
btree_remove(&t, 2, NULL);
btree_remove(&t, 43, NULL);
btree_remove(&t, 22, NULL);
btree_remove(&t, 100, NULL);
btree_remove(&t, 98, NULL);
btree_remove(&t, 96, NULL);
btree_remove(&t, 66, NULL);
btree_remove(&t, 1, NULL);
 
for (i = 70; i < 90; i++)
btree_remove(&t, i, NULL);
 
btree_remove(&t, 20, NULL);
btree_remove(&t, 0, NULL);
btree_remove(&t, 40, NULL);
btree_remove(&t, 3, NULL);
btree_remove(&t, 4, NULL);
btree_remove(&t, 21, NULL);
btree_remove(&t, 44, NULL);
btree_remove(&t, 55, NULL);
btree_remove(&t, 62, NULL);
btree_remove(&t, 26, NULL);
btree_remove(&t, 27, NULL);
btree_remove(&t, 28, NULL);
btree_remove(&t, 29, NULL);
btree_remove(&t, 30, NULL);
btree_remove(&t, 31, NULL);
btree_remove(&t, 32, NULL);
btree_remove(&t, 33, NULL);
btree_remove(&t, 93, NULL);
btree_remove(&t, 95, NULL);
btree_remove(&t, 94, NULL);
btree_remove(&t, 69, NULL);
btree_remove(&t, 68, NULL);
btree_remove(&t, 92, NULL);
btree_remove(&t, 91, NULL);
btree_remove(&t, 67, NULL);
btree_remove(&t, 63, NULL);
btree_remove(&t, 90, NULL);
btree_remove(&t, 59, NULL);
btree_remove(&t, 23, NULL);
btree_remove(&t, 24, NULL);
btree_remove(&t, 25, NULL);
btree_remove(&t, 37, NULL);
btree_remove(&t, 38, NULL);
btree_remove(&t, 42, NULL);
btree_remove(&t, 39, NULL);
btree_remove(&t, 34, NULL);
btree_remove(&t, 35, NULL);
btree_remove(&t, 36, NULL);
 
btree_print(&t);
#ifdef CONFIG_BENCH
uint64_t dt = get_cycle() - t0;
printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
#endif
}
/trunk/kernel/test/test.h
42,9 → 42,14
char * name;
char * desc;
function entry;
bool safe;
} test_t;
 
extern void test_atomic1(void);
extern void test_btree1(void);
extern void test_mips1(void);
extern void test_fault1(void);
extern void test_fpu1(void);
 
extern test_t tests[];
 
/trunk/kernel/test/debug/mips1/test.c
File deleted
/trunk/kernel/test/debug/mips1.c
0,0 → 1,54
/*
* 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 <atomic.h>
#include <proc/thread.h>
#include <time/delay.h>
 
#include <arch.h>
 
 
void test_mips1(void)
{
#ifdef mips32
printf("MIPS debug test #1\n");
 
printf("You should enter kconsole debug mode now.\n");
 
asm __volatile__ ("break");
 
printf("Test passed.\n");
#else
printf("This test is availaible only on MIPS32 platform.\n");
#endif
}
/trunk/kernel/test/fpu/fpu1/test.c
File deleted
/trunk/kernel/test/fpu/fpu1.c
0,0 → 1,200
/*
* 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 <atomic.h>
#include <proc/thread.h>
 
#include <arch.h>
#include <arch/arch.h>
 
#ifdef CONFIG_BENCH
#include <arch/cycle.h>
#endif
 
#if (defined(ia32) || defined(amd64) || defined(ia64) || defined(ia32xen))
 
#define THREADS 150*2
#define ATTEMPTS 100
 
#define E_10e8 271828182
#define PI_10e8 314159265
 
 
#ifdef KERN_ia32_ARCH_H_
static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; }
#endif
 
#ifdef KERN_amd64_ARCH_H_
static inline double sqrt(double x) { double v; __asm__ ("fsqrt\n" : "=t" (v) : "0" (x)); return v; }
#endif
 
#ifdef KERN_ia64_ARCH_H_
static inline long double sqrt(long double a)
{
long double x = 1;
long double lx = 0;
 
if(a<0.00000000000000001) return 0;
while(x!=lx)
{
lx=x;
x=(x+(a/x))/2;
}
return x;
}
#endif
 
 
 
static atomic_t threads_ok;
static waitq_t can_start;
 
static void e(void *data)
{
int i;
double e,d,le,f;
 
thread_detach(THREAD);
 
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=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*e),(unative_t) E_10e8);
}
 
printf("tid%d: e*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*e),(unative_t) E_10e8);
atomic_inc(&threads_ok);
}
 
static void pi(void *data)
{
 
#ifdef KERN_ia64_ARCH_H_
#undef PI_10e8
#define PI_10e8 3141592
#endif
 
 
int i;
double lpi, pi;
double n, ab, ad;
thread_detach(THREAD);
 
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;
}
 
#ifdef KERN_ia64_ARCH_H_
if((int)(1000000*pi)!=PI_10e8)
panic("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (1000000*pi),(unative_t) (PI_10e8/100));
#else
if((int)(100000000*pi)!=PI_10e8)
panic("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*pi),(unative_t) PI_10e8);
#endif
 
}
 
printf("tid%d: pi*10e8=%zd should be %zd\n", THREAD->tid, (unative_t) (100000000*pi),(unative_t) PI_10e8);
atomic_inc(&threads_ok);
}
 
void test_fpu1(void)
{
#ifdef CONFIG_BENCH
uint64_t t0 = get_cycle();
#endif
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, "e")))
panic("could not create thread\n");
thread_ready(t);
if (!(t = thread_create(pi, NULL, TASK, 0, "pi")))
panic("could not create thread\n");
thread_ready(t);
}
printf("ok\n");
thread_sleep(1);
waitq_wakeup(&can_start, WAKEUP_ALL);
 
while (atomic_get(&threads_ok) != THREADS)
;
printf("Test passed.\n");
#ifdef CONFIG_BENCH
uint64_t dt = get_cycle() - t0;
printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
#endif
}
 
#else
 
void test_fpu1(void)
{
printf("This test is available only on Intel/AMD platforms.");
}
 
#endif
/trunk/kernel/test/fault/fault1/test.c
File deleted
/trunk/kernel/test/fault/fault1.c
0,0 → 1,46
/*
* 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 <atomic.h>
#include <proc/thread.h>
 
#include <arch.h>
 
 
void test_fault1(void)
{
 
((int *)(0))[1]=0;
 
}
/trunk/kernel/test/atomic/atomic1.c
63,5 → 63,4
uint64_t dt = get_cycle() - t0;
printf("Time: %.*d cycles\n", sizeof(dt) * 2, dt);
#endif
return;
}