2020-02-29 03:01:21 +03:00
|
|
|
param(
|
2020-08-11 23:19:28 +03:00
|
|
|
[string]$dotnet = "dotnet",
|
2020-08-19 08:44:27 +03:00
|
|
|
[ValidateSet("all", "netcoreapp3.1", "net47", "net48", "net5.0")]
|
2020-08-11 23:19:28 +03:00
|
|
|
[string]$framework = "all",
|
2020-10-22 04:22:44 +03:00
|
|
|
[ValidateSet("all", "systematic", "tasks", "actors", "actors-systematic", "standalone")]
|
2020-08-11 23:19:28 +03:00
|
|
|
[string]$test = "all",
|
|
|
|
[string]$filter = "",
|
|
|
|
[string]$logger = "",
|
|
|
|
[ValidateSet("quiet", "minimal", "normal", "detailed", "diagnostic")]
|
|
|
|
[string]$v = "normal"
|
2020-02-29 03:01:21 +03:00
|
|
|
)
|
|
|
|
|
2020-08-11 23:19:28 +03:00
|
|
|
Import-Module $PSScriptRoot/powershell/common.psm1 -Force
|
2020-02-29 03:01:21 +03:00
|
|
|
|
Merged PR 2211: initial prototype for task binary rewriting
**How to run:**
```
..\coyote\bin\netcoreapp3.1\coyote.exe rewrite .\bin\netcoreapp3.1\example.coyote.json
```
Basically the `rewrite` tool option uses `PATH` to declare a JSON configuration file. Add `-d` to get some useful debugging info.
Then just do regular `coyote test` on the rewritten binary.
**JSON:**
```json
{
"AssembliesPath": "../../bin/netcoreapp3.1",
"OutputPath": "../../bin/netcoreapp3.1/RewrittenBinaries",
"Assemblies": [
"Example.dll"
],
"Dependencies": [
"Microsoft.Coyote.dll",
"Microsoft.Coyote.Test.dll",
"Library.dll",
"Example.runtimeconfig.json"
]
}
```
If `OutputPath` is the same as `AssembliesPath`, then the original assemblies get overwritten.
**Discussion:**
The main components are an `AssemblyRewriter` that takes a JSON configuration file and uses that info to rewrite a set of assemblies (and their dependencies) and put them in some location (or overwrite original ones). That happens via "coyote rewrite". Once that is done, someone can just run "coyote test" and it should work as if someone wrote controlled tasks manually (ofc we need to push corner cases now, some APIs still I need to do, and support for build in mocks like TCS). We also have CI now, our existing run-test.ps1 script first rewrites the xUnit test project, that is only native tasks, and then it runs it (works only for .NET Core 3.1 via xUnit right now for some reason).
The cool thing is that we do not use a custom `Coyote.Task` type anymore. The reason we needed a custom task type was purely to make the manual approach usable. A custom type gives us an awaitable object (because we cannot take control of `GetAwaiter` from native Task, when someone calls await on it), as well as allows you to have it as return type of an async method (for the state machine to be generated). Instead now we focus instrumentation on two aspects: (1) every generated async state machine is replaced with a custom `AsyncStateMachineBuilder` (this is similar to what we had before, but this time we can just replace it automatically as the state machine is already there in the IL , we don't need a custom type to do that for us), and (2) replace some Task methods with custom ones (e.g. `Task.Run` with `ControlledTask.Run`, `Delay`, `Yield`, and importantly `Task.GetAwaiter` with `ControlledTask.GetAwaiter`, to get a callback on an await point). You can think of `ControlledTask` as an "extension" method, not a custom type method (its a purely static class) so its much easier to replace (we don't need to replace `Task` with `Coyote.Task` in every single IL instruction ... as `ControlledTask` APIs just return native tasks, they are just a way to get hooks).
**Known issues:**
- Figure out how to make xUnit recognize rewritten assemblies with .NET Framework (.NET Core works fine).
Related work items: #3911, #4378
2020-07-07 01:48:04 +03:00
|
|
|
$frameworks = Get-ChildItem -Path "$PSScriptRoot/../Tests/bin" | Where-Object Name -CNotIn "netstandard2.0", "netstandard2.1" | Select-Object -expand Name
|
2020-02-29 03:01:21 +03:00
|
|
|
|
|
|
|
$targets = [ordered]@{
|
2020-10-22 01:39:52 +03:00
|
|
|
"systematic" = "Tests.SystematicTesting"
|
|
|
|
"tasks" = "Tests.Tasks"
|
2020-10-22 04:22:44 +03:00
|
|
|
"actors" = "Tests.Actors"
|
|
|
|
"actors-systematic" = "Tests.Actors.SystematicTesting"
|
2020-10-22 01:39:52 +03:00
|
|
|
"standalone" = "Tests.Standalone"
|
2020-02-29 03:01:21 +03:00
|
|
|
}
|
|
|
|
|
2020-08-11 23:19:28 +03:00
|
|
|
$key_file = "$PSScriptRoot/../Common/Key.snk"
|
|
|
|
|
|
|
|
[System.Environment]::SetEnvironmentVariable('COYOTE_CLI_TELEMETRY_OPTOUT', '1')
|
2020-06-04 00:36:37 +03:00
|
|
|
|
2020-02-29 03:01:21 +03:00
|
|
|
Write-Comment -prefix "." -text "Running the Coyote tests" -color "yellow"
|
|
|
|
|
2020-10-22 04:22:44 +03:00
|
|
|
# Rewrite the systematic tests, if enabled.
|
|
|
|
if (($test -eq "all") -or ($test -eq "systematic") -or ($test -eq "actors-systematic")) {
|
2020-02-29 03:01:21 +03:00
|
|
|
foreach ($f in $frameworks) {
|
|
|
|
if (($framework -ne "all") -and ($f -ne $framework)) {
|
|
|
|
continue
|
|
|
|
}
|
2020-10-22 04:22:44 +03:00
|
|
|
|
|
|
|
$rewriting_target = "$PSScriptRoot/../Tests/bin/$f/rewrite.coyote.json"
|
|
|
|
Invoke-CoyoteTool -cmd "rewrite" -dotnet $dotnet -framework $f -target $rewriting_target -key $key_file
|
|
|
|
}
|
|
|
|
}
|
2020-02-29 03:01:21 +03:00
|
|
|
|
2020-10-22 04:22:44 +03:00
|
|
|
# Rewrite the standalone test, if enabled.
|
|
|
|
if (($test -eq "all") -or ($test -eq "standalone")) {
|
|
|
|
foreach ($f in $frameworks) {
|
|
|
|
if (($framework -ne "all") -and ($f -ne $framework)) {
|
|
|
|
continue
|
2020-08-14 03:19:10 +03:00
|
|
|
}
|
2020-10-22 04:22:44 +03:00
|
|
|
|
|
|
|
$rewriting_target = "$PSScriptRoot/../Tests/bin/$f/Microsoft.Coyote.Tests.Standalone.dll"
|
|
|
|
Invoke-CoyoteTool -cmd "rewrite" -dotnet $dotnet -framework $f -target $rewriting_target -key $key_file
|
|
|
|
}
|
|
|
|
}
|
2020-08-11 22:19:55 +03:00
|
|
|
|
2020-10-22 04:22:44 +03:00
|
|
|
# Run all enabled (rewritten) tests.
|
|
|
|
foreach ($kvp in $targets.GetEnumerator()) {
|
|
|
|
if (($test -ne "all") -and ($test -ne $($kvp.Name))) {
|
|
|
|
continue
|
|
|
|
}
|
2020-08-14 03:19:10 +03:00
|
|
|
|
2020-10-22 04:22:44 +03:00
|
|
|
foreach ($f in $frameworks) {
|
|
|
|
if (($framework -ne "all") -and ($f -ne $framework)) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-08-14 03:19:10 +03:00
|
|
|
$target = "$PSScriptRoot/../Tests/$($kvp.Value)/$($kvp.Value).csproj"
|
|
|
|
Invoke-DotnetTest -dotnet $dotnet -project $($kvp.Name) -target $target -filter $filter -logger $logger -framework $f -verbosity $v
|
2020-02-29 03:01:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Comment -prefix "." -text "Done" -color "green"
|