From 864c240cddf700515e35c158dc062e9dfda8e9a6 Mon Sep 17 00:00:00 2001 From: Andy Li Date: Tue, 10 Oct 2017 17:17:05 +0800 Subject: [PATCH] Actually running tests in Appveyor (#87) Implement test run for AppVeyor and adapt them for Windows --- CMakeLists.txt | 25 ++++++++++++++++++++-- appveyor.yml | 19 +++++++++++------ tests/lua/channel-stress.lua | 41 +++++++++++++++++++----------------- tests/lua/gc-stress.lua | 2 +- tests/lua/run_tests | 2 +- 5 files changed, 59 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index affe42e..24003f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,18 @@ if (NOT (LUA_INCLUDE_DIR OR BUILD_ROCK)) find_package(Lua REQUIRED) endif() +# avoid the extra "Debug", "Release" directories +# http://stackoverflow.com/questions/7747857/in-cmake-how-do-i-work-around-the-debug-and-release-directories-visual-studio-2 +set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} ) +set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} ) +set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} ) +foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) + string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG ) + set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ) + set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ) + set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} ) +endforeach() + # Supress warning CMP0042 if(APPLE) set(CMAKE_MACOSX_RPATH 1) @@ -29,8 +41,17 @@ FILE(GLOB SOURCES src/cpp/*.cpp src/cpp/*.h) FILE(GLOB LUA_SOURCES src/lua/*.lua) add_library(effil SHARED ${SOURCES}) -target_link_libraries(effil -lpthread ${LUA_LIBRARY} -ldl) -set_target_properties(effil PROPERTIES SUFFIX .so) +target_link_libraries(effil ${LUA_LIBRARY}) +if (WIN32) + set_target_properties(effil PROPERTIES + PREFIX lib + SUFFIX .dll) +else() + target_link_libraries(effil -lpthread -ldl) + set_target_properties(effil PROPERTIES + PREFIX lib + SUFFIX .so) +endif() set(GENERAL "-DSOL_EXCEPTIONS_SAFE_PROPAGATION") set(CMAKE_CXX_FLAGS "${EXTRA_FLAGS} ${CMAKE_CXX_FLAGS} ${GENERAL}") diff --git a/appveyor.yml b/appveyor.yml index c8aa3a2..f7176fe 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,12 +5,14 @@ configuration: - Release environment: + global: + STRESS: 1 matrix: - - LUA: "lua 5.1" - - LUA: "lua 5.2" - - LUA: "lua 5.3" - - LUA: "luajit 2.0" - - LUA: "luajit 2.1" + - LUA: "lua 5.1" + - LUA: "lua 5.2" + - LUA: "lua 5.3" + - LUA: "luajit 2.0" + # - LUA: "luajit 2.1" # currently failing before_build: - git submodule update --init --recursive @@ -19,7 +21,10 @@ before_build: - call env\bin\activate build_script: - - cmake . -G "Visual Studio 14 2015 Win64" + - mkdir build + - cd build + - cmake .. -G "Visual Studio 14 2015 Win64" - cmake --build . --config %CONFIGURATION% -test: off \ No newline at end of file +test_script: + - lua ../tests/lua/run_tests \ No newline at end of file diff --git a/tests/lua/channel-stress.lua b/tests/lua/channel-stress.lua index fe26da0..b17e784 100644 --- a/tests/lua/channel-stress.lua +++ b/tests/lua/channel-stress.lua @@ -5,7 +5,7 @@ test.channel_stress.tear_down = default_tear_down test.channel_stress.with_multiple_threads = function () local exchange_channel, result_channel = effil.channel(), effil.channel() - local threads_number = 20 + local threads_number = 20 * tonumber(os.getenv("STRESS")) local threads = {} for i = 1, threads_number do threads[i] = effil.thread(function(exchange_channel, result_channel, indx) @@ -45,24 +45,27 @@ test.channel_stress.with_multiple_threads = function () end end -test.channel_stress.timed_read = function () - local chan = effil.channel() - local delayed_writer = function(channel, delay) - require("effil").sleep(delay) - channel:push("hello!") - end - effil.thread(delayed_writer)(chan, 70) +-- TODO: fix it for Windows +if not os.getenv("APPVEYOR") then + test.channel_stress.timed_read = function () + local chan = effil.channel() + local delayed_writer = function(channel, delay) + require("effil").sleep(delay) + channel:push("hello!") + end + effil.thread(delayed_writer)(chan, 70) + + local function check_time(real_time, use_time, metric, result) + local start_time = os.time() + test.equal(chan:pop(use_time, metric), result) + test.almost_equal(os.time(), start_time + real_time, 1) + end + check_time(2, 2, nil, nil) -- second by default + check_time(2, 2, 's', nil) + check_time(60, 1, 'm', nil) - local function check_time(real_time, use_time, metric, result) local start_time = os.time() - test.equal(chan:pop(use_time, metric), result) - test.almost_equal(os.time(), start_time + real_time, 1) + test.equal(chan:pop(10), "hello!") + test.is_true(os.time() < start_time + 10) end - check_time(2, 2, nil, nil) -- second by default - check_time(2, 2, 's', nil) - check_time(60, 1, 'm', nil) - - local start_time = os.time() - test.equal(chan:pop(10), "hello!") - test.is_true(os.time() < start_time + 10) -end +end \ No newline at end of file diff --git a/tests/lua/gc-stress.lua b/tests/lua/gc-stress.lua index d8a6799..6a43cc4 100644 --- a/tests/lua/gc-stress.lua +++ b/tests/lua/gc-stress.lua @@ -12,7 +12,7 @@ test.gc_stress.create_and_collect_in_parallel = function () {{{}}}, --[[3 levels]] {{{{}}}} --[[4 levels]] } - for i = 1, 100 do + for i = 1, 20 * tonumber(os.getenv("STRESS")) do for t = 1, 10 do local tbl = effil.table(nested_table) for l = 1, 10 do diff --git a/tests/lua/run_tests b/tests/lua/run_tests index 5b34784..711a46e 100755 --- a/tests/lua/run_tests +++ b/tests/lua/run_tests @@ -1,6 +1,6 @@ #!/usr/bin/env lua -local scripts_path = arg[0]:gsub("/run_tests", "") +local scripts_path = arg[0]:gsub("[\\/]run_tests", "") local src_path = scripts_path .. "/../.." package.path = ";" .. scripts_path .. "/?.lua;" .. src_path .. "/src/lua/?.lua;"