Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cstyl committed Dec 17, 2023
1 parent 39df791 commit ff9fdb5
Show file tree
Hide file tree
Showing 16 changed files with 399 additions and 375 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ else()
set(MORPHEUS_IS_SUBDIRECTORY FALSE)
endif()

# Enable C++17
set(CMAKE_CXX_STANDARD 17)

include(cmake/morpheusoracle_utils.cmake)

option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
Expand Down
3 changes: 1 addition & 2 deletions examples/decision-tree-tuner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ elseif(Morpheus_ENABLE_HIP)
target_compile_definitions(MorpheusOracle_decision_tree_tuner_HIP PRIVATE EXAMPLE_ENABLE_HIP)
target_link_libraries(MorpheusOracle_decision_tree_tuner_HIP PUBLIC Morpheus::morpheus)
elseif(Morpheus_ENABLE_OPENMP)
morpheusoracle_add_test_executable(decision_tree_tuner_OPENMP SOURCES
decision_tree_tuner.cpp)
morpheusoracle_add_test_executable(decision_tree_tuner_OPENMP SOURCES decision_tree_tuner.cpp)
target_compile_definitions(MorpheusOracle_decision_tree_tuner_OPENMP
PRIVATE EXAMPLE_ENABLE_OPENMP)
target_link_libraries(MorpheusOracle_decision_tree_tuner_OPENMP PUBLIC Morpheus::morpheus)
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ install(

set(MORPHEUS_ORACLE_SOURCES)
append_glob(MORPHEUS_ORACLE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
append_glob(MORPHEUS_ORACLE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/impl/*.cpp)

set(MORPHEUS_ORACLE_HEADERS)
append_glob(MORPHEUS_ORACLE_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
Expand Down
2 changes: 1 addition & 1 deletion src/impl/DecisionTree/MorpheusOracle_Loader_Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void load_text(std::ifstream& stree, Tree& tree,
std::vector<std::string> tokens;
std::string line;
std::getline(stree, line);
Impl::tokenize(tokens, line);
Oracle::Impl::tokenize(tokens, line);

size_t nfeatures, nclasses, nodecount, maxdepth;
std::istringstream(tokens[0]) >> nfeatures;
Expand Down
26 changes: 26 additions & 0 deletions src/impl/MorpheusOracle_Loader_Utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <impl/MorpheusOracle_Loader_Utils.hpp>

namespace Morpheus {
namespace Oracle {
namespace Impl {

void tokenize(std::vector<std::string>& tokens, const std::string& str,
const std::string& delimiters) {
// Skip delimiters at beginning.
std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
std::string::size_type pos = str.find_first_of(delimiters, lastPos);

while (std::string::npos != pos || std::string::npos != lastPos) {
// Found a token, add it to the vector.
tokens.push_back(str.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = str.find_first_of(delimiters, lastPos);
}
}

} // namespace Impl
} // namespace Oracle
} // namespace Morpheus
23 changes: 5 additions & 18 deletions src/impl/MorpheusOracle_Loader_Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,14 @@
#include <sstream>
#include <iostream>
#include <exception>
#include <vector>

namespace Morpheus {
namespace Oracle {
namespace Impl {

void tokenize(std::vector<std::string>& tokens, const std::string& str,
const std::string& delimiters = "\n\r\t ") {
// Skip delimiters at beginning.
std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
// Find first "non-delimiter".
std::string::size_type pos = str.find_first_of(delimiters, lastPos);

while (std::string::npos != pos || std::string::npos != lastPos) {
// Found a token, add it to the vector.
tokens.push_back(str.substr(lastPos, pos - lastPos));
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of(delimiters, pos);
// Find next "non-delimiter"
pos = str.find_first_of(delimiters, lastPos);
}
}
const std::string& delimiters = "\n\r\t ");

template <typename Stream>
void skip_comment(Stream& input, const std::string delimiter = "#") {
Expand All @@ -76,7 +63,7 @@ void load_array(std::vector<std::string>& vec, Stream& input,
std::getline(input, line);

std::vector<std::string> tokens;
Impl::tokenize(tokens, line);
Oracle::Impl::tokenize(tokens, line);

if (tokens.size() != vec.size()) {
throw std::runtime_error("Entries (" + std::to_string(tokens.size()) +
Expand All @@ -102,7 +89,7 @@ void load_array(Vector& vec, Stream& input, bool skip_comments = true,
std::getline(input, line);

std::vector<std::string> tokens;
Impl::tokenize(tokens, line);
Oracle::Impl::tokenize(tokens, line);

if (tokens.size() != vec.size()) {
throw std::runtime_error("Entries (" + std::to_string(tokens.size()) +
Expand Down Expand Up @@ -131,7 +118,7 @@ void load_2d_array(Matrix& mat, size_t dim1, size_t dim2, Stream& input,
std::getline(input, line);

std::vector<std::string> tokens;
Impl::tokenize(tokens, line);
Oracle::Impl::tokenize(tokens, line);

if (tokens.size() != dim2) {
throw std::runtime_error("Entries (" + std::to_string(tokens.size()) +
Expand Down
2 changes: 1 addition & 1 deletion src/impl/RandomForest/MorpheusOracle_Loader_Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void load_text(std::ifstream& sforest, Tree& forest,
std::vector<std::string> tokens;
std::string line;
std::getline(sforest, line);
Impl::tokenize(tokens, line);
Oracle::Impl::tokenize(tokens, line);

size_t nfeatures, nclasses, noutputs, nestimators;
std::istringstream(tokens[0]) >> nfeatures;
Expand Down
76 changes: 14 additions & 62 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,23 @@ message(STATUS "Morpheus-Oracle Tests are enabled")

morpheusoracle_include_directories(${CMAKE_CURRENT_BINARY_DIR})
morpheusoracle_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
morpheusoracle_include_directories(
${MorpheusOracle_SOURCE_DIR}/tests/category_files)

foreach(Tag Serial;OpenMP;Cuda;HIP)
string(TOUPPER ${Tag} DEVICE)
string(TOLOWER ${Tag} dir)
global_set(${Tag}_SOURCES)
global_set(TEST_SOURCES)

if(Morpheus_ENABLE_${DEVICE})
set(testdir ${CMAKE_CURRENT_BINARY_DIR}/${dir})
file(MAKE_DIRECTORY ${testdir})
set(testdir ${CMAKE_CURRENT_BINARY_DIR})
file(MAKE_DIRECTORY ${testdir})

foreach(Name RunFirstTuner TuneRunFirst TypeTraits)
set(file ${testdir}/Test_${Tag}_${Name}.cpp)
# Write to a temporary intermediate file and call configure_file to avoid
# updating timestamps triggering unnecessary rebuilds on subsequent cmake
# runs.
file(WRITE ${testdir}/dummy.cpp "#include <Test${Tag}_Category.hpp>\n"
"#include <Test_${Name}.hpp>\n")
configure_file(${testdir}/dummy.cpp ${file})
global_append(${Tag}_SOURCES ${file})
endforeach()
endif()
foreach(Name RunFirstTuner TuneRunFirst TypeTraits)
set(file ${testdir}/Test_${Name}.cpp)
# Write to a temporary intermediate file and call configure_file to avoid
# updating timestamps triggering unnecessary rebuilds on subsequent cmake
# runs.
file(WRITE ${testdir}/dummy.cpp "#include <Test_${Name}.hpp>\n")
configure_file(${testdir}/dummy.cpp ${file})
global_append(TEST_SOURCES ${file})
endforeach()

set(ALL_SOURCES)
morpheusoracle_add_executable_and_test(
UnitTest SOURCES TestMain.cpp ${TEST_SOURCES} TESTONLYLIBS
morpheusoracle_gtest)

if(Morpheus_ENABLE_SERIAL)
if(MorpheusOracle_ENABLE_INDIVIDUAL_TESTS)
morpheusoracle_add_executable_and_test(
UnitTest_Serial SOURCES TestMain.cpp ${Serial_SOURCES} TESTONLYLIBS
morpheusoracle_gtest)
endif()
list(APPEND ALL_SOURCES ${Serial_SOURCES})
endif()

if(Morpheus_ENABLE_OPENMP)
if(MorpheusOracle_ENABLE_INDIVIDUAL_TESTS)
morpheusoracle_add_executable_and_test(
UnitTest_OpenMP SOURCES TestMain.cpp ${OpenMP_SOURCES} TESTONLYLIBS
morpheusoracle_gtest)
endif()
list(APPEND ALL_SOURCES ${OpenMP_SOURCES})
endif()

if(Morpheus_ENABLE_CUDA)
if(MorpheusOracle_ENABLE_INDIVIDUAL_TESTS)
morpheusoracle_add_executable_and_test(
UnitTest_Cuda SOURCES TestMain.cpp ${Cuda_SOURCES} TESTONLYLIBS
morpheusoracle_gtest)
endif()
list(APPEND ALL_SOURCES ${Cuda_SOURCES})
endif()

if(Morpheus_ENABLE_HIP)
if(MorpheusOracle_ENABLE_INDIVIDUAL_TESTS)
morpheusoracle_add_executable_and_test(
UnitTest_HIP SOURCES TestMain.cpp ${HIP_SOURCES} TESTONLYLIBS
morpheusoracle_gtest)
endif()
list(APPEND ALL_SOURCES ${HIP_SOURCES})
endif()

if(NOT MorpheusOracle_ENABLE_INDIVIDUAL_TESTS)
morpheusoracle_add_executable_and_test(
UnitTest SOURCES TestMain.cpp ${ALL_SOURCES} TESTONLYLIBS
morpheusoracle_gtest)
endif()
4 changes: 1 addition & 3 deletions tests/TestMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ int main(int argc, char *argv[]) {
int result;
::testing::InitGoogleTest(&argc, argv);

Morpheus::initialize(argc, argv);
{ result = RUN_ALL_TESTS(); }
Morpheus::finalize();
result = RUN_ALL_TESTS();

return result;
}
Loading

0 comments on commit ff9fdb5

Please sign in to comment.