Skip to content
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

[System.Runtime.Loader] Add hot reload test infrastructure #51144

Merged
merged 22 commits into from
May 10, 2021

Conversation

lambdageek
Copy link
Member

@lambdageek lambdageek commented Apr 12, 2021

Adding infrastructure for hot reload testing.

For each test we define a new library assembly project. The .csproj has a
DeltaScript property that specifies a JSON file that lists the name of an
initial source file, and a list of updated versions of that file. The
hotreload-delta-gen tool runs during the build to read the delta script and
create deltas that incorporate the updates.

The main testsuite references all the test assemblies, and when a test runs, it
calls ApplyUpdateUtil.ApplyUpdate to load subsequent deltas
and then compares the results before and after an update.

Dependencies:

  • https://github.com/dotnet/hotreload-utils - there is now a Microsoft.DotNet.HotReload.Utils.Generator.BuildTool MSBuild targets nupkg on the dotnet6-transport nuget feed.
  • If DOTNET_MODIFIABLE_ASSEMBLIES is not set in the environment, we use remote executor to run the tests.

Mono is technically enabled, but practically it's not running anywhere:

  • We have not enabled the MonoMetadataUpdate support on desktop linux or macos
  • For wasm, ios and Android since we don't have remote executor support, we would need to adjust the test pipelines to pass the DOTNET_MODIFIABLE_ASSEMBLIES flag via xharness (and the app builder tasks).
  • For ios and Android we would need to enable the interpreter as the execution engine, otherwise the tests are skipped.

To try it out locally with CoreCLR run:

./dotnet.sh build src/libraries/System.Runtime.Loader/tests /t:Test

For mono, build the runtime with /p:MonoMetadataUpdate=true and setenv MONO_ENV_OPTIONS=--interp

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@lambdageek
Copy link
Member Author

@tommcdon @mikem8361 So here's the general shape of how I think hot reload tests should look.

@akoeplinger @ViktorHofer I really need help setting up arcade stuff for https://github.com/dotnet/hotreload-utils - the end state is that I'd like for hotreload-delta-gen to be a dotnet tool that's packaged in a transport package that dotnet/runtime could pick up using arcade/BAR/maestro. I tried setting up the eng/ folder, and Alexander set up an internal repo for the publishing. But there's no pipeline that pushes out packages yet.

@akoeplinger @ViktorHofer I also will need some help with CI. The tests depend on some environment variable being set (DOTNET_MODIFIABLE_ASSEMBLIES=debug) and I'm not sure if we should set that in the pipeline, or if there's some way to have the test project itself start up with environment values set.

@ghost
Copy link

ghost commented Apr 12, 2021

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Issue Details

Adding infrastructure for hot reload testing.

For each test we define a new library assembly project. The .csproj has a
DeltaScript property that specifies a JSON file that lists the name of an
initial source file, and a list of updated versions of that file. The
hotreload-delta-gen tool runs during the build to read the delta script and
create deltas that incorporate the updates.

The main testsuite references all the test assemblies, and when a test runs, it
calls ApplyUpdateUtil.ApplyUpdate to load subsequent deltas
and then compares the results before and after an update.

Dependencies:

Needs work:

  • Mono test runs need to pass the FEATURE_MONO_METADATA_UPDATE property to
    msbuild to the test project. This is because not every mono configuration
    includes hot reload support. Eventually this should be subsumed by the
    runtime API to querty hot reload capabilities internal runtime API to return hot reload capabilities #50111
  • All runs need to pass DOTNET_MODIFIABLE_ASSEMBLIES=debug to the testsuite.
    Hot reload only works when:
    • the assemblies are compiled with the Debug compiler setting,
    • and, if the runtime is tarted with the above environment variable set.
  • The GenerateHotReloadDeltas.targets needs some output file work to run hotreload-delta-gen less
    frequently. Right now it runs every time even if everything is up to date.
    For CI testing we should ideally compile the deltas ahead of time once.

To try it out locally:

  1. checkout and build hotreload-utils and do dotnet publish --self-contained -r <RID> to
    put hotreload-delta-gen into that projects' artifacts/... forlder. Add the
    publish folder to your $PATH

  2. In dotnet/runtime run

DOTNET_MODIFIABLE_ASSEMBLIES=debug MONO_ENV_OPTIONS=--interp ./dotnet.sh build src/libraries/System.Runtime.Loader/tests /p:MonoMetadataUpdate=true /t:Test

(CoreCLR doesn't need MONO_ENV_OPTIONS or MonoMetadataUpdate)

Author: lambdageek
Assignees: -
Labels:

area-Infrastructure

Milestone: -

@mikem8361
Copy link
Member

One thing to note that "source build" will require the hotreload-utils repo to built as part of it. I'm not sure exactly how tools like this are handled as part of the source build.

@lambdageek
Copy link
Member Author

One thing to note that "source build" will require the hotreload-utils repo to built as part of it. I'm not sure exactly how tools like this are handled as part of the source build.

Good point. Not sure. I think the situation will be similar to how our LLVM fork, or the other transport nugets are built. (Possibly with a bit more of a bootstrapping problem since hotreload-utils depends on Roslyn which depends on the runtime)

@lambdageek lambdageek mentioned this pull request Apr 13, 2021
51 tasks
@lambdageek lambdageek marked this pull request as ready for review April 27, 2021 19:54
@lambdageek
Copy link
Member Author

various Libraries builds are failing with

Run "dotnet tool restore" to make the "hotreload-delta-gen" command available.

@ViktorHofer @akoeplinger is it not enough to add the reference to eng/Version.Details.xml and to .config/dotnet-tools.json? Is there something else I need to tweak?

@lambdageek

This comment has been minimized.

lambdageek and others added 10 commits May 10, 2021 09:50
just calling RemoteExecutor.IsSupported on wasm throws

```
System.TypeInitializationException: The type initializer for 'Microsoft.DotNet.RemoteExecutor.RemoteExecutor' threw an exception.
---> System.PlatformNotSupportedException: System.Diagnostics.Process
is not supported on this platform.
```
It's for the old project style, only
…otreload-delta-gen

Use an msbuild target nuget instead of the CLI tool
Don't need this anymore - using an MSBuild targets nuget now instead of a
dotnet tool

This reverts commit c125be86a3324d4bbcce1728b124fb0b4abd9add.
The Microsoft.DotNet.HotReload.Utils.Generator.BuildTool nuget now includes a
task to compute the output names.  So the targets in the nuget are entirely
self-contained now - incremental builds and project references should work now.

Bump to version 1.0.1 of Generator.BuildTool which has the necessary targets
Copy link
Member

@ViktorHofer ViktorHofer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo style nits

@lambdageek lambdageek merged commit 49f34eb into dotnet:main May 10, 2021
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jun 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants