Skip to content

Commit

Permalink
Merge pull request #468 from CesiumGS/createTestsExtension
Browse files Browse the repository at this point in the history
Set up basic tests extension to test c++ code
  • Loading branch information
mattelser authored Sep 27, 2023
2 parents 190b534 + 7b3dfe3 commit bdcd339
Show file tree
Hide file tree
Showing 20 changed files with 427 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ exts/cesium.omniverse/cesium/omniverse/bindings/CesiumOmniversePythonBindings.cp
exts/cesium.usd.plugins/cesium/usd/plugins/CesiumUsdSchemas/_CesiumUsdSchemas.so
exts/cesium.usd.plugins/cesium/usd/plugins/CesiumUsdSchemas/_CesiumUsdSchemas.pyd
exts/cesium.usd.plugins/cesium/usd/plugins/CesiumUsdSchemas/_CesiumUsdSchemas.lib
exts/cesium.omniverse.cpp.tests/cesium/omniverse/cpp/tests/bindings/CesiumOmniverseCppTestsPythonBindings.cpython-310-x86_64-linux-gnu.so
exts/cesium.omniverse.cpp.tests/cesium/omniverse/cpp/tests/bindings/CesiumOmniverseCppTestsPythonBindings.cp310-win_amd64.pyd

# Installed libraries
exts/cesium.omniverse/bin/
exts/cesium.usd.plugins/bin/
exts/cesium.omniverse.cpp.tests/bin/

# Installed plugins
exts/cesium.usd.plugins/plugins/
Expand Down
30 changes: 29 additions & 1 deletion .vscode/launch.linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@
}
]
},
{
"name": "Tests Extension",
"preLaunchTask": "Build Only (debug)",
"program": "${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/kit",
"args": [
"${workspaceFolder}/apps/cesium.omniverse.cpp.tests.runner.kit"
],
"env": {
// Disable LSAN when debugging since it doesn't work with GDB and prints harmless but annoying warning messages
"ASAN_OPTIONS": "detect_leaks=0",
"UBSAN_OPTIONS": "print_stacktrace=1"
},
"cwd": "${workspaceFolder}",
"type": "lldb",
"request": "launch",
"console": "externalTerminal",
"internalConsoleOptions": "openOnSessionStart",
"MIMode": "gdb",
"setupCommands": [
{
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"text": "set print elements 0"
}
]
},
{
"name": "Development App (Kit Debug)",
"preLaunchTask": "Build Only (debug)",
Expand Down Expand Up @@ -174,4 +202,4 @@
"host": "localhost"
}
]
}
}
24 changes: 23 additions & 1 deletion .vscode/launch.windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@
"console": "externalTerminal",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "Tests Extension",
"preLaunchTask": "Build Only (debug)",
"program": "${workspaceFolder}/extern/nvidia/_build/target-deps/kit-sdk/kit.exe",
"args": [
"${workspaceFolder}/apps/cesium.omniverse.cpp.tests.runner.kit"
],
"cwd": "${workspaceFolder}",
"type": "cppvsdbg",
"request": "launch",
"console": "externalTerminal",
"internalConsoleOptions": "openOnSessionStart",
"setupCommands": [
{
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"text": "set print elements 0"
}
]
},
{
"name": "Python Debugging (start)",
"preLaunchTask": "Build Only (debug)",
Expand All @@ -84,4 +106,4 @@
"host": "localhost"
}
]
}
}
57 changes: 56 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ set(LINT_SOURCE_DIRECTORIES
"${PROJECT_SOURCE_DIR}/src/bindings"
"${PROJECT_SOURCE_DIR}/src/core"
"${PROJECT_SOURCE_DIR}/src/public"
"${PROJECT_SOURCE_DIR}/tests")
"${PROJECT_SOURCE_DIR}/tests"
"${PROJECT_SOURCE_DIR}/cesiumOmniverseCppTestsExtension")

# Source directories for coverage
set(COVERAGE_SOURCE_DIRECTORIES "${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/src")
Expand Down Expand Up @@ -437,6 +438,7 @@ add_subdirectory(src)
if(CESIUM_OMNI_ENABLE_TESTS)
enable_testing()
add_subdirectory(tests)
add_subdirectory(cesiumOmniverseCppTestsExtension)
endif()

