# The RTX Renderer Test Framework [omni.rtx.tests]

This extensions contains python tests for RTX renderer.

This tests is based on kit python tests. See `omni.kit.tests` documentation.

# How-to run tets
There is few ways to run tets.
1) Run script `_build/{build}/{config}/tests-omni.rtx.tests.{bat|sh}`
2) Run `kit`. Open `Window -> Test Runner`. Select and run tests you want to run.
# How-to add new tests:

1) Create new py file. See `test_example.py` as template.
2) Derive you test class from `class RtxTests` from `test_common.py`
3) Add your test by adding method started from `test_`
4) Improt your test class in __init__.py


# How-to write tests

You may use any methods from `omni.kit.tests`. For example to assert use `self.assertTrue({condition})`.

Default directory for placing usd files is `{ext_path}/data/usd`

## Settings
It is not recommended to use `carb.settings` directly as tests might be executed by user in kit and overwrite user's 
settings config. There is way to deal with it - use next method for settings.
```        
self.set_settings({"/app/setting1": "val1",
                   "/app/setting2": (0, 0),
                   "/app/setting3": True}))
```

`set_settings` remembers previous value of setting that changed first time and set this value on `tearDown()`

### Default rtx test settings
See `testSettings` and `postLoadTestSettings`.

`testSettings` is set on test startup before stage loading.

`postLoadTestSettings`is set after stage loading.
You can load this settings in your tests without changes or create your own setup based on it.


## Capture and compare screenshots with golden

Rendering is drawn screen with few frames delay. So after any changes has done it is needed to wait few frames before capture.
Use `wait_for_update(wait_frames=4)` for waiting next few frames.


For capturing use `capture_and_compare` function.

Generated images are placed in `{kit}/kit/outputs/omni.rtx.tests/{image_subdir}`.

Goldens for compare are placed in `{ext_path}/data/goldens/{image_subdir}`.

### Generating goldens
Tests is not interrupted if golden is missed in goloden directory. So if it is needed to generate 
goldens it shold be removed from golden directory. Then run the tests and copy new goldens from output directory.


## Helper functions
`set_transform_helper` - set transform for specified prim path

`add_dir_light` - add directional light `/World/Light` to scene 

`add_floor` - add floor plane `/World/Floor` to scene

`open_usd` - open usd file

`set_camera` - set camera position and target