Skip to content

Commit

Permalink
Expand tests for UsdUtil, building out a bit more test infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
mattelser committed Oct 20, 2023
1 parent 5ec6e4b commit 5a8e0d3
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ class ICesiumOmniverseCppTestsInterface:
def __init__(self, *args, **kwargs) -> None: ...
def on_shutdown(self) -> None: ...
def on_startup(self, arg0: str) -> None: ...
def run_all_tests(self, arg0: int) -> None: ...
def run_all_tests(self) -> None: ...
def set_up_tests(self, arg0: int) -> None: ...

def acquire_cesium_omniverse_tests_interface(
plugin_name: str = ..., library_path: str = ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import omni.usd
import omni.kit.ui
import omni.kit.app
from cesium.omniverse.utils import wait_n_frames
from .bindings import acquire_cesium_omniverse_tests_interface, release_cesium_omniverse_tests_interface


class CesiumOmniverseCppTestsExtension(omni.ext.IExt):
def __init__(self):
super().__init__()
self.tests_set_up = False

def on_startup(self):
print("Starting Cesium Tests Extension...")
Expand All @@ -30,12 +32,21 @@ def on_startup(self):
print("Started Cesium Tests Extension.")

def run_once_after_stage_opens(self, _):
# wait until the USD stage is fully set up
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()
# set up tests on one frame, then run the tests on the next frame
# note we can't use wait_n_frames here as this is a subscribed function
# so it cannot be async
if not self.tests_set_up:
self.tests_set_up = True
print("Beginning Cesium Tests Extension tests")
stageId = omni.usd.get_context().get_stage_id()
tests_interface.set_up_tests(stageId)
else:
# unsubscribe so there's no way the next frame triggers another run
self._run_once_sub.unsubscribe()
tests_interface.run_all_tests()
print("Cesium Tests Extension tests complete")

def on_shutdown(self):
print("Stopping Cesium Tests Extension...")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ class Data(pxr.Usd.Typed):
def CreateProjectDefaultIonAccessTokenAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateProjectDefaultIonAccessTokenIdAttr(cls, *args, **kwargs) -> Any: ...
def Define(self, *args, **kwargs) -> Any: ...
def Get(self, *args, **kwargs) -> Any: ...
@classmethod
def Define(cls, *args, **kwargs) -> Any: ...
@classmethod
def Get(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetDebugDisableGeometryPoolAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
Expand All @@ -60,10 +62,12 @@ class Data(pxr.Usd.Typed):
def GetProjectDefaultIonAccessTokenAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetProjectDefaultIonAccessTokenIdAttr(cls, *args, **kwargs) -> Any: ...
def GetSchemaAttributeNames(self, *args, **kwargs) -> Any: ...
def _GetStaticTfType(self, *args, **kwargs) -> Any: ...
@classmethod
def __bool__(cls) -> Any: ...
def GetSchemaAttributeNames(cls, *args, **kwargs) -> Any: ...
@classmethod
def _GetStaticTfType(cls, *args, **kwargs) -> Any: ...
@classmethod
def __bool__(cls) -> bool: ...
@classmethod
def __reduce__(cls) -> Any: ...

Expand All @@ -77,27 +81,33 @@ class Georeference(pxr.Usd.Typed):
def CreateGeoreferenceOriginLatitudeAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateGeoreferenceOriginLongitudeAttr(cls, *args, **kwargs) -> Any: ...
def Define(self, *args, **kwargs) -> Any: ...
def Get(self, *args, **kwargs) -> Any: ...
@classmethod
def Define(cls, *args, **kwargs) -> Any: ...
@classmethod
def Get(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetGeoreferenceOriginHeightAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetGeoreferenceOriginLatitudeAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetGeoreferenceOriginLongitudeAttr(cls, *args, **kwargs) -> Any: ...
def GetSchemaAttributeNames(self, *args, **kwargs) -> Any: ...
def _GetStaticTfType(self, *args, **kwargs) -> Any: ...
@classmethod
def __bool__(cls) -> Any: ...
def GetSchemaAttributeNames(cls, *args, **kwargs) -> Any: ...
@classmethod
def _GetStaticTfType(cls, *args, **kwargs) -> Any: ...
@classmethod
def __bool__(cls) -> bool: ...
@classmethod
def __reduce__(cls) -> Any: ...

class GlobeAnchorAPI(pxr.Usd.APISchemaBase):
__instance_size__: ClassVar[int] = ...
@classmethod
def __init__(cls, *args, **kwargs) -> None: ...
def Apply(self, *args, **kwargs) -> Any: ...
def CanApply(self, *args, **kwargs) -> Any: ...
@classmethod
def Apply(cls, *args, **kwargs) -> Any: ...
@classmethod
def CanApply(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateAdjustOrientationForGlobeWhenMovingAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
Expand All @@ -112,7 +122,8 @@ class GlobeAnchorAPI(pxr.Usd.APISchemaBase):
def CreateRotationAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateScaleAttr(cls, *args, **kwargs) -> Any: ...
def Get(self, *args, **kwargs) -> Any: ...
@classmethod
def Get(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetAdjustOrientationForGlobeWhenMovingAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
Expand All @@ -127,10 +138,12 @@ class GlobeAnchorAPI(pxr.Usd.APISchemaBase):
def GetRotationAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetScaleAttr(cls, *args, **kwargs) -> Any: ...
def GetSchemaAttributeNames(self, *args, **kwargs) -> Any: ...
def _GetStaticTfType(self, *args, **kwargs) -> Any: ...
@classmethod
def __bool__(cls) -> Any: ...
def GetSchemaAttributeNames(cls, *args, **kwargs) -> Any: ...
@classmethod
def _GetStaticTfType(cls, *args, **kwargs) -> Any: ...
@classmethod
def __bool__(cls) -> bool: ...
@classmethod
def __reduce__(cls) -> Any: ...

Expand All @@ -144,18 +157,22 @@ class Imagery(pxr.Usd.Typed):
def CreateIonAssetIdAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateShowCreditsOnScreenAttr(cls, *args, **kwargs) -> Any: ...
def Define(self, *args, **kwargs) -> Any: ...
def Get(self, *args, **kwargs) -> Any: ...
@classmethod
def Define(cls, *args, **kwargs) -> Any: ...
@classmethod
def Get(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetIonAccessTokenAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetIonAssetIdAttr(cls, *args, **kwargs) -> Any: ...
def GetSchemaAttributeNames(self, *args, **kwargs) -> Any: ...
@classmethod
def GetSchemaAttributeNames(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetShowCreditsOnScreenAttr(cls, *args, **kwargs) -> Any: ...
def _GetStaticTfType(self, *args, **kwargs) -> Any: ...
@classmethod
def __bool__(cls) -> Any: ...
def _GetStaticTfType(cls, *args, **kwargs) -> Any: ...
@classmethod
def __bool__(cls) -> bool: ...
@classmethod
def __reduce__(cls) -> Any: ...

Expand All @@ -165,14 +182,18 @@ class Session(pxr.Usd.Typed):
def __init__(cls, *args, **kwargs) -> None: ...
@classmethod
def CreateEcefToUsdTransformAttr(cls, *args, **kwargs) -> Any: ...
def Define(self, *args, **kwargs) -> Any: ...
def Get(self, *args, **kwargs) -> Any: ...
@classmethod
def Define(cls, *args, **kwargs) -> Any: ...
@classmethod
def Get(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetEcefToUsdTransformAttr(cls, *args, **kwargs) -> Any: ...
def GetSchemaAttributeNames(self, *args, **kwargs) -> Any: ...
def _GetStaticTfType(self, *args, **kwargs) -> Any: ...
@classmethod
def __bool__(cls) -> Any: ...
def GetSchemaAttributeNames(cls, *args, **kwargs) -> Any: ...
@classmethod
def _GetStaticTfType(cls, *args, **kwargs) -> Any: ...
@classmethod
def __bool__(cls) -> bool: ...
@classmethod
def __reduce__(cls) -> Any: ...

Expand Down Expand Up @@ -220,8 +241,10 @@ class Tileset(pxr.UsdGeom.Gprim):
def CreateSuspendUpdateAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def CreateUrlAttr(cls, *args, **kwargs) -> Any: ...
def Define(self, *args, **kwargs) -> Any: ...
def Get(self, *args, **kwargs) -> Any: ...
@classmethod
def Define(cls, *args, **kwargs) -> Any: ...
@classmethod
def Get(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetCulledScreenSpaceErrorAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
Expand Down Expand Up @@ -252,7 +275,8 @@ class Tileset(pxr.UsdGeom.Gprim):
def GetPreloadAncestorsAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetPreloadSiblingsAttr(cls, *args, **kwargs) -> Any: ...
def GetSchemaAttributeNames(self, *args, **kwargs) -> Any: ...
@classmethod
def GetSchemaAttributeNames(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetShowCreditsOnScreenAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
Expand All @@ -263,9 +287,10 @@ class Tileset(pxr.UsdGeom.Gprim):
def GetSuspendUpdateAttr(cls, *args, **kwargs) -> Any: ...
@classmethod
def GetUrlAttr(cls, *args, **kwargs) -> Any: ...
def _GetStaticTfType(self, *args, **kwargs) -> Any: ...
@classmethod
def __bool__(cls) -> Any: ...
def _GetStaticTfType(cls, *args, **kwargs) -> Any: ...
@classmethod
def __bool__(cls) -> bool: ...
@classmethod
def __reduce__(cls) -> Any: ...

Expand Down Expand Up @@ -370,13 +395,13 @@ class _CanApplyResult(Boost.Python.instance):
@classmethod
def __init__(cls, *args, **kwargs) -> None: ...
@classmethod
def __bool__(cls) -> Any: ...
def __bool__(cls) -> bool: ...
@classmethod
def __eq__(cls, other) -> Any: ...
def __eq__(cls, other) -> bool: ...
@classmethod
def __getitem__(cls, index) -> Any: ...
@classmethod
def __ne__(cls, other) -> Any: ...
def __ne__(cls, other) -> bool: ...
@classmethod
def __reduce__(cls) -> Any: ...
@property
Expand Down
1 change: 1 addition & 0 deletions tests/bindings/PythonBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +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("set_up_tests", &ICesiumOmniverseCppTestsInterface::setUpTests)
.def("run_all_tests", &ICesiumOmniverseCppTestsInterface::runAllTests)
.def("on_startup", &ICesiumOmniverseCppTestsInterface::onStartup)
.def("on_shutdown", &ICesiumOmniverseCppTestsInterface::onShutdown);
Expand Down
11 changes: 10 additions & 1 deletion tests/include/CesiumOmniverseCppTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ class ICesiumOmniverseCppTestsInterface {
*/
virtual void onShutdown() noexcept = 0;

virtual void runAllTests(long int stage_id) noexcept = 0;
/**
* @brief To be run at least one fram prior to `runAllTests` in order to
* allow time for USD notifications to propogate.
*/
virtual void setUpTests(long int stage_id) noexcept = 0;

/**
* @brief Collects and runs all the doctest tests defined in adjacent .cpp files
*/
virtual void runAllTests() noexcept = 0;
};

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

namespace cesium::omniverse::UsdUtil {
void setUpUsdUtilTests(long int stage_id);
void cleanUpUsdUtilTests();
}
26 changes: 22 additions & 4 deletions tests/src/CesiumOmniverseCppTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

#include "CesiumOmniverseCppTests.h"

#include "UsdUtilTests.h"
#include "testUtils.h"

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

#include <carb/PluginUtils.h>
#include <cesium/omniverse/UsdUtil.h>
#include <doctest/doctest.h>
#include <omni/fabric/IFabric.h>

Expand All @@ -28,11 +30,18 @@ class CesiumOmniverseCppTestsPlugin final : public ICesiumOmniverseCppTestsInter
Context::onShutdown();
}

void runAllTests(long int stage_id) noexcept override {
void setUpTests(long int stage_id) noexcept override {
// This runs after the stage has been created, but at least one frame
// before runAllTests. This is to allow time for USD notifications to
// propogate, as prims cannot be created and used on the same frame.

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

Context::instance().setStageId(stage_id);
cesium::omniverse::UsdUtil::setUpUsdUtilTests(stage_id);
}

void runAllTests() noexcept override {
CESIUM_LOG_INFO("Running Cesium Omniverse Tests");

// construct a doctest context
doctest::Context context;
Expand All @@ -48,7 +57,16 @@ class CesiumOmniverseCppTestsPlugin final : public ICesiumOmniverseCppTestsInter
// restore the previous working directory
std::filesystem::current_path(oldWorkingDir);

CESIUM_LOG_INFO("Cesium Omniverse Tests complete");
CESIUM_LOG_INFO("Cesium Omniverse tests complete");

CESIUM_LOG_INFO("Cleaning up after tests");
cleanUpAfterTests();
CESIUM_LOG_INFO("Cesium Omniverse test prims removed");
}

void cleanUpAfterTests() noexcept {
// delete any test related prims here
cesium::omniverse::UsdUtil::cleanUpUsdUtilTests();
}
};

Expand Down
4 changes: 4 additions & 0 deletions tests/src/ExampleTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ TEST_SUITE("Example Tests") {
x -= 1;
CHECK(x == 0);
}

// Flow returns here after each independant subcase, so we can test
// shared effects here
CHECK(x != 1);
}
// A few notes on subcases:
// - You can nest subcases
Expand Down
2 changes: 1 addition & 1 deletion tests/src/ObjectPoolTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void testRandomSequenceOfCmds(MockObjectPool& opl, int numEvents, bool setCap) {
if (maxActiveCount != 0) {
expectedPercentActive = (float)numActive / (float)maxActiveCount;
} else {
expectedPercentActive = 0;
expectedPercentActive = 1;
}
CHECK(opl.computePercentActive() <= expectedPercentActive);
}
Expand Down
Loading

0 comments on commit 5a8e0d3

Please sign in to comment.