-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
56 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# On multithreading | ||
|
||
The way LLVM instrumentation works doesn't really lend itself well to the | ||
multi-threading of tests, so multiple tests cannot run at the same time. | ||
But a single test can spawn multiple threads, and the runtime will keep | ||
track of those threads as well. | ||
|
||
However, those extra threads *must* finish running before the test itself | ||
finishes. If they do not, and they are still going while the next test is | ||
executing, they *will* interfere with that test's coverage. | ||
|
||
This is not a problem if all the test code is single-threaded; however, | ||
special caution should be taken for multi-threaded tests. | ||
|
||
This however is different from spawning different processes, which is | ||
supported; see the article on spawning subprocesses that should be tracked | ||
[here](spawning-subprocesses.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Spawning subprocesses | ||
|
||
You can go ahead and spawn subprocesses normally; if their | ||
coverage information should be ignored. If you however want them | ||
to be tracked, you should pass them some environment variables. | ||
|
||
## Environment variables | ||
|
||
You can pass the required environment variables to the subprocess | ||
like this: | ||
|
||
```Rust | ||
#[test] | ||
fn test_f() { | ||
let env: DifftestsEnv = setup_difftests("test_f"); | ||
let mut cmd = std::process::Command::new("exe"); | ||
// the DifftestsEnv::env_for_children() | ||
// method gives us the required environment variables | ||
#[cfg(cargo_difftests)] | ||
cmd.envs(env.env_for_children()); | ||
cmd.spawn().unwrap().wait().unwrap(); | ||
} | ||
``` | ||
|
||
The instrumented binaries must have had coverage enabled for this to work. | ||
|
||
Unlike with [multithreading](multithreading.md), the subprocesses can run | ||
even after the test has finished, and they will still be tracked. They | ||
only have to finish before the analysis. However, leaky tests are still | ||
a problem, and should be avoided. |