-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fire AssemblyUnloadStarted event (#87890)
Fixes #86178 AssemblyUnloadStarted event is now being fired
- Loading branch information
1 parent
4c72d9c
commit 4cbf8bd
Showing
9 changed files
with
167 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
|
||
namespace Profiler.Tests | ||
{ | ||
class ALCTest | ||
{ | ||
static readonly Guid AssemblyProfilerGuid = new Guid("19A49007-9E58-4E31-B655-83EC3B924E7B"); | ||
|
||
public static int RunTest(String[] args) | ||
{ | ||
string currentAssemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
string testAssemblyFullPath = Path.Combine(currentAssemblyDirectory, "..", "TestFile", "TestFile.dll"); | ||
|
||
int exitCode = TestLibrary.Utilities.ExecuteAndUnload(testAssemblyFullPath, args); | ||
return exitCode; | ||
} | ||
|
||
public static int Main(string[] args) | ||
{ | ||
if (args.Length > 0 && args[0].Equals("RunTest", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
return RunTest(args); | ||
} | ||
|
||
return ProfilerTestRunner.Run(profileePath: System.Reflection.Assembly.GetExecutingAssembly().Location, | ||
testName: "ALCTest", | ||
profilerClsid: AssemblyProfilerGuid); | ||
} | ||
} | ||
} |
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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier> | ||
<OutputType>exe</OutputType> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<Optimize>true</Optimize> | ||
<!-- The test launches a secondary process and process launch creates | ||
an infinite event loop in the SocketAsyncEngine on Linux. Since | ||
runincontext loads even framework assemblies into the unloadable | ||
context, locals in this loop prevent unloading --> | ||
<UnloadabilityIncompatible>true</UnloadabilityIncompatible> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" /> | ||
<ProjectReference Include="../common/profiler_common.csproj" /> | ||
<CMakeProjectReference Include="$(MSBuildThisFileDirectory)/../native/CMakeLists.txt" /> | ||
</ItemGroup> | ||
</Project> |
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,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
|
||
namespace Profiler.Tests | ||
{ | ||
class TestFile | ||
{ | ||
|
||
public static int Main(string[] args) | ||
{ | ||
return 100; | ||
} | ||
} | ||
} |
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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier> | ||
<OutputType>exe</OutputType> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<Optimize>true</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" /> | ||
<ProjectReference Include="../common/profiler_common.csproj" /> | ||
<CMakeProjectReference Include="$(MSBuildThisFileDirectory)/../native/CMakeLists.txt" /> | ||
</ItemGroup> | ||
</Project> |
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
50 changes: 50 additions & 0 deletions
50
src/tests/profiler/native/assemblyprofiler/assemblyprofiler.cpp
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,50 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#include "assemblyprofiler.h" | ||
|
||
GUID AssemblyProfiler::GetClsid() | ||
{ | ||
GUID clsid = { 0x19A49007, 0x9E58, 0x4E31,{ 0xB6, 0x55, 0x83, 0xEC, 0x3B, 0x92, 0x4E, 0x7B } }; | ||
return clsid; | ||
} | ||
|
||
HRESULT AssemblyProfiler::Initialize(IUnknown* pICorProfilerInfoUnk) | ||
{ | ||
Profiler::Initialize(pICorProfilerInfoUnk); | ||
|
||
return S_OK; | ||
} | ||
|
||
HRESULT AssemblyProfiler::Shutdown() | ||
{ | ||
Profiler::Shutdown(); | ||
|
||
if (_assemblyUnloadStartedCount != _assemblyUnloadFinishedCount) | ||
{ | ||
printf("AssemblyProfiler::Shutdown: FAIL: Expected AssemblyUnloadStarted and AssemblyUnloadFinished to be called the same number of times\n"); | ||
} | ||
else | ||
{ | ||
printf("PROFILER TEST PASSES\n"); | ||
} | ||
|
||
fflush(stdout); | ||
return S_OK; | ||
} | ||
|
||
HRESULT AssemblyProfiler::AssemblyUnloadStarted(AssemblyID assemblyId) | ||
{ | ||
SHUTDOWNGUARD(); | ||
|
||
_assemblyUnloadStartedCount++; | ||
return S_OK; | ||
} | ||
|
||
HRESULT AssemblyProfiler::AssemblyUnloadFinished(AssemblyID assemblyId, HRESULT hrStatus) | ||
{ | ||
SHUTDOWNGUARD(); | ||
|
||
_assemblyUnloadFinishedCount++; | ||
return S_OK; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/tests/profiler/native/assemblyprofiler/assemblyprofiler.h
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,25 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#pragma once | ||
|
||
#include "../profiler.h" | ||
|
||
class AssemblyProfiler : public Profiler | ||
{ | ||
public: | ||
AssemblyProfiler() : Profiler(), | ||
_assemblyUnloadStartedCount(0), | ||
_assemblyUnloadFinishedCount(0) | ||
{} | ||
|
||
static GUID GetClsid(); | ||
virtual HRESULT STDMETHODCALLTYPE Initialize(IUnknown* pICorProfilerInfoUnk); | ||
virtual HRESULT STDMETHODCALLTYPE Shutdown(); | ||
virtual HRESULT STDMETHODCALLTYPE AssemblyUnloadStarted(AssemblyID assemblyId); | ||
virtual HRESULT STDMETHODCALLTYPE AssemblyUnloadFinished(AssemblyID assemblyId, HRESULT hrStatus); | ||
|
||
private: | ||
std::atomic<int> _assemblyUnloadStartedCount; | ||
std::atomic<int> _assemblyUnloadFinishedCount; | ||
}; |
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