# Ninja and various Makefiles generators support generating compile_commands.json
Expand Down Expand Up @@ -511,6 +513,10 @@ set(KIT_EXTENSION_BINDINGS_PATH "${PROJECT_SOURCE_DIR}/exts/cesium.omniverse/ces
set(KIT_PLUGIN_EXTENSION_BINDINGS_PATH "${PROJECT_SOURCE_DIR}/exts/cesium.usd.plugins/cesium/usd/plugins")
set(KIT_EXTENSION_PLUGINS_PATH "${PROJECT_SOURCE_DIR}/exts/cesium.usd.plugins/plugins")

set(KIT_EXTENSION_TESTS_BIN_PATH "${PROJECT_SOURCE_DIR}/exts/cesium.omniverse.cpp.tests/bin")
set(KIT_EXTENSION_TESTS_BINDINGS_PATH
"${PROJECT_SOURCE_DIR}/exts/cesium.omniverse.cpp.tests/cesium/omniverse/cpp/tests/bindings")

# You may see warnings like:
#
# CMake Warning at build/src/cmake_install.cmake:115 (file):
Expand Down Expand Up @@ -663,6 +669,55 @@ install(
COMPONENT library
EXCLUDE_FROM_ALL)

install(
TARGETS cesium.omniverse.cpp.tests.plugin
ARCHIVE DESTINATION ${KIT_EXTENSION_TESTS_BIN_PATH} COMPONENT install
LIBRARY DESTINATION ${KIT_EXTENSION_TESTS_BIN_PATH} COMPONENT install
RUNTIME DESTINATION ${KIT_EXTENSION_TESTS_BIN_PATH} COMPONENT install)
install(
TARGETS cesium.omniverse.cpp.tests.plugin
RUNTIME_DEPENDENCIES
DIRECTORIES
${INSTALL_SEARCH_PATHS}
PRE_EXCLUDE_REGEXES
${INSTALL_PRE_EXCLUDE_REGEXES}
POST_EXCLUDE_REGEXES
${INSTALL_POST_EXCLUDE_REGEXES}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
EXCLUDE_FROM_ALL
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
EXCLUDE_FROM_ALL
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
EXCLUDE_FROM_ALL)

install(
TARGETS CesiumOmniverseCppTestsPythonBindings
ARCHIVE DESTINATION ${KIT_EXTENSION_TESTS_BINDINGS_PATH} COMPONENT install
LIBRARY DESTINATION ${KIT_EXTENSION_TESTS_BINDINGS_PATH} COMPONENT install
RUNTIME DESTINATION ${KIT_EXTENSION_TESTS_BINDINGS_PATH} COMPONENT install)

install(
TARGETS CesiumOmniverseCppTestsPythonBindings
RUNTIME_DEPENDENCIES
DIRECTORIES
${INSTALL_SEARCH_PATHS}
PRE_EXCLUDE_REGEXES
${INSTALL_PRE_EXCLUDE_REGEXES}
POST_EXCLUDE_REGEXES
${INSTALL_POST_EXCLUDE_REGEXES}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
EXCLUDE_FROM_ALL
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
EXCLUDE_FROM_ALL
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library
EXCLUDE_FROM_ALL)

install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include/"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
Expand Down
19 changes: 19 additions & 0 deletions apps/cesium.omniverse.cpp.tests.runner.kit
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
title = "Cesium For Omniverse Tests App"
version = "0.0.0"
app = true

[dependencies]
"cesium.omniverse.dev" = {}
"cesium.omniverse.cpp.tests" = {}

[settings]
app.window.title = "Cesium for Omniverse Tests App"

[settings.app.exts]
folders.'++' = [
"${app}", # Find other applications in this folder
"${app}/exts", # Find extensions in this folder
"${app}/../exts", # Find cesium.omniverse and cesium.usd.schemas
"${app}/../extern/nvidia/app/extscache" # Find omni.kit.window.material_graph
]
2 changes: 2 additions & 0 deletions cesiumOmniverseCppTestsExtension/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(bindings)
add_subdirectory(public)
25 changes: 25 additions & 0 deletions cesiumOmniverseCppTestsExtension/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
include(Macros)

glob_files(SOURCES "${CMAKE_CURRENT_LIST_DIR}/*.cpp")

# cmake-format: off
setup_python_module(
PYTHON_DIR
# Use the same Python version as Omniverse (Python 3.10)
"${PROJECT_SOURCE_DIR}/extern/nvidia/_build/target-deps/python"
TARGET_NAME
CesiumOmniverseCppTestsPythonBindings
SOURCES
${SOURCES}
LIBRARIES
cesium.omniverse.cpp.tests.plugin
CXX_FLAGS
${CESIUM_OMNI_CXX_FLAGS}
CXX_FLAGS_DEBUG
${CESIUM_OMNI_CXX_FLAGS_DEBUG}
CXX_DEFINES
${CESIUM_OMNI_CXX_DEFINES}
CXX_DEFINES_DEBUG
${CESIUM_OMNI_CXX_DEFINES_DEBUG}
)
# cmake-format: on
22 changes: 22 additions & 0 deletions cesiumOmniverseCppTestsExtension/bindings/PythonBindings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "CesiumOmniverseCppTests.h"

#include <carb/BindingsPythonUtils.h>

// NOLINTNEXTLINE
CARB_BINDINGS("cesium.omniverse.cpp.tests.python")
DISABLE_PYBIND11_DYNAMIC_CAST(cesium::omniverse::tests::ICesiumOmniverseCppTestsInterface)

PYBIND11_MODULE(CesiumOmniverseCppTestsPythonBindings, m) {

using namespace cesium::omniverse::tests;

m.doc() = "pybind11 cesium.omniverse.cpp.tests bindings";

// clang-format off
carb::defineInterfaceClass<ICesiumOmniverseCppTestsInterface>(
m, "ICesiumOmniverseCppTestsInterface", "acquire_cesium_omniverse_tests_interface", "release_cesium_omniverse_tests_interface")
.def("run_all_tests", &ICesiumOmniverseCppTestsInterface::run_all_tests)
.def("on_startup", &ICesiumOmniverseCppTestsInterface::onStartup)
.def("on_shutdown", &ICesiumOmniverseCppTestsInterface::onShutdown);
// clang-format on
}
24 changes: 24 additions & 0 deletions cesiumOmniverseCppTestsExtension/include/CesiumOmniverseCppTests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once
#include <carb/Interface.h>

namespace cesium::omniverse::tests {

class ICesiumOmniverseCppTestsInterface {
public:
CARB_PLUGIN_INTERFACE("cesium::omniverse::tests::ICesiumOmniverseCppTestsInterface", 0, 0);
/**
* @brief Call this on extension startup.
*
* @param cesiumExtensionLocation Path to the Cesium Omniverse extension location.
*/
virtual void onStartup(const char* cesiumExtensionLocation) noexcept = 0;

/**
* @brief Call this on extension shutdown.
*/
virtual void onShutdown() noexcept = 0;

virtual void run_all_tests(long int stage_id) noexcept = 0;
};

} // namespace cesium::omniverse::tests
34 changes: 34 additions & 0 deletions cesiumOmniverseCppTestsExtension/public/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
include(Macros)

glob_files(SOURCES "${CMAKE_CURRENT_LIST_DIR}/*.cpp")

get_property(ADDITIONAL_LIBRARIES GLOBAL PROPERTY NVIDIA_ADDITIONAL_LIBRARIES_PROPERTY)

# cmake-format: off
setup_lib(
TARGET_NAME
cesium.omniverse.cpp.tests.plugin
TYPE
# Carbonite Plugins needs to be shared libraries
SHARED
SOURCES
${SOURCES}
INCLUDE_DIRS
"${PROJECT_SOURCE_DIR}/cesiumOmniverseCppTestsExtension/include"
LIBRARIES
CesiumOmniverseCore
doctest::doctest
ADDITIONAL_LIBRARIES
# Unfortunately we need this in both cesium.omniverse.plugin and CesiumOmniverseCore because we're bypassing
# CMake's built-in dependency system
"${ADDITIONAL_LIBRARIES}"
CXX_FLAGS
${CESIUM_OMNI_CXX_FLAGS}
CXX_FLAGS_DEBUG
${CESIUM_OMNI_CXX_FLAGS_DEBUG}
CXX_DEFINES
${CESIUM_OMNI_CXX_DEFINES}
CXX_DEFINES_DEBUG
${CESIUM_OMNI_CXX_DEFINES_DEBUG}
)
# cmake-format: on
Loading

0 comments on commit bdcd339

Please sign in to comment.