Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CTest support #310

Merged
merged 11 commits into from
Apr 10, 2020
Prev Previous commit
Next Next commit
[CMake] Set and respect OCCA_CACHE_DIR in tests
Some tests override the OCCA_CACHE_DIR environment variable.
This leads to artefacts (e.g. lock files) in the source tree
instead of the build tree.

In this way we let CMake take care of the correct paths.
  • Loading branch information
SFrijters committed Apr 9, 2020
commit 2297d14991d072bfbd1969d61214f4de0421f8da
3 changes: 2 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
macro(add_test_with_mode exe mode device)
add_test(NAME ${exe}-${mode} COMMAND ${exe} --verbose --device ${device} WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
add_test(NAME ${exe}-${mode} COMMAND ${exe} --verbose --device ${device})
set_property(TEST ${exe}-${mode} APPEND PROPERTY ENVIRONMENT OCCA_CACHE_DIR=${CMAKE_BINARY_DIR}/cache)
endmacro()

macro(add_test_without_mode exe)
Expand Down
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ if (WITH_CUDA)
endif()
add_test(NAME occa-version COMMAND occa version)

set_property(TEST occa-autocomplete occa-clear occa-compile-help occa-env occa-info occa-modes occa-translate-help occa-translate-serial occa-version APPEND PROPERTY ENVIRONMENT OCCA_CACHE_DIR=${CMAKE_BINARY_DIR}/cache)
if (WITH_CUDA)
set_property(TEST occa-translate-cuda occa-translate-cuda-launcher APPEND PROPERTY ENVIRONMENT OCCA_CACHE_DIR=${CMAKE_BINARY_DIR}/cache)
endif()

add_custom_target(testinput ALL)
add_custom_command(TARGET testinput POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
Expand Down
1 change: 1 addition & 0 deletions tests/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ macro(add_cpp_test exe_name source)
add_executable(${exe_name} ${source})
target_link_libraries(${exe_name} libocca ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
add_test(NAME test-${exe_name} COMMAND ${exe_name})
set_property(TEST test-${exe_name} APPEND PROPERTY ENVIRONMENT OCCA_CACHE_DIR=${CMAKE_BINARY_DIR}/cache)
endmacro()

add_cpp_test(dtype dtype.cpp)
Expand Down
2 changes: 2 additions & 0 deletions tests/src/io/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ void testHashDir();
void testBuild();

int main(const int argc, const char **argv) {
#ifndef USE_CMAKE
occa::env::OCCA_CACHE_DIR = occa::io::dirname(__FILE__);
#endif
srand(time(NULL));

testCacheInfoMethods();
Expand Down
2 changes: 2 additions & 0 deletions tests/src/io/fileOpener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ void testDefaultFileOpener();
void testOccaFileOpener();

int main(const int argc, const char **argv) {
#ifndef USE_CMAKE
occa::env::OCCA_CACHE_DIR = occa::io::dirname(__FILE__);
#endif

testDefaultFileOpener();
testOccaFileOpener();
Expand Down
2 changes: 2 additions & 0 deletions tests/src/io/lock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ void testStaleRelease();
void clearLocks();

int main(const int argc, const char **argv) {
#ifndef USE_CMAKE
occa::env::OCCA_CACHE_DIR = occa::io::dirname(__FILE__);
#endif
occa::settings()["locks/stale-warning"] = 0;
occa::settings()["locks/stale-age"] = 0.2;

Expand Down
2 changes: 2 additions & 0 deletions tests/src/io/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ void testDirMethods();
void testIOMethods();

int main(const int argc, const char **argv) {
#ifndef USE_CMAKE
occa::env::OCCA_CACHE_DIR = "/occa/cache/dir/";
#endif
srand(time(NULL));

testPathMethods();
Expand Down