-
Notifications
You must be signed in to change notification settings - Fork 689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PVF: Add test instructions #2058
Changes from all commits
de09ba3
5f5e808
a47ef24
fec503f
1ed0852
783753d
06fb1df
714ef9a
95b869c
8f8f7b3
8d3e42a
3ea6885
758bf69
c5fada9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,65 @@ | ||
# Testing | ||
|
||
Automated testing is an essential tool to assure correctness. | ||
Testing is an essential tool to assure correctness. This document describes how we test the Polkadot code, whether | ||
locally, at scale, and/or automatically in CI. | ||
|
||
## Scopes | ||
|
||
The testing strategy for Polkadot is 4-fold: | ||
|
||
### Unit testing (1) | ||
|
||
Boring, small scale correctness tests of individual functions. | ||
Boring, small scale correctness tests of individual functions. It is usually | ||
enough to run `cargo test` in the crate you are testing. | ||
|
||
For full coverage you may have to pass some additional features. For example: | ||
|
||
```sh | ||
cargo test --features ci-only-tests | ||
``` | ||
|
||
### Integration tests | ||
|
||
There are two variants of integration tests: | ||
There are the following variants of integration tests: | ||
|
||
#### Subsystem tests (2) | ||
|
||
One particular subsystem (subsystem under test) interacts with a mocked overseer that is made to assert incoming and | ||
outgoing messages of the subsystem under test. This is largely present today, but has some fragmentation in the evolved | ||
integration test implementation. A `proc-macro`/`macro_rules` would allow for more consistent implementation and | ||
structure. | ||
outgoing messages of the subsystem under test. See e.g. the `statement-distribution` tests. | ||
|
||
#### Behavior tests (3) | ||
|
||
Launching small scale networks, with multiple adversarial nodes without any further tooling required. This should | ||
include tests around the thresholds in order to evaluate the error handling once certain assumed invariants fail. | ||
Launching small scale networks, with multiple adversarial nodes. This should include tests around the thresholds in | ||
order to evaluate the error handling once certain assumed invariants fail. | ||
|
||
Currently, we commonly use **zombienet** to run mini test-networks, whether locally or in CI. To run on your machine: | ||
|
||
- First, make sure you have [zombienet][zombienet] installed. | ||
|
||
- Now, all the required binaries must be installed in your $PATH. You must run the following from the `polkadot/` | ||
directory in order to test your changes. (Not `zombienet setup`, or you will get the released binaries without your | ||
local changes!) | ||
|
||
For this purpose based on `AllSubsystems` and `proc-macro` `AllSubsystemsGen`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed this stuff because I couldn't find any reference to |
||
```sh | ||
cargo install --path . --locked | ||
``` | ||
|
||
- You will also need to install whatever binaries are required for your specific tests. For example, to install | ||
`undying-collator`, from `polkadot/`, run: | ||
|
||
```sh | ||
cargo install --path ./parachain/test-parachains/undying/collator --locked | ||
``` | ||
|
||
This assumes a simplistic test runtime. | ||
- Finally, run the zombienet test from the `polkadot` directory: | ||
|
||
```sh | ||
RUST_LOG=parachain::pvf=trace zombienet --provider=native spawn zombienet_tests/functional/0001-parachains-pvf.toml | ||
``` | ||
|
||
- You can pick a validator node like `alice` from the output and view its logs | ||
(`tail -f <log_file>`) or metrics. Make sure there is nothing funny in the logs | ||
(try `grep WARN <log_file>`). | ||
|
||
#### Testing at scale (4) | ||
|
||
|
@@ -41,13 +72,27 @@ addition prometheus avoiding additional Polkadot source changes. | |
_Behavior tests_ and _testing at scale_ have naturally soft boundary. The most significant difference is the presence of | ||
a real network and the number of nodes, since a single host often not capable to run multiple nodes at once. | ||
|
||
--- | ||
## Observing Logs | ||
|
||
To verify expected behavior it's often useful to observe logs. To avoid too many | ||
logs at once, you can run one test at a time: | ||
|
||
1. Add `sp_tracing::try_init_simple();` to the beginning of a test | ||
2. Specify `RUST_LOG=<target>::<subtarget>=trace` before the cargo command. | ||
|
||
For example: | ||
|
||
```sh | ||
RUST_LOG=parachain::pvf=trace cargo test execute_can_run_serially | ||
``` | ||
|
||
For more info on how our logs work, check [the docs][logs]. | ||
|
||
## Coverage | ||
|
||
Coverage gives a _hint_ of the actually covered source lines by tests and test applications. | ||
|
||
The state of the art is currently [tarpaulin][tarpaulin] which unfortunately yields a lot of false negatives. Lines that | ||
The state of the art is currently tarpaulin which unfortunately yields a lot of false negatives. Lines that | ||
are in fact covered, marked as uncovered due to a mere linebreak in a statement can cause these artifacts. This leads to | ||
lower coverage percentages than there actually is. | ||
|
||
|
@@ -102,7 +147,7 @@ Fuzzing is an approach to verify correctness against arbitrary or partially stru | |
|
||
Currently implemented fuzzing targets: | ||
|
||
* `erasure-coding` | ||
- `erasure-coding` | ||
|
||
The tooling of choice here is `honggfuzz-rs` as it allows _fastest_ coverage according to "some paper" which is a | ||
positive feature when run as part of PRs. | ||
|
@@ -113,16 +158,16 @@ hence simply not feasible due to the amount of state that is required. | |
|
||
Other candidates to implement fuzzing are: | ||
|
||
* `rpc` | ||
* ... | ||
- `rpc` | ||
- ... | ||
|
||
## Performance metrics | ||
|
||
There are various ways of performance metrics. | ||
|
||
* timing with `criterion` | ||
* cache hits/misses w/ `iai` harness or `criterion-perf` | ||
* `coz` a performance based compiler | ||
- timing with `criterion` | ||
- cache hits/misses w/ `iai` harness or `criterion-perf` | ||
- `coz` a performance based compiler | ||
|
||
Most of them are standard tools to aid in the creation of statistical tests regarding change in time of certain unit | ||
tests. | ||
|
@@ -140,10 +185,10 @@ pursued at the current time. | |
|
||
Requirements: | ||
|
||
* spawn nodes with preconfigured behaviors | ||
* allow multiple types of configuration to be specified | ||
* allow extendability via external crates | ||
* ... | ||
- spawn nodes with preconfigured behaviors | ||
- allow multiple types of configuration to be specified | ||
- allow extendability via external crates | ||
- ... | ||
|
||
--- | ||
|
||
|
@@ -251,5 +296,7 @@ behavior_testcase!{ | |
} | ||
``` | ||
|
||
[zombienet]: https://github.com/paritytech/zombienet | ||
[Gurke]: https://github.com/paritytech/gurke | ||
[simnet]: https://github.com/paritytech/simnet_scripts | ||
[logs]: https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/node/gum/src/lib.rs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# PVF Host | ||
|
||
This is the PVF host, responsible for responding to requests from Candidate | ||
Validation and spawning worker tasks to fulfill those requests. | ||
|
||
See also: | ||
|
||
- for more information: [the Implementer's Guide][impl-guide] | ||
- for an explanation of terminology: [the Glossary][glossary] | ||
|
||
## Running basic tests | ||
|
||
Running `cargo test` in the `pvf/` directory will run unit and integration | ||
tests. | ||
|
||
**Note:** some tests run only under Linux, amd64, and/or with the | ||
`ci-only-tests` feature enabled. | ||
|
||
See the general [Testing][testing] instructions for more information on | ||
**running tests** and **observing logs**. | ||
|
||
## Running a test-network with zombienet | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Wouldn't this steps be better at the top of this repo ? And if we already have them can we just reference them, since they might change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, there is a |
||
|
||
Since this crate is consensus-critical, for major changes it is highly | ||
recommended to run a test-network. See the "Behavior tests" section of the | ||
[Testing][testing] docs for full instructions. | ||
|
||
To run the PVF-specific zombienet test: | ||
|
||
```sh | ||
RUST_LOG=parachain::pvf=trace zombienet --provider=native spawn zombienet_tests/functional/0001-parachains-pvf.toml | ||
``` | ||
|
||
## Testing on Linux | ||
|
||
Some of the PVF functionality, especially related to security, is Linux-only, | ||
and some is amd64-only. If you touch anything security-related, make sure to | ||
test on Linux amd64! If you're on a Mac, you can either run a VM or you can hire | ||
a VPS and use the open-source tool [EternalTerminal][et] to connect to it.[^et] | ||
|
||
[^et]: Unlike ssh, ET preserves your session across disconnects, and unlike | ||
another popular persistent shell, mosh, it allows scrollback. | ||
|
||
[impl-guide]: https://paritytech.github.io/polkadot-sdk/book/pvf-prechecking.html#summary | ||
[glossary]: https://paritytech.github.io/polkadot-sdk/book/glossary.html | ||
[testing]: https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/doc/testing.md | ||
[et]: https://github.com/MisterTea/EternalTerminal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this feature-ask because it should be in an issue, not in user-facing documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this has been here for like three years, if it was an issue it would have been lost in the monorepo migration. So, I won't create it. :)