From 4997fae5291a5fad4f8bede26365a3f437196879 Mon Sep 17 00:00:00 2001 From: go2432 Date: Thu, 12 Aug 2021 14:15:53 -0500 Subject: [PATCH] began gtest --- CMake/CPUParallel.cmake | 4 +- CMake/FileLists.cmake | 60 ++++++++------------------ CMakeLists.txt | 17 ++++++-- {common => lib}/CSVIterator.cpp | 0 {common => lib}/CSVIterator.h | 0 {common => lib}/CSVRange.cpp | 0 {common => lib}/CSVRange.h | 0 {common => lib}/CSVRow.cpp | 0 {common => lib}/CSVRow.h | 0 simpleParallel/COO.h | 4 +- simpleParallel/Graph.h | 2 +- test/CMakeLists.txt.in | 15 +++++++ test/FileList.cmake | 23 ++++++++++ test/GoogleTest.cmake | 42 ++++++++++++++++++ test/src/ParallelKernelizationTest.cpp | 7 +++ 15 files changed, 124 insertions(+), 50 deletions(-) rename {common => lib}/CSVIterator.cpp (100%) rename {common => lib}/CSVIterator.h (100%) rename {common => lib}/CSVRange.cpp (100%) rename {common => lib}/CSVRange.h (100%) rename {common => lib}/CSVRow.cpp (100%) rename {common => lib}/CSVRow.h (100%) create mode 100644 test/CMakeLists.txt.in create mode 100644 test/FileList.cmake create mode 100644 test/GoogleTest.cmake create mode 100644 test/src/ParallelKernelizationTest.cpp diff --git a/CMake/CPUParallel.cmake b/CMake/CPUParallel.cmake index 5a1f20a..5bc4f82 100644 --- a/CMake/CPUParallel.cmake +++ b/CMake/CPUParallel.cmake @@ -4,9 +4,9 @@ set(CPU_PARALLEL_name "K_VC_CPU_PARALLEL") set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED true) #add_executable(CPUParallel ${sources_cpu_parallel} ${headers_cpu_parallel} ${libHeaders} ${libSources} ${BOOST_INCLUDE_DIRS}) -add_executable(CPUParallel ${headers_common} ${sources_common} ${sources_simple_parallel} ${headers_simple_parallel}) +add_executable(CPUParallel ${headers_lib} ${sources_lib} ${sources_simple_parallel} ${headers_simple_parallel}) set_target_properties(CPUParallel PROPERTIES OUTPUT_NAME ${CPU_PARALLEL_name}) if(WIN32) #needed for hostname target_link_libraries(CPUParallel ws2_32) -endif() \ No newline at end of file +endif() diff --git a/CMake/FileLists.cmake b/CMake/FileLists.cmake index f30955e..17f33a0 100644 --- a/CMake/FileLists.cmake +++ b/CMake/FileLists.cmake @@ -1,14 +1,3 @@ -set(sources_common - common/CSVIterator.cpp - common/CSVRange.cpp - common/CSVRow.cpp -) - -set(headers_common - common/CSVIterator.h - common/CSVRange.h - common/CSVRow.h -) set(sources_cpu_serial MainSerial.cpp @@ -23,18 +12,6 @@ set(sources_cpu_serial serial/SparseMatrix.cpp ) -set(sources_cpu_parallel - MainOpenMP.cpp - openmp/COO.cpp - openmp/CSR.cpp - openmp/Graph.cpp - openmp/LinearTimeDegreeSort.cpp - openmp/ParallelB1.cpp - openmp/ParallelKernelization.cpp - openmp/SparseMatrix.cpp - ) - - set(sources_simple_parallel MainSimpleParallel.cpp simpleParallel/COO.cpp @@ -68,16 +45,6 @@ set(headers_cpu_serial serial/SparseMatrix.h ) -set(headers_cpu_parallel - openmp/COO.h - openmp/CSR.h - openmp/Graph.h - openmp/LinearTimeDegreeSort.h - openmp/ParallelB1.h - openmp/ParallelKernelization.h - openmp/SparseMatrix.h - ) - set(headers_simple_parallel simpleParallel/COO.h simpleParallel/CSR.h @@ -97,15 +64,24 @@ set(headers_gpu gpu/SparseMatrix.cuh ) -set(libHeaders - lib/boost/include/dynamic_bitset.hpp - lib/boost/include/dynamic_bitset_fwd.hpp - lib/boost/include/dynamic_bitset/dynamic_bitset.hpp - lib/boost/include/dynamic_bitset/config.hpp - ) +#set(libHeaders +# lib/boost/include/dynamic_bitset.hpp +# lib/boost/include/dynamic_bitset_fwd.hpp +# lib/boost/include/dynamic_bitset/dynamic_bitset.hpp +# lib/boost/include/dynamic_bitset/config.hpp +# ) + +set(sources_lib + lib/CSVIterator.cpp + lib/CSVRange.cpp + lib/CSVRow.cpp +) -set(libSources - ) +set(headers_lib + lib/CSVIterator.h + lib/CSVRange.h + lib/CSVRow.h +) set(cudaHeaders ) @@ -116,4 +92,4 @@ set(cudaSources source_group("Header Files" FILES ${headers}) source_group("Lib Headers" FILES ${libHeaders}) source_group("CUDA Header Files" FILES ${cudaHeaders}) -source_group("CUDA Source Files" FILES ${cudaSources}) \ No newline at end of file +source_group("CUDA Source Files" FILES ${cudaSources}) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88dabfc..9f966a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,8 +12,8 @@ project(FPT) #include_directories(serial) #include_directories(lib/boost/include) #include_directories(lib/boost) -#include_directories(lib) - +include_directories(simpleParallel) +include_directories(test/src) #Out-of-source build set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) @@ -67,8 +67,19 @@ if (CMAKE_CUDA_COMPILER) # include(${PROJECT_SOURCE_DIR}/CMake/GPU.cmake) endif() + +#Optional CMake Argument +option(GTEST "Build unit tests " OFF) +option(GTEST_MPI "Build unit tests - MPI Enabled" OFF) + +# Enable google test, for now these vars of exclusive +if(GTEST OR GTEST_MPI) + enable_testing() + include(${PROJECT_SOURCE_DIR}/test/GoogleTest.cmake) +endif() + + # Setup Serial version -#include(${PROJECT_SOURCE_DIR}/CMake/CPUSerial.cmake) include(${PROJECT_SOURCE_DIR}/CMake/CPUParallel.cmake) # find OpenMP and set it up diff --git a/common/CSVIterator.cpp b/lib/CSVIterator.cpp similarity index 100% rename from common/CSVIterator.cpp rename to lib/CSVIterator.cpp diff --git a/common/CSVIterator.h b/lib/CSVIterator.h similarity index 100% rename from common/CSVIterator.h rename to lib/CSVIterator.h diff --git a/common/CSVRange.cpp b/lib/CSVRange.cpp similarity index 100% rename from common/CSVRange.cpp rename to lib/CSVRange.cpp diff --git a/common/CSVRange.h b/lib/CSVRange.h similarity index 100% rename from common/CSVRange.h rename to lib/CSVRange.h diff --git a/common/CSVRow.cpp b/lib/CSVRow.cpp similarity index 100% rename from common/CSVRow.cpp rename to lib/CSVRow.cpp diff --git a/common/CSVRow.h b/lib/CSVRow.h similarity index 100% rename from common/CSVRow.h rename to lib/CSVRow.h diff --git a/simpleParallel/COO.h b/simpleParallel/COO.h index 811a3c1..90ef184 100644 --- a/simpleParallel/COO.h +++ b/simpleParallel/COO.h @@ -5,7 +5,7 @@ #include #include #include -#include "../common/CSVRange.h" +#include "../lib/CSVRange.h" #include #include /* rand */ #include @@ -46,4 +46,4 @@ class COO final : public SparseMatrix std::map< std::pair, int > orderedMap; bool isSorted; }; -#endif \ No newline at end of file +#endif diff --git a/simpleParallel/Graph.h b/simpleParallel/Graph.h index 9a23558..342bf8d 100644 --- a/simpleParallel/Graph.h +++ b/simpleParallel/Graph.h @@ -10,7 +10,7 @@ #include #include #include "ConnectednessTest.h" -#include "../common/CSVRange.h" +#include "../lib/CSVRange.h" class Graph { public: diff --git a/test/CMakeLists.txt.in b/test/CMakeLists.txt.in new file mode 100644 index 0000000..5221aad --- /dev/null +++ b/test/CMakeLists.txt.in @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.8) + +project(googletest-download NONE) + +include(ExternalProject) +ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG master + SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) \ No newline at end of file diff --git a/test/FileList.cmake b/test/FileList.cmake new file mode 100644 index 0000000..fa0102b --- /dev/null +++ b/test/FileList.cmake @@ -0,0 +1,23 @@ +set(TestSources + test/src/ParallelKernelizationTest.cpp +) + +set(TestHeaders +) + +#set(headers +#) + +#set(libHeaders +#) + +#set(cudaSources +#) + +#set(cudaHeaders +#) + +#source_group("Header Files" FILES ${headers}) +#source_group("Lib Headers" FILES ${libHeaders}) +#source_group("CUDA Header Files" FILES ${cudaHeaders}) +#source_group("CUDA Source Files" FILES ${cudaSources}) diff --git a/test/GoogleTest.cmake b/test/GoogleTest.cmake new file mode 100644 index 0000000..3059d5f --- /dev/null +++ b/test/GoogleTest.cmake @@ -0,0 +1,42 @@ +# Download and unpack googletest at configure time +configure_file(${PROJECT_SOURCE_DIR}/test/CMakeLists.txt.in googletest-download/CMakeLists.txt) +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") +endif() +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "Build step for googletest failed: ${result}") +endif() + +# Prevent overriding the parent project's compiler/linker +# settings on Windows +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +# Add googletest directly to our build. This defines +# the gtest and gtest_main targets. +add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src + ${CMAKE_CURRENT_BINARY_DIR}/googletest-build + EXCLUDE_FROM_ALL) + +# The gtest/gtest_main targets carry header search path +# dependencies automatically when using CMake 2.8.11 or +# later. Otherwise we have to add them here ourselves. +if (CMAKE_VERSION VERSION_LESS 2.8.11) + include_directories("${gtest_SOURCE_DIR}/include") +endif() +# Include file lists +include(${PROJECT_SOURCE_DIR}/test/FileList.cmake) +#MESSAGE(STATUS "Cuda version: ${PROJECT_SOURCE_DIR}/CMake/FileList.cmake") +#include(${PROJECT_SOURCE_DIR}/CMake/FileList.cmake) + +# Now simply link against gtest or gtest_main as needed. Eg +add_executable(FPT_Test ${headers_simple_parallel} ${headers_lib} ${sources_lib} ${TestHeaders} ${TestSources}) +#add_executable(FPT_Test ${sources_simple_parallel} ${headers_simple_parallel} ${headers_lib} ${sources_lib} ${TestHeaders} ${TestSources}) +target_link_libraries(FPT_Test gtest_main) +add_test(NAME PKTest COMMAND PKTest) +#set(GOMC_GTEST 1) diff --git a/test/src/ParallelKernelizationTest.cpp b/test/src/ParallelKernelizationTest.cpp new file mode 100644 index 0000000..9cba3e3 --- /dev/null +++ b/test/src/ParallelKernelizationTest.cpp @@ -0,0 +1,7 @@ +#include +#include "ParallelKernelization.h" +TEST(PKTest, DegreeKernelTester) { + + EXPECT_EQ(true, true); + +}