Skip to content

Commit

Permalink
Reorganize C++ Tests (#1095)
Browse files Browse the repository at this point in the history
I have a few changes here. Some of them might not make it depending on how others feel.

- Move test utilities in to a library to share across tests.
- Move tests in to individual executable to enforce individual tests to not sharing code.
- Use `gtest_discover_tests` to let `ctest` run and show all tests individually.
- Use `gtest::gtest_main` and remove explicit main entry file.
- ~Build and run tests by default.~
- Ability to filter tests by `ctest --test-dir build -R "TestCuda.*"`

```
+ echo 'Running CTest...'
Running CTest...
+ ctest --test-dir build
Internal ctest changing into directory: /workspaces/morpheus/build
Test project /workspaces/morpheus/build
      Start  1: TestCuda.LargeShape
 1/35 Test  #1: TestCuda.LargeShape .......................................   Passed    0.17 sec
      Start  2: TestDataLoader.DataLoaderInitializationTest
 2/35 Test  #2: TestDataLoader.DataLoaderInitializationTest ...............   Passed    0.07 sec
      Start  3: TestDataLoader.DataLoaderRegisterLoaderTest
 3/35 Test  #3: TestDataLoader.DataLoaderRegisterLoaderTest ...............   Passed    0.07 sec
      Start  4: TestDataLoader.DataLoaderRemoveLoaderTest
 4/35 Test  #4: TestDataLoader.DataLoaderRemoveLoaderTest .................   Passed    0.07 sec
      Start  5: TestDataLoader.PayloadLoaderTest
 5/35 Test  #5: TestDataLoader.PayloadLoaderTest ..........................   Passed    1.42 sec
      Start  6: TestDataLoader.FileLoaderTest
 6/35 Test  #6: TestDataLoader.FileLoaderTest .............................   Passed    2.65 sec
      Start  7: TestControlMessage.InitializationTest
 7/35 Test  #7: TestControlMessage.InitializationTest .....................   Passed    0.07 sec
      Start  8: TestControlMessage.SetMessageTest
 8/35 Test  #8: TestControlMessage.SetMessageTest .........................   Passed    0.07 sec
      Start  9: TestControlMessage.TaskTest
 9/35 Test  #9: TestControlMessage.TaskTest ...............................   Passed    0.07 sec
      Start 10: TestControlMessage.PayloadTest
10/35 Test #10: TestControlMessage.PayloadTest ............................   Passed    1.45 sec
      Start 11: TestDataLoaderModule.DataLoaderModuleInitializationTest
11/35 Test #11: TestDataLoaderModule.DataLoaderModuleInitializationTest ...   Passed    0.07 sec
      Start 12: TestDataLoaderModule.EndToEndPayloadDataLoaderTest
12/35 Test #12: TestDataLoaderModule.EndToEndPayloadDataLoaderTest ........   Passed    0.12 sec
      Start 13: TestDeserializers.GetIndexColCountNoIdxFromFile
13/35 Test #13: TestDeserializers.GetIndexColCountNoIdxFromFile ...........   Passed    1.39 sec
      Start 14: TestDeserializers.GetIndexColCountWithIdxFromFile
14/35 Test #14: TestDeserializers.GetIndexColCountWithIdxFromFile .........   Passed    1.37 sec
      Start 15: TestDeserializers.GetIndexColCountNoIdxSimilarName
15/35 Test #15: TestDeserializers.GetIndexColCountNoIdxSimilarName ........   Passed    0.19 sec
      Start 16: TestDeserializers.GetIndexColCountIdx
16/35 Test #16: TestDeserializers.GetIndexColCountIdx .....................   Passed    0.18 sec
      Start 17: TestDeserializers.GetIndexColCountValidNameInvalidType
17/35 Test #17: TestDeserializers.GetIndexColCountValidNameInvalidType ....   Passed    0.16 sec
      Start 18: TestDevMemInfo.RmmBufferConstructor
18/35 Test #18: TestDevMemInfo.RmmBufferConstructor .......................   Passed    0.16 sec
      Start 19: TestDevMemInfo.VoidPtrConstructor
19/35 Test #19: TestDevMemInfo.VoidPtrConstructor .........................   Passed    0.25 sec
      Start 20: TestDevMemInfo.MakeNewBuffer
20/35 Test #20: TestDevMemInfo.MakeNewBuffer ..............................   Passed    0.25 sec
      Start 21: TestFileInOut.RoundTripCSV
21/35 Test #21: TestFileInOut.RoundTripCSV ................................   Passed    2.67 sec
      Start 22: TestFileInOut.RoundTripJSON
22/35 Test #22: TestFileInOut.RoundTripJSON ...............................   Passed    2.69 sec
      Start 23: TestMatxUtil.ReduceMax1d
23/35 Test #23: TestMatxUtil.ReduceMax1d ..................................   Passed    0.17 sec
      Start 24: TestMatxUtil.ReduceMax2dRowMajor
24/35 Test #24: TestMatxUtil.ReduceMax2dRowMajor ..........................   Passed    0.17 sec
      Start 25: TestMatxUtil.ReduceMax2dColMajor
25/35 Test #25: TestMatxUtil.ReduceMax2dColMajor ..........................   Passed    1.40 sec
      Start 26: TestMatxUtil.Cast
26/35 Test #26: TestMatxUtil.Cast .........................................   Passed    0.16 sec
      Start 27: TestMatxUtil.Threshold
27/35 Test #27: TestMatxUtil.Threshold ....................................   Passed    0.16 sec
      Start 28: TestMatxUtil.ThresholdByRow
28/35 Test #28: TestMatxUtil.ThresholdByRow ...............................   Passed    0.19 sec
      Start 29: TestMultiSlices.Ranges
29/35 Test #29: TestMultiSlices.Ranges ....................................   Passed    1.37 sec
      Start 30: TestTensor.UtilsShapeString
30/35 Test #30: TestTensor.UtilsShapeString ...............................   Passed    0.06 sec
      Start 31: TestTensor.GetElementStride
31/35 Test #31: TestTensor.GetElementStride ...............................   Passed    0.06 sec
      Start 32: TestTensor.AsType
32/35 Test #32: TestTensor.AsType .........................................   Passed    0.16 sec
      Start 33: TestTensor.Create
33/35 Test #33: TestTensor.Create .........................................   Passed    0.16 sec
      Start 34: TestTensor.UtilsValidateShapeAndStride
34/35 Test #34: TestTensor.UtilsValidateShapeAndStride ....................   Passed    0.16 sec
      Start 35: TestTypeUtils.DTypeCopy
35/35 Test #35: TestTypeUtils.DTypeCopy ...................................   Passed    0.06 sec

100% tests passed, 0 tests failed out of 35

Total Test time (real) =  19.91 sec
```

Authors:
  - Christopher Harris (https://github.com/cwharris)

Approvers:
  - David Gardner (https://github.com/dagardner-nv)

URL: #1095
  • Loading branch information
cwharris authored Aug 2, 2023
1 parent 7719873 commit b228389
Show file tree
Hide file tree
Showing 23 changed files with 99 additions and 78 deletions.
106 changes: 78 additions & 28 deletions morpheus/_lib/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,103 @@ list(APPEND CMAKE_MESSAGE_CONTEXT "tests")

find_package(pybind11 REQUIRED)

# Keep all source files sorted
add_executable(test_libmorpheus
include(GoogleTest)

add_library(
morpheus_test_utilities
test_utils/common.cpp
)

target_link_libraries(
morpheus_test_utilities
PRIVATE
GTest::gtest
morpheus
)

function (add_morpheus_test TEST_NAME TEST_FILES)

add_executable(
test_${TEST_NAME}
${TEST_FILES}
)

target_link_libraries(
test_${TEST_NAME}
PRIVATE
GTest::gtest
GTest::gtest_main
matx::matx
morpheus
morpheus_test_utilities
pybind11::embed
)

gtest_discover_tests(test_${TEST_NAME})

set_target_properties(test_${TEST_NAME}
PROPERTIES
INSTALL_RPATH "$ORIGIN/.."
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON
)

install(
TARGETS
test_${TEST_NAME}
RUNTIME DESTINATION
"${MORPHEUS_LIB_INSTALL_DIR}/tests"
COMPONENT Wheel
)

endfunction()

add_morpheus_test(cuda
test_cuda.cu
)

add_morpheus_test(data_loader
io/test_data_loader.cpp
io/test_data_loader_registry.cpp
io/test_loaders.cpp
)

add_morpheus_test(messages
messages/test_control_message.cpp
messages/test_dev_doc_ex3.cpp
messages/test_sliced_message_meta.cpp
)

add_morpheus_test(modules
modules/test_data_loader_module.cpp
)

add_morpheus_test(deserializers
test_deserializers.cpp
)

add_morpheus_test(dev_mem_info
test_dev_mem_info.cpp
)

add_morpheus_test(file_io
test_file_in_out.cpp
test_main.cpp
test_matx_util.cpp
test_morpheus.cpp
test_multi_slices.cpp
test_tensor.cpp
test_type_util.cpp
)

target_link_libraries(test_libmorpheus
PRIVATE
GTest::gtest
matx::matx
morpheus
pybind11::embed
add_morpheus_test(matx
test_matx_util.cpp
)

add_test(
NAME test_libmorpheus
COMMAND $<TARGET_FILE:test_libmorpheus>
add_morpheus_test(multi_slices
test_multi_slices.cpp
)

set_target_properties(test_libmorpheus
PROPERTIES
INSTALL_RPATH "$ORIGIN/.."
CUDA_STANDARD 17
CUDA_STANDARD_REQUIRED ON
add_morpheus_test(tensor
test_tensor.cpp
)

install(
TARGETS
test_libmorpheus
RUNTIME DESTINATION
"${MORPHEUS_LIB_INSTALL_DIR}/tests"
COMPONENT Wheel
add_morpheus_test(type_util
test_type_util.cpp
)

list(POP_BACK CMAKE_MESSAGE_CONTEXT)
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/io/test_data_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "../test_morpheus.hpp" // IWYU pragma: associated
#include "../test_utils/common.hpp" // IWYU pragma: associated
#include "test_io.hpp"

#include "morpheus/io/data_loader.hpp"
Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/io/test_data_loader_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "../test_morpheus.hpp" // IWYU pragma: associated
#include "../test_utils/common.hpp" // IWYU pragma: associated
#include "test_io.hpp"

#include "morpheus/io/data_loader_registry.hpp"
Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/io/test_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#pragma once

#include "../test_morpheus.hpp" // IWYU pragma: associated
#include "../test_utils/common.hpp" // IWYU pragma: associated

namespace morpheus::test {

Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/io/test_loaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "../test_morpheus.hpp" // IWYU pragma: associated
#include "../test_utils/common.hpp" // IWYU pragma: associated
#include "test_io.hpp"

#include "morpheus/io/loaders/file.hpp"
Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/messages/test_control_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "../test_morpheus.hpp" // IWYU pragma: associated
#include "../test_utils/common.hpp" // IWYU pragma: associated
#include "test_messages.hpp"

#include "morpheus/messages/control.hpp"
Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/messages/test_dev_doc_ex3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "../test_morpheus.hpp" // IWYU pragma: associated
#include "../test_utils/common.hpp" // IWYU pragma: associated

#include "morpheus/messages/meta.hpp" // for MessageMeta
#include "morpheus/messages/multi.hpp" // for MultiMessage
Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/messages/test_messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#pragma once

#include "../test_morpheus.hpp" // IWYU pragma: associated
#include "../test_utils/common.hpp" // IWYU pragma: associated

namespace morpheus::test {

Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/messages/test_sliced_message_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "../test_morpheus.hpp" // IWYU pragma: associated
#include "../test_utils/common.hpp" // IWYU pragma: associated

#include "morpheus/io/deserializers.hpp" // for load_table_from_file, prepare_df_index
#include "morpheus/messages/meta.hpp" // for MessageMeta and SlicedMessageMeta
Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/modules/test_data_loader_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "../test_morpheus.hpp" // IWYU pragma: associated
#include "../test_utils/common.hpp" // IWYU pragma: associated
#include "mrc/runnable/types.hpp"
#include "test_modules.hpp"

Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/modules/test_modules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#pragma once

#include "../test_morpheus.hpp" // IWYU pragma: associated
#include "../test_utils/common.hpp" // IWYU pragma: associated

namespace morpheus::test {

Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/test_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "test_morpheus.hpp"
#include "./test_utils/common.hpp"

#include <matx.h>

Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/test_deserializers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "./test_morpheus.hpp" // IWYU pragma: associated
#include "./test_utils/common.hpp" // IWYU pragma: associated

#include "morpheus/io/deserializers.hpp"

Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/test_dev_mem_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "./test_morpheus.hpp" // IWYU pragma: associated
#include "./test_utils/common.hpp" // IWYU pragma: associated

#include "morpheus/objects/dev_mem_info.hpp"
#include "morpheus/objects/dtype.hpp" // for DType
Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/test_file_in_out.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "./test_morpheus.hpp" // IWYU pragma: associated
#include "./test_utils/common.hpp" // IWYU pragma: associated

#include "morpheus/io/deserializers.hpp"
#include "morpheus/io/serializers.hpp"
Expand Down
29 changes: 0 additions & 29 deletions morpheus/_lib/tests/test_main.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion morpheus/_lib/tests/test_matx_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "./test_morpheus.hpp" // IWYU pragma: associated
#include "./test_utils/common.hpp" // IWYU pragma: associated

#include "morpheus/io/deserializers.hpp"
#include "morpheus/objects/dev_mem_info.hpp"
Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/test_multi_slices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "./test_morpheus.hpp" // IWYU pragma: associated
#include "./test_utils/common.hpp" // IWYU pragma: associated

#include "morpheus/io/deserializers.hpp"

Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/test_tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "./test_morpheus.hpp" // IWYU pragma: associated
#include "./test_utils/common.hpp" // IWYU pragma: associated

#include "morpheus/objects/dtype.hpp" // for DType
#include "morpheus/objects/memory_descriptor.hpp" // for MemoryDescriptor
Expand Down
2 changes: 1 addition & 1 deletion morpheus/_lib/tests/test_type_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "./test_morpheus.hpp" // IWYU pragma: associated
#include "./test_utils/common.hpp" // IWYU pragma: associated

#include "morpheus/objects/dtype.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

#include "test_morpheus.hpp"
#include "./common.hpp"

#include "morpheus/io/data_loader_registry.hpp"
#include "morpheus/io/loaders/file.hpp"
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions scripts/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ echo "Runing CMake configure..."
# Use some standard default values plus CMAKE_ARGS and CMAKE_CONFIGURE_EXTRA_ARGS
# CMAKE_ARGS is supplied by the conda environment
# CMAKE_CONFIGURE_EXTRA_ARGS is supplied by the user
cmake -B ${BUILD_DIR} -GNinja \
cmake -S . -B ${BUILD_DIR} -GNinja \
-DCMAKE_MESSAGE_CONTEXT_SHOW=ON \
-DMORPHEUS_USE_CLANG_TIDY=OFF \
-DMORPHEUS_PYTHON_INPLACE_BUILD=ON \
Expand All @@ -34,7 +34,7 @@ cmake -B ${BUILD_DIR} -GNinja \
-DMORPHEUS_SUPPORT_DOCA=${MORPHEUS_SUPPORT_DOCA:-OFF} \
${INSTALL_PREFIX:+-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}} \
${CMAKE_ARGS:+${CMAKE_ARGS}} \
${CMAKE_CONFIGURE_EXTRA_ARGS:+${CMAKE_CONFIGURE_EXTRA_ARGS}} .
${CMAKE_CONFIGURE_EXTRA_ARGS:+${CMAKE_CONFIGURE_EXTRA_ARGS}}

echo "Running CMake build..."
cmake --build ${BUILD_DIR} -j ${INSTALL_PREFIX:+--target install} "$@"

0 comments on commit b228389

Please sign in to comment.