1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-25 15:58:08 +00:00
trezor-firmware/core/docs/testing.md

78 lines
1.7 KiB
Markdown
Raw Normal View History

2018-05-04 14:57:25 +00:00
# Testing
## Testing with python-trezor
2019-05-24 16:43:00 +00:00
Apart from the internal tests, Trezor core has a suite of integration tests in the `python` subdirectory. There are several ways to use that.
2018-05-04 14:57:25 +00:00
### 1. Running the suite with pipenv
[`pipenv`](https://docs.pipenv.org/) is a tool for making reproducible Python environments. Install it with:
2018-06-05 21:42:26 +00:00
2018-05-04 14:57:25 +00:00
```sh
sudo pip3 install pipenv
```
2018-06-05 21:42:26 +00:00
2018-05-04 14:57:25 +00:00
Inside `trezor-core` checkout, install the environment:
2018-06-05 21:42:26 +00:00
2018-05-04 14:57:25 +00:00
```sh
pipenv install
```
2018-06-05 21:42:26 +00:00
2018-05-04 14:57:25 +00:00
And run the automated tests:
2018-06-05 21:42:26 +00:00
2018-05-04 14:57:25 +00:00
```sh
pipenv run make test_emu
```
### 2. Developing new tests
Prepare a virtual environment with all the requirements, and switch into it. Again, it's easiest to do this with `pipenv`:
2018-06-05 21:42:26 +00:00
2018-05-04 14:57:25 +00:00
```sh
2019-05-24 16:43:00 +00:00
pipenv install
2018-05-04 14:57:25 +00:00
pipenv shell
```
2018-06-05 21:42:26 +00:00
2019-05-24 16:43:00 +00:00
Alternately, if you have an existing virtualenv, you can install `python` in "develop" mode:
2018-06-05 21:42:26 +00:00
2018-05-04 14:57:25 +00:00
```sh
python setup.py develop
```
2019-05-24 16:43:00 +00:00
If you want to test against the emulator, run it in a separate terminal from the `core` subdirectory:
2018-06-05 21:42:26 +00:00
2018-05-04 14:57:25 +00:00
```sh
PYOPT=0 ./emu.sh
2018-05-04 14:57:25 +00:00
```
Find the device address and export it as an environment variable. For the emulator, this is:
2018-06-05 21:42:26 +00:00
2018-05-04 14:57:25 +00:00
```sh
export TREZOR_PATH="udp:127.0.0.1:21324"
```
2018-06-05 21:42:26 +00:00
2018-05-04 14:57:25 +00:00
(You can find other devices with `trezorctl list`.)
2019-05-24 16:43:00 +00:00
Now you can run the test suite, either from `python` or `core` root directory:
2018-06-05 21:42:26 +00:00
2018-05-04 14:57:25 +00:00
```sh
pytest
```
2018-06-05 21:42:26 +00:00
Or from anywhere else:
2018-06-05 21:42:26 +00:00
```sh
pytest --pyargs trezorlib.tests.device_tests # this works from other locations
```
2018-05-04 14:57:25 +00:00
You can place your own tests in `trezorlib/tests/device_tests`. See test style guide (TODO).
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`.