Added some tests involving phobos.

This commit is contained in:
Steve King 2010-08-14 13:11:51 -07:00
parent 5d96b5e3ca
commit ed4e619228
6 changed files with 102 additions and 1 deletions

View file

@ -47,7 +47,7 @@ SET(CMAKE_DL_LIBS "dl")
SET(CMAKE_FIND_LIBRARY_PREFIXES "lib")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
SET(CMAKE_D_STDLIBS "-L-lphobos2 -L-lpthread -L-lm" )
#SET(CMAKE_D_STDLIBS "-L-lphobos2 -L-lpthread -L-lm" )
#SET (CMAKE_D_FLAGS_INIT "-version=${CMAKE_BUILD_TYPE}Build ${DSTDLIB_FLAGS} ${DSTDLIB_TYPE} -I$ENV{D_PATH}/include -I$ENV{D_PATH}/import -I${CMAKE_PROJECT_SOURCE_DIR}")
SET (CMAKE_D_FLAGS_INIT "")

View file

@ -27,3 +27,5 @@ ADD_SUBDIRECTORY (app_2)
ADD_SUBDIRECTORY (app_3)
ADD_SUBDIRECTORY (app_5)
ADD_SUBDIRECTORY (app_4)
ADD_SUBDIRECTORY (app_6)
ADD_SUBDIRECTORY (app_7)

View file

@ -0,0 +1,2 @@
ADD_EXECUTABLE( app_6 app_6.d )
ADD_TEST( app_6 app_6 )

9
tests/app_6/app_6.d Normal file
View file

@ -0,0 +1,9 @@
/*
Barebones app, but uses phobos
*/
import std.stdio;
int main()
{
writeln( "Hello, world!" );
return 0;
}

View file

@ -0,0 +1,3 @@
# A more complex library test.
ADD_EXECUTABLE( app_7 app_7.d )
ADD_TEST( app_7 app_7 )

85
tests/app_7/app_7.d Normal file
View file

@ -0,0 +1,85 @@
import std.stdio;
import core.thread;
import std.perf;
// Yield count should be larger for a
// more accurate measurment, but this
// is just a unit tests, so don't spin
// for long
immutable uint yield_count = 1000;
immutable uint worker_count = 10;
uint stack_check()
{
uint x;
asm
{
mov x,ESP;
}
return x;
}
void fiber_func()
{
uint i = yield_count;
while( --i ) Fiber.yield();
}
void thread_func()
{
uint i = yield_count;
while( --i ) Thread.yield();
}
void fiber_test()
{
Fiber[worker_count] fib_array;
foreach( ref f; fib_array )
f = new Fiber( &fiber_func );
auto timer = new PerformanceCounter;
uint i = yield_count;
// fibers are cooperative and need a driver loop
timer.start();
bool done;
do
{
done = true;
foreach( f; fib_array )
{
f.call();
if( f.state() != f.State.TERM )
done = false;
}
} while( !done );
timer.stop();
writeln( "Elapsed time for ", worker_count, " workers times ", yield_count, " yield() calls with fibers = ",
timer.milliseconds, "ms" );
}
void thread_test()
{
Thread[worker_count] thread_array;
foreach( ref t; thread_array )
t = new Thread( &thread_func );
auto timer = new PerformanceCounter;
timer.start();
foreach( t; thread_array )
t.start();
thread_joinAll();
timer.stop();
writeln( "Elapsed time for ", worker_count, " workers times ", yield_count, " yield() calls with threads = ",
timer.milliseconds, "ms" );
}
int main()
{
fiber_test();
thread_test();
return 0;
}