Add host startup hook and tests (dotnet/core-setup#4465)
authorSven Boemer <sbomer@gmail.com>
Thu, 13 Sep 2018 16:25:46 +0000 (09:25 -0700)
committerGitHub <noreply@github.com>
Thu, 13 Sep 2018 16:25:46 +0000 (09:25 -0700)
commit8c8e2858ded1bdc46c382a60d33e602312c3f236
tree336ac838463dfdc1ecb415532d85f0dab4757498
parentf0a0faed98ab2b16b26dacf9b8bc12031d30d815
Add host startup hook and tests (dotnet/core-setup#4465)

* Expose coreclr_create_delegate function

* Add startup hook call

Read DOTNET_STARTUP_HOOKS environment variable, and pass it along to a
private function in
System.Private.CoreLib (StartupHookProvider.ProcessStartupHookS).

* Add startup hook tests

* Add some more syntax checks

* Reorder the tests

* Add test for exclamation mark in assembly path

* Fix error behavior for missing methods

MissingMethodException is now only thrown when the Initialize method
doesn't exist at all. This also reorganizes the existing tests for the
invalid signature, and adds some cases.

* Change test behavior to not expect eager file exists check

* Expect full paths for startup hook.

Fixes this in existing tests, and adds a new check for the error
behavior when a relative path is passed.

* Add test for startup hook trace output

* Update tests to use new syntax (without type name)

* Pass STARTUP_HOOKS property key to coreclr_initialize

STARTUP_HOOKS is now passed to the clr during initialization, instead
of using create_delegate in the host. This will allow the clr to call
the startup hooks closer to the execution of the main method, allowing
the threading apartment state to be set based on the main method's
attributes.

* Allow non-public Initialize method

* Remove coreclr::create_delegate

* Add comments clarifying purpose of startup hook test projects

* Add test with ALC assembly resolve event

The startup hook will inject a dependency into the app.

* Fix the ALC startup hook testcase

- Don't set ReferenceOutputAssembly in the projectreference, because
  that results in it not being published.
- Dispose the new projects
- Don't throw exceptions from the resolver, since they are swallowed.

Commit migrated from https://github.com/dotnet/core-setup/commit/841b7e407f6b782b1f5900873f4ffc57875111c6
36 files changed:
src/installer/corehost/cli/hostpolicy.cpp
src/installer/test/Assets/TestProjects/LightupLib/Program.cs
src/installer/test/Assets/TestProjects/PortableAppWithMissingRef/PortableAppWithMissingRef.csproj [new file with mode: 0644]
src/installer/test/Assets/TestProjects/PortableAppWithMissingRef/Program.cs [new file with mode: 0644]
src/installer/test/Assets/TestProjects/PortableAppWithMissingRef/SharedLibrary/ReferenceLibrary.csproj [new file with mode: 0644]
src/installer/test/Assets/TestProjects/PortableAppWithMissingRef/SharedLibrary/SharedLibrary.cs [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHook/StartupHook.cs [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHook/StartupHook.csproj [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookFake/StartupHookFake.csproj [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookFake/StartupHookInvalidAssembly.dll [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithAssemblyResolver/SharedLibrary/SharedLibrary.cs [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithAssemblyResolver/SharedLibrary/SharedLibrary.csproj [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithAssemblyResolver/StartupHookWithAssemblyResolver.cs [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithAssemblyResolver/StartupHookWithAssemblyResolver.csproj [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithDependency/StartupHookWithDependency.cs [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithDependency/StartupHookWithDependency.csproj [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithInstanceMethod/StartupHookWithInstanceMethod.cs [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithInstanceMethod/StartupHookWithInstanceMethod.csproj [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithMultipleIncorrectSignatures/StartupHookWithMultipleIncorrectSignatures.cs [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithMultipleIncorrectSignatures/StartupHookWithMultipleIncorrectSignatures.csproj [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithNonPublicMethod/StartupHookWithNonPublicMethod.cs [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithNonPublicMethod/StartupHookWithNonPublicMethod.csproj [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithOverload/StartupHookWithOverload.cs [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithOverload/StartupHookWithOverload.csproj [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithParameter/StartupHookWithParameter.cs [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithParameter/StartupHookWithParameter.csproj [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithReturnType/StartupHookWithReturnType.cs [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithReturnType/StartupHookWithReturnType.csproj [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithoutInitializeMethod/StartupHookWithoutInitializeMethod.cs [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithoutInitializeMethod/StartupHookWithoutInitializeMethod.csproj [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithoutStartupHookType/StartupHookWithoutStartupHookType.cs [new file with mode: 0644]
src/installer/test/Assets/TestProjects/StartupHookWithoutStartupHookType/StartupHookWithoutStartupHookType.csproj [new file with mode: 0644]
src/installer/test/HostActivationTests/GivenThatICareAboutStartupHooks.cs [new file with mode: 0644]
src/installer/test/HostActivationTests/HostActivationTests.csproj
src/installer/test/TestUtils/Assertions/CommandResultAssertions.cs
src/installer/test/TestUtils/TestProjectFixture.cs