From ed4e6192288de01f1fcf00e57557eab9153344c9 Mon Sep 17 00:00:00 2001 From: Steve King Date: Sat, 14 Aug 2010 13:11:51 -0700 Subject: [PATCH] Added some tests involving phobos. --- cmaked/Platform/Linux-dmd.cmake | 2 +- tests/CMakeLists.txt | 2 + tests/app_6/CMakeLists.txt | 2 + tests/app_6/app_6.d | 9 ++++ tests/app_7/CMakeLists.txt | 3 ++ tests/app_7/app_7.d | 85 +++++++++++++++++++++++++++++++++ 6 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 tests/app_6/CMakeLists.txt create mode 100644 tests/app_6/app_6.d create mode 100644 tests/app_7/CMakeLists.txt create mode 100644 tests/app_7/app_7.d diff --git a/cmaked/Platform/Linux-dmd.cmake b/cmaked/Platform/Linux-dmd.cmake index 994bab8..c95c4d8 100644 --- a/cmaked/Platform/Linux-dmd.cmake +++ b/cmaked/Platform/Linux-dmd.cmake @@ -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 "") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a2771b9..92a5646 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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) diff --git a/tests/app_6/CMakeLists.txt b/tests/app_6/CMakeLists.txt new file mode 100644 index 0000000..048c8ad --- /dev/null +++ b/tests/app_6/CMakeLists.txt @@ -0,0 +1,2 @@ +ADD_EXECUTABLE( app_6 app_6.d ) +ADD_TEST( app_6 app_6 ) diff --git a/tests/app_6/app_6.d b/tests/app_6/app_6.d new file mode 100644 index 0000000..6347c4e --- /dev/null +++ b/tests/app_6/app_6.d @@ -0,0 +1,9 @@ +/* + Barebones app, but uses phobos +*/ +import std.stdio; +int main() +{ + writeln( "Hello, world!" ); + return 0; +} diff --git a/tests/app_7/CMakeLists.txt b/tests/app_7/CMakeLists.txt new file mode 100644 index 0000000..7e1eee0 --- /dev/null +++ b/tests/app_7/CMakeLists.txt @@ -0,0 +1,3 @@ +# A more complex library test. +ADD_EXECUTABLE( app_7 app_7.d ) +ADD_TEST( app_7 app_7 ) diff --git a/tests/app_7/app_7.d b/tests/app_7/app_7.d new file mode 100644 index 0000000..b644aea --- /dev/null +++ b/tests/app_7/app_7.d @@ -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; +}