Adds Light component tests (non-GPU portion) to AutomatedTesting from AtomTest (#2758)
* Fixed Vegetation Layer Spawner documentation link. Signed-off-by: Chris Galvan <chgalvan@amazon.com> Signed-off-by: jromnoa <jromnoa@amazon.com> * add remaining non-GPU test portions for Light component test Signed-off-by: jromnoa <jromnoa@amazon.com> * make non-GPU light component test more robust Signed-off-by: jromnoa <jromnoa@amazon.com> * remove redundant logging, convert LIGHT_TYPES from list to dict, remove redundant f-string Signed-off-by: jromnoa <jromnoa@amazon.com> Co-authored-by: Chris Galvan <chgalvan@amazon.com>
This commit is contained in:
@@ -17,7 +17,7 @@ if(PAL_TRAIT_BUILD_HOST_TOOLS AND PAL_TRAIT_BUILD_TESTS_SUPPORTED AND AutomatedT
|
||||
TEST_SUITE main
|
||||
PATH ${CMAKE_CURRENT_LIST_DIR}/test_Atom_MainSuite.py
|
||||
TEST_SERIAL
|
||||
TIMEOUT 400
|
||||
TIMEOUT 600
|
||||
RUNTIME_DEPENDENCIES
|
||||
AssetProcessor
|
||||
AutomatedTesting.Assets
|
||||
|
||||
+217
@@ -0,0 +1,217 @@
|
||||
"""
|
||||
Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
|
||||
SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
Hydra script that creates an entity, attaches the Light component to it for test verifications.
|
||||
The test verifies that each light type option is available and can be selected without errors.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import azlmbr.bus as bus
|
||||
import azlmbr.editor as editor
|
||||
import azlmbr.math as math
|
||||
import azlmbr.paths
|
||||
import azlmbr.legacy.general as general
|
||||
|
||||
sys.path.append(os.path.join(azlmbr.paths.devassets, "Gem", "PythonTests"))
|
||||
|
||||
import editor_python_test_tools.hydra_editor_utils as hydra
|
||||
from atom_renderer.atom_utils.atom_component_helper import LIGHT_TYPES
|
||||
|
||||
LIGHT_TYPE_PROPERTY = 'Controller|Configuration|Light type'
|
||||
SPHERE_AND_SPOT_DISK_LIGHT_PROPERTIES = [
|
||||
("Controller|Configuration|Shadows|Enable shadow", True),
|
||||
("Controller|Configuration|Shadows|Shadowmap size", 0), # 256
|
||||
("Controller|Configuration|Shadows|Shadowmap size", 1), # 512
|
||||
("Controller|Configuration|Shadows|Shadowmap size", 2), # 1024
|
||||
("Controller|Configuration|Shadows|Shadowmap size", 3), # 2048
|
||||
("Controller|Configuration|Shadows|Shadow filter method", 1), # PCF
|
||||
("Controller|Configuration|Shadows|Filtering sample count", 4.0),
|
||||
("Controller|Configuration|Shadows|Filtering sample count", 64.0),
|
||||
("Controller|Configuration|Shadows|PCF method", 0), # Bicubic
|
||||
("Controller|Configuration|Shadows|PCF method", 1), # Boundary search
|
||||
("Controller|Configuration|Shadows|Shadow filter method", 2), # ECM
|
||||
("Controller|Configuration|Shadows|ESM exponent", 50),
|
||||
("Controller|Configuration|Shadows|ESM exponent", 5000),
|
||||
("Controller|Configuration|Shadows|Shadow filter method", 3), # ESM+PCF
|
||||
]
|
||||
QUAD_LIGHT_PROPERTIES = [
|
||||
("Controller|Configuration|Both directions", True),
|
||||
("Controller|Configuration|Fast approximation", True),
|
||||
]
|
||||
SIMPLE_POINT_LIGHT_PROPERTIES = [
|
||||
("Controller|Configuration|Attenuation radius|Mode", 0),
|
||||
("Controller|Configuration|Attenuation radius|Radius", 100.0),
|
||||
]
|
||||
SIMPLE_SPOT_LIGHT_PROPERTIES = [
|
||||
("Controller|Configuration|Shutters|Inner angle", 45.0),
|
||||
("Controller|Configuration|Shutters|Outer angle", 90.0),
|
||||
]
|
||||
|
||||
|
||||
def verify_required_component_property_value(entity_name, component, property_path, expected_property_value):
|
||||
"""
|
||||
Compares the property value of component against the expected_property_value.
|
||||
:param entity_name: name of the entity to use (for test verification purposes).
|
||||
:param component: component to check on a given entity for its current property value.
|
||||
:param property_path: the path to the property inside the component.
|
||||
:param expected_property_value: The value expected from the value inside property_path.
|
||||
:return: None, but prints to general.log() which the test uses to verify against.
|
||||
"""
|
||||
property_value = editor.EditorComponentAPIBus(
|
||||
bus.Broadcast, "GetComponentProperty", component, property_path).GetValue()
|
||||
general.log(f"{entity_name}_test: Property value is {property_value} "
|
||||
f"which matches {expected_property_value}")
|
||||
|
||||
|
||||
def run():
|
||||
"""
|
||||
Test Case - Light Component
|
||||
1. Creates a "light_entity" Entity and attaches a "Light" component to it.
|
||||
2. Updates the Light component to each light type option from the LIGHT_TYPES constant.
|
||||
3. The test will check the Editor log to ensure each light type was selected.
|
||||
4. Prints the string "Light component test (non-GPU) completed" after completion.
|
||||
|
||||
Tests will fail immediately if any of these log lines are found:
|
||||
1. Trace::Assert
|
||||
2. Trace::Error
|
||||
3. Traceback (most recent call last):
|
||||
|
||||
:return: None
|
||||
"""
|
||||
# Create a "light_entity" entity with "Light" component.
|
||||
light_entity_name = "light_entity"
|
||||
light_component = "Light"
|
||||
light_entity = hydra.Entity(light_entity_name)
|
||||
light_entity.create_entity(math.Vector3(-1.0, -2.0, 3.0), [light_component])
|
||||
general.log(
|
||||
f"{light_entity_name}_test: Component added to the entity: "
|
||||
f"{hydra.has_components(light_entity.id, [light_component])}")
|
||||
|
||||
# Populate the light_component_id_pair value so that it can be used to select all Light component options.
|
||||
light_component_id_pair = None
|
||||
component_type_id_list = azlmbr.editor.EditorComponentAPIBus(
|
||||
azlmbr.bus.Broadcast, 'FindComponentTypeIdsByEntityType', [light_component], 0)
|
||||
if len(component_type_id_list) < 1:
|
||||
general.log(f"ERROR: A component class with name {light_component} doesn't exist")
|
||||
light_component_id_pair = None
|
||||
elif len(component_type_id_list) > 1:
|
||||
general.log(f"ERROR: Found more than one component classes with same name: {light_component}")
|
||||
light_component_id_pair = None
|
||||
entity_component_id_pair = azlmbr.editor.EditorComponentAPIBus(
|
||||
azlmbr.bus.Broadcast, 'GetComponentOfType', light_entity.id, component_type_id_list[0])
|
||||
if entity_component_id_pair.IsSuccess():
|
||||
light_component_id_pair = entity_component_id_pair.GetValue()
|
||||
|
||||
# Test each Light component option can be selected and it's properties updated.
|
||||
# Point (sphere) light type checks.
|
||||
light_type_property_test(
|
||||
light_type=LIGHT_TYPES['sphere'],
|
||||
light_properties=SPHERE_AND_SPOT_DISK_LIGHT_PROPERTIES,
|
||||
light_component_id_pair=light_component_id_pair,
|
||||
light_entity_name=light_entity_name,
|
||||
light_entity=light_entity
|
||||
)
|
||||
|
||||
# Spot (disk) light type checks.
|
||||
light_type_property_test(
|
||||
light_type=LIGHT_TYPES['spot_disk'],
|
||||
light_properties=SPHERE_AND_SPOT_DISK_LIGHT_PROPERTIES,
|
||||
light_component_id_pair=light_component_id_pair,
|
||||
light_entity_name=light_entity_name,
|
||||
light_entity=light_entity
|
||||
)
|
||||
|
||||
# Capsule light type checks.
|
||||
azlmbr.editor.EditorComponentAPIBus(
|
||||
azlmbr.bus.Broadcast,
|
||||
'SetComponentProperty',
|
||||
light_component_id_pair,
|
||||
LIGHT_TYPE_PROPERTY,
|
||||
LIGHT_TYPES['capsule']
|
||||
)
|
||||
verify_required_component_property_value(
|
||||
entity_name=light_entity_name,
|
||||
component=light_entity.components[0],
|
||||
property_path=LIGHT_TYPE_PROPERTY,
|
||||
expected_property_value=LIGHT_TYPES['capsule']
|
||||
)
|
||||
|
||||
# Quad light type checks.
|
||||
light_type_property_test(
|
||||
light_type=LIGHT_TYPES['quad'],
|
||||
light_properties=QUAD_LIGHT_PROPERTIES,
|
||||
light_component_id_pair=light_component_id_pair,
|
||||
light_entity_name=light_entity_name,
|
||||
light_entity=light_entity
|
||||
)
|
||||
|
||||
# Polygon light type checks.
|
||||
azlmbr.editor.EditorComponentAPIBus(
|
||||
azlmbr.bus.Broadcast,
|
||||
'SetComponentProperty',
|
||||
light_component_id_pair,
|
||||
LIGHT_TYPE_PROPERTY,
|
||||
LIGHT_TYPES['polygon']
|
||||
)
|
||||
verify_required_component_property_value(
|
||||
entity_name=light_entity_name,
|
||||
component=light_entity.components[0],
|
||||
property_path=LIGHT_TYPE_PROPERTY,
|
||||
expected_property_value=LIGHT_TYPES['polygon']
|
||||
)
|
||||
|
||||
# Point (simple punctual) light type checks.
|
||||
light_type_property_test(
|
||||
light_type=LIGHT_TYPES['simple_point'],
|
||||
light_properties=SIMPLE_POINT_LIGHT_PROPERTIES,
|
||||
light_component_id_pair=light_component_id_pair,
|
||||
light_entity_name=light_entity_name,
|
||||
light_entity=light_entity
|
||||
)
|
||||
|
||||
# Spot (simple punctual) light type checks.
|
||||
light_type_property_test(
|
||||
light_type=LIGHT_TYPES['simple_spot'],
|
||||
light_properties=SIMPLE_SPOT_LIGHT_PROPERTIES,
|
||||
light_component_id_pair=light_component_id_pair,
|
||||
light_entity_name=light_entity_name,
|
||||
light_entity=light_entity
|
||||
)
|
||||
|
||||
general.log("Light component test (non-GPU) completed.")
|
||||
|
||||
|
||||
def light_type_property_test(light_type, light_properties, light_component_id_pair, light_entity_name, light_entity):
|
||||
"""
|
||||
Updates the current light type and modifies its properties, then verifies they are accurate to what was set.
|
||||
:param light_type: The type of light to update, must match a value in LIGHT_TYPES
|
||||
:param light_properties: List of tuples detailing properties to modify with update values.
|
||||
:param light_component_id_pair: Entity + component ID pair for updating the light component on a given entity.
|
||||
:param light_entity_name: the name of the Entity holding the light component.
|
||||
:param light_entity: the Entity object containing the light component.
|
||||
:return: None
|
||||
"""
|
||||
azlmbr.editor.EditorComponentAPIBus(
|
||||
azlmbr.bus.Broadcast,
|
||||
'SetComponentProperty',
|
||||
light_component_id_pair,
|
||||
LIGHT_TYPE_PROPERTY,
|
||||
light_type
|
||||
)
|
||||
verify_required_component_property_value(
|
||||
entity_name=light_entity_name,
|
||||
component=light_entity.components[0],
|
||||
property_path=LIGHT_TYPE_PROPERTY,
|
||||
expected_property_value=light_type
|
||||
)
|
||||
|
||||
for light_property in light_properties:
|
||||
light_entity.get_set_test(0, light_property[0], light_property[1])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
@@ -0,0 +1,19 @@
|
||||
"""
|
||||
Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
|
||||
SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
|
||||
File to assist with common hydra component functions or constants used across various Atom tests.
|
||||
"""
|
||||
|
||||
# Light type options for the Light component.
|
||||
LIGHT_TYPES = {
|
||||
'unknown': 0,
|
||||
'sphere': 1,
|
||||
'spot_disk': 2,
|
||||
'capsule': 3,
|
||||
'quad': 4,
|
||||
'polygon': 5,
|
||||
'simple_point': 6,
|
||||
'simple_spot': 7,
|
||||
}
|
||||
@@ -12,9 +12,10 @@ import os
|
||||
import pytest
|
||||
|
||||
import editor_python_test_tools.hydra_test_utils as hydra
|
||||
from atom_renderer.atom_utils.atom_component_helper import LIGHT_TYPES
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
EDITOR_TIMEOUT = 300
|
||||
EDITOR_TIMEOUT = 120
|
||||
TEST_DIRECTORY = os.path.join(os.path.dirname(__file__), "atom_hydra_scripts")
|
||||
|
||||
|
||||
@@ -180,3 +181,64 @@ class TestAtomEditorComponentsMain(object):
|
||||
null_renderer=True,
|
||||
cfg_args=cfg_args,
|
||||
)
|
||||
|
||||
def test_AtomEditorComponents_LightComponent(
|
||||
self, request, editor, workspace, project, launcher_platform, level):
|
||||
"""
|
||||
Please review the hydra script run by this test for more specific test info.
|
||||
Tests that the Light component has the expected property options available to it.
|
||||
"""
|
||||
cfg_args = [level]
|
||||
|
||||
expected_lines = [
|
||||
"light_entity Entity successfully created",
|
||||
"Entity has a Light component",
|
||||
"light_entity_test: Component added to the entity: True",
|
||||
f"light_entity_test: Property value is {LIGHT_TYPES['sphere']} which matches {LIGHT_TYPES['sphere']}",
|
||||
"Controller|Configuration|Shadows|Enable shadow set to True",
|
||||
"light_entity Controller|Configuration|Shadows|Shadowmap size: SUCCESS",
|
||||
"Controller|Configuration|Shadows|Shadow filter method set to 1", # PCF
|
||||
"Controller|Configuration|Shadows|Filtering sample count set to 4",
|
||||
"Controller|Configuration|Shadows|Filtering sample count set to 64",
|
||||
"Controller|Configuration|Shadows|PCF method set to 0",
|
||||
"Controller|Configuration|Shadows|PCF method set to 1",
|
||||
"Controller|Configuration|Shadows|Shadow filter method set to 2", # ESM
|
||||
"Controller|Configuration|Shadows|ESM exponent set to 50.0",
|
||||
"Controller|Configuration|Shadows|ESM exponent set to 5000.0",
|
||||
"Controller|Configuration|Shadows|Shadow filter method set to 3", # ESM+PCF
|
||||
f"light_entity_test: Property value is {LIGHT_TYPES['spot_disk']} which matches {LIGHT_TYPES['spot_disk']}",
|
||||
f"light_entity_test: Property value is {LIGHT_TYPES['capsule']} which matches {LIGHT_TYPES['capsule']}",
|
||||
f"light_entity_test: Property value is {LIGHT_TYPES['quad']} which matches {LIGHT_TYPES['quad']}",
|
||||
"light_entity Controller|Configuration|Fast approximation: SUCCESS",
|
||||
"light_entity Controller|Configuration|Both directions: SUCCESS",
|
||||
f"light_entity_test: Property value is {LIGHT_TYPES['polygon']} which matches {LIGHT_TYPES['polygon']}",
|
||||
f"light_entity_test: Property value is {LIGHT_TYPES['simple_point']} "
|
||||
f"which matches {LIGHT_TYPES['simple_point']}",
|
||||
"Controller|Configuration|Attenuation radius|Mode set to 0",
|
||||
"Controller|Configuration|Attenuation radius|Radius set to 100.0",
|
||||
f"light_entity_test: Property value is {LIGHT_TYPES['simple_spot']} "
|
||||
f"which matches {LIGHT_TYPES['simple_spot']}",
|
||||
"Controller|Configuration|Shutters|Outer angle set to 45.0",
|
||||
"Controller|Configuration|Shutters|Outer angle set to 90.0",
|
||||
"light_entity_test: Component added to the entity: True",
|
||||
"Light component test (non-GPU) completed.",
|
||||
]
|
||||
|
||||
unexpected_lines = [
|
||||
"Trace::Assert",
|
||||
"Trace::Error",
|
||||
"Traceback (most recent call last):",
|
||||
]
|
||||
|
||||
hydra.launch_and_validate_results(
|
||||
request,
|
||||
TEST_DIRECTORY,
|
||||
editor,
|
||||
"hydra_AtomEditorComponents_LightComponent.py",
|
||||
timeout=EDITOR_TIMEOUT,
|
||||
expected_lines=expected_lines,
|
||||
unexpected_lines=unexpected_lines,
|
||||
halt_on_unexpected=True,
|
||||
null_renderer=True,
|
||||
cfg_args=cfg_args,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user