Skip to content

Commit

Permalink
Tests extension now waits for stage to open before running (#484)
Browse files Browse the repository at this point in the history
Tests extension now waits for stage to open before running
  • Loading branch information
mattelser authored Oct 5, 2023
1 parent c8edb67 commit 0ffa9e7
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 11 deletions.
32 changes: 31 additions & 1 deletion .vscode/launch.linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,36 @@
}
]
},
{
"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": "cppdbg",
"request": "launch",
"MIMode": "gdb",
"setupCommands": [
{
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"text": "set print elements 0"
}
],
"symbolLoadInfo": {
"loadAll": false,
"exceptionList": "libcesium.omniverse.plugin.so;libcesium.omniverse.cpp.tests.plugin.so"
}
},
{
"name": "Python Debugging (attach)",
"type": "python",
Expand All @@ -95,4 +125,4 @@
"host": "localhost"
}
]
}
}
13 changes: 12 additions & 1 deletion .vscode/launch.windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@
"type": "cppvsdbg",
"request": "launch"
},
{
"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"
},
{
"name": "Python Debugging (attach)",
"type": "python",
Expand All @@ -42,4 +53,4 @@
"host": "localhost"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PYBIND11_MODULE(CesiumOmniverseCppTestsPythonBindings, m) {
// 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("run_all_tests", &ICesiumOmniverseCppTestsInterface::runAllTests)
.def("on_startup", &ICesiumOmniverseCppTestsInterface::onStartup)
.def("on_shutdown", &ICesiumOmniverseCppTestsInterface::onShutdown);
// clang-format on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ICesiumOmniverseCppTestsInterface {
*/
virtual void onShutdown() noexcept = 0;

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

} // namespace cesium::omniverse::tests
3 changes: 3 additions & 0 deletions cesiumOmniverseCppTestsExtension/include/UsdUtilTests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void runAllUsdUtilTests();
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

#include "CesiumOmniverseCppTests.h"

#include "UsdUtilTests.h"

#include "cesium/omniverse/Context.h"
#include "cesium/omniverse/LoggerSink.h"
#include "cesium/omniverse/UsdUtil.h"

#include <carb/PluginUtils.h>
#include <doctest/doctest.h>
Expand Down Expand Up @@ -62,11 +63,13 @@ class CesiumOmniverseCppTestsPlugin final : public ICesiumOmniverseCppTestsInter
Context::onShutdown();
}

void run_all_tests(long int stage_id) noexcept override {
void runAllTests(long int stage_id) noexcept override {

CESIUM_LOG_INFO("Running Cesium Omniverse Tests with stage id: {}", stage_id);

// construct a context
Context::instance().setStageId(stage_id);

// construct a doctest context
doctest::Context context;

// sets the context as the default one - so asserts used outside of a testing context do not crash
Expand All @@ -77,6 +80,7 @@ class CesiumOmniverseCppTestsPlugin final : public ICesiumOmniverseCppTestsInter
context.setAssertHandler(handler);

exampleTest();
runAllUsdUtilTests();

CESIUM_LOG_INFO("Cesium Omniverse Tests complete");
}
Expand Down
15 changes: 15 additions & 0 deletions cesiumOmniverseCppTestsExtension/public/UsdUtilTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "UsdUtilTests.h"

#include "cesium/omniverse/Context.h"
#include "cesium/omniverse/LoggerSink.h"
#include "cesium/omniverse/UsdUtil.h"

#include <doctest/doctest.h>

void runAllUsdUtilTests() {
// CESIUM_LOG_INFO macro can only be run inside the cesium::omniverse namespace
using namespace cesium::omniverse;
CESIUM_LOG_INFO("Running UsdUtil Tests...");
CHECK(UsdUtil::primExists(pxr::SdfPath("/Cesium")));
CESIUM_LOG_INFO("UsdUtil Tests complete!");
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import omni.ext
import omni.usd
import omni.kit.ui
import omni.kit.app
from .bindings import acquire_cesium_omniverse_tests_interface, release_cesium_omniverse_tests_interface


Expand All @@ -14,15 +16,27 @@ def on_startup(self):
global tests_interface
tests_interface = acquire_cesium_omniverse_tests_interface()

tests_interface.on_startup("exts/cesium.omniverse")
tests_interface.on_startup(os.path.join(os.path.dirname(__file__), "../../../../../cesium.omniverse"))

# TODO ensure the stage has been set up before getting stage id
stageId = omni.usd.get_context().get_stage_id()
update_stream = omni.kit.app.get_app().get_update_event_stream()

tests_interface.run_all_tests(stageId)
# To ensure the tests only run after the stage has been opened, we
# attach a handler to an event that occurs every frame. That handler
# checks if the stage has opened, runs once, then detaches itself
self._run_once_sub = update_stream.create_subscription_to_pop(
self.run_once_after_stage_opens, name="Run once after stage opens"
)

print("Started Cesium Tests Extension.")

def run_once_after_stage_opens(self, _):
if omni.usd.get_context().get_stage_state() == omni.usd.StageState.OPENED:
print("Beginning Cesium Tests Extension tests")
stageId = omni.usd.get_context().get_stage_id()
tests_interface.run_all_tests(stageId)
print("Cesium Tests Extension tests complete")
self._run_once_sub.unsubscribe()

def on_shutdown(self):
print("Stopping Cesium Tests Extension...")
release_cesium_omniverse_tests_interface(tests_interface)
Expand Down

0 comments on commit 0ffa9e7

Please sign in to comment.