1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-02 04:18:20 +00:00
trezor-firmware/core/docs/tests/index.md

86 lines
2.2 KiB
Markdown
Raw Normal View History

2018-05-04 14:57:25 +00:00
# Testing
## Testing with python-trezor
Apart from the internal tests, Trezor Core has a suite of integration tests in the
`python` monorepo's subdirectory. There are several ways to use that.
2018-05-04 14:57:25 +00:00
2019-05-27 14:12:53 +00:00
### 1. Running the full test suite
2018-06-05 21:42:26 +00:00
_Note: You need Pipenv, as mentioned in the [build](../build/index.md) section._
In the `trezor-firmware` checkout, in the root of the monorepo, install the environment:
2018-05-04 14:57:25 +00:00
```sh
2019-05-27 14:12:53 +00:00
pipenv sync
2018-05-04 14:57:25 +00:00
```
And run the automated tests:
```sh
2019-05-27 14:12:53 +00:00
pipenv run make -C core test_emu
2018-05-04 14:57:25 +00:00
```
2019-05-27 14:12:53 +00:00
### 2. Running tests manually
2018-06-05 21:42:26 +00:00
2019-05-27 14:12:53 +00:00
Install the pipenv environment as outlined above. Then switch to a shell inside the
environment:
2018-06-05 21:42:26 +00:00
2018-05-04 14:57:25 +00:00
```sh
2019-05-27 14:12:53 +00:00
pipenv shell
2018-05-04 14:57:25 +00:00
```
2019-05-27 14:12:53 +00:00
If you want to test against the emulator, run it in a separate terminal from the `core`
subdirectory:
2018-05-04 14:57:25 +00:00
```sh
PYOPT=0 ./emu.sh
2018-05-04 14:57:25 +00:00
```
2019-05-27 14:12:53 +00:00
Find the device address and export it as an environment variable. For the emulator, this
is:
2018-05-04 14:57:25 +00:00
```sh
export TREZOR_PATH="udp:127.0.0.1:21324"
```
(You can find other devices with `trezorctl list`.)
2019-05-27 14:12:53 +00:00
Now you can run the test suite with `pytest`, either from `python` or `core` directory:
2018-05-04 14:57:25 +00:00
```sh
pytest
```
2018-06-05 21:42:26 +00:00
Or from anywhere else:
```sh
pytest --pyargs trezorlib.tests.device_tests # this works from other locations
```
2018-05-04 14:57:25 +00:00
2019-05-27 14:12:53 +00:00
You can place your own tests in [device_tests] directory. See test style guide (TODO).
2018-05-04 14:57:25 +00:00
If you only want to run a particular test, pick it with `-k <keyword>` or `-m <marker>`:
2018-06-05 21:42:26 +00:00
2018-05-04 14:57:25 +00:00
```sh
pytest -k nem # only runs tests that have "nem" in the name
pytest -m stellar # only runs tests marked with @pytest.mark.stellar
2018-05-04 14:57:25 +00:00
```
2018-05-04 14:57:25 +00:00
If you want to see debugging information and protocol dumps, run with `-v`.
2019-05-27 14:12:53 +00:00
### 3. Using markers
When you're developing a new currency, you should mark all tests that belong to that
currency. For example, if your currency is called NewCoin, your device tests should have
the following marker:
```python
@pytest.mark.newcoin
```
This marker must be registered in [REGISTERED_MARKERS] file.
If you wish to run a test only on TT, mark it with `@pytest.mark.skip_t1`.
If the test should only run on T1, mark it with `@pytest.mark.skip_t2`.
You must not use both on the same test.
[pipenv]: https://docs.pipenv.org/
[device_tests]: ../../python/trezorlib/tests/device_tests
[REGISTERED_MARKERS]: ../../python/trezorlib/tests/device_tests/REGISTERED_MARKERS