|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +#include "classload.h" |
| 5 | + |
| 6 | +GUID ClassLoad::GetClsid() |
| 7 | +{ |
| 8 | + // {A1B2C3D4-E5F6-7890-1234-56789ABCDEF0} |
| 9 | + GUID clsid = {0xa1b2c3d4, 0xe5f6, 0x7890, {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0}}; |
| 10 | + return clsid; |
| 11 | +} |
| 12 | + |
| 13 | +HRESULT ClassLoad::Initialize(IUnknown* pICorProfilerInfoUnk) |
| 14 | +{ |
| 15 | + Profiler::Initialize(pICorProfilerInfoUnk); |
| 16 | + |
| 17 | + HRESULT hr = S_OK; |
| 18 | + printf("Setting COR_PRF_MONITOR_CLASS_LOADS mask\n"); |
| 19 | + if (FAILED(hr = pCorProfilerInfo->SetEventMask2(COR_PRF_MONITOR_CLASS_LOADS, 0))) |
| 20 | + { |
| 21 | + _failures++; |
| 22 | + printf("FAIL: ICorProfilerInfo::SetEventMask2() failed hr=0x%x", hr); |
| 23 | + return hr; |
| 24 | + } |
| 25 | + |
| 26 | + return S_OK; |
| 27 | +} |
| 28 | + |
| 29 | +HRESULT ClassLoad::ClassLoadStarted(ClassID classId) |
| 30 | +{ |
| 31 | + _classLoadStartedCount++; |
| 32 | + return S_OK; |
| 33 | +} |
| 34 | + |
| 35 | +HRESULT ClassLoad::ClassLoadFinished(ClassID classId, HRESULT hrStatus) |
| 36 | +{ |
| 37 | + _classLoadFinishedCount++; |
| 38 | + return S_OK; |
| 39 | +} |
| 40 | + |
| 41 | +HRESULT ClassLoad::ClassUnloadStarted(ClassID classId) |
| 42 | +{ |
| 43 | + _classUnloadStartedCount++; |
| 44 | + wprintf(L"ClassUnloadStarted: %s\n", GetClassIDName(classId).ToCStr()); |
| 45 | + |
| 46 | + return S_OK; |
| 47 | +} |
| 48 | + |
| 49 | +HRESULT ClassLoad::ClassUnloadFinished(ClassID classID, HRESULT hrStatus) |
| 50 | +{ |
| 51 | + _classUnloadFinishedCount++; |
| 52 | + return S_OK; |
| 53 | +} |
| 54 | + |
| 55 | + |
| 56 | +HRESULT ClassLoad::Shutdown() |
| 57 | +{ |
| 58 | + Profiler::Shutdown(); |
| 59 | + |
| 60 | + if(_failures == 0 |
| 61 | + && (_classLoadStartedCount != 0) |
| 62 | + // Expect unloading of UnloadLibrary.TestClass and |
| 63 | + // List<UnloadLibrary.TestClass> with all its base classes with everything used in List constructor: |
| 64 | + // - UnloadLibrary.TestClass |
| 65 | + // - System.Collections.Generic.IEnumerable`1<UnloadLibrary.TestClass> |
| 66 | + // - System.Collections.Generic.IList`1<UnloadLibrary.TestClass> |
| 67 | + // - System.Collections.Generic.IReadOnlyCollection`1<UnloadLibrary.TestClass> |
| 68 | + // - System.Collections.Generic.IReadOnlyList`1<UnloadLibrary.TestClass> |
| 69 | + // - System.Collections.Generic.List`1<UnloadLibrary.TestClass> |
| 70 | + // - System.Collections.Generic.ICollection`1<UnloadLibrary.TestClass> |
| 71 | + && (_classUnloadStartedCount == 7) |
| 72 | + && (_classLoadStartedCount == _classLoadFinishedCount) |
| 73 | + && (_classUnloadStartedCount == _classUnloadFinishedCount)) |
| 74 | + { |
| 75 | + printf("PROFILER TEST PASSES\n"); |
| 76 | + } |
| 77 | + else |
| 78 | + { |
| 79 | + printf("PROFILER TEST FAILED, failures=%d classLoadStartedCount=%d classLoadFinishedCount=%d classUnloadStartedCount=%d classUnloadFinishedCount=%d\n", |
| 80 | + _failures.load(), |
| 81 | + _classLoadStartedCount.load(), |
| 82 | + _classLoadFinishedCount.load(), |
| 83 | + _classUnloadStartedCount.load(), |
| 84 | + _classUnloadFinishedCount.load()); |
| 85 | + } |
| 86 | + |
| 87 | + fflush(stdout); |
| 88 | + |
| 89 | + return S_OK; |
| 90 | +} |
0 commit comments