Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add test for ObjectsAllocatedByClass profiler callbacks
  • Loading branch information
ogxd committed Jan 14, 2022
commit 4e87dff1fe6d2ce1f8081c59ac852ef5342fb232
18 changes: 18 additions & 0 deletions src/tests/profiler/native/gcprofiler/gcprofiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ HRESULT GCProfiler::Shutdown()
{
printf("GCProfiler::Shutdown: FAIL: Expected GarbageCollectionFinished to be called\n");
}
else if (_allocatedByClassCalls == 0)
{
printf("GCProfiler::Shutdown: FAIL: Expected ObjectsAllocatedByClass to be called\n");
}
else if (_pohObjectsSeenRootReferences == 0 || _pohObjectsSeenObjectReferences == 0)
{
printf("GCProfiler::Shutdown: FAIL: no POH objects seen. root references=%d object references=%d\n",
Expand Down Expand Up @@ -86,6 +90,20 @@ HRESULT GCProfiler::GarbageCollectionFinished()
return S_OK;
}

HRESULT GCProfiler::ObjectsAllocatedByClass(ULONG cClassCount, ClassID classIds[], ULONG cObjects[])
{
SHUTDOWNGUARD();

_allocatedByClassCalls++;
if (_gcStarts != _allocatedByClassCalls)
{
_failures++;
printf("GCProfiler::ObjectsAllocatedByClass: FAIL: Expected ObjectsAllocatedByClass Calls == GCStart. AllocatedByClassCalls=%d, Start=%d\n", (int)_gcStarts, (int)_gcFinishes);
}

return S_OK;
}

HRESULT GCProfiler::ObjectReferences(ObjectID objectId, ClassID classId, ULONG cObjectRefs, ObjectID objectRefIds[])
{
SHUTDOWNGUARD();
Expand Down
3 changes: 3 additions & 0 deletions src/tests/profiler/native/gcprofiler/gcprofiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class GCProfiler : public Profiler
GCProfiler() : Profiler(),
_gcStarts(0),
_gcFinishes(0),
_allocatedByClassCalls(0),
_failures(0),
_pohObjectsSeenRootReferences(0),
_pohObjectsSeenObjectReferences(0),
Expand All @@ -28,12 +29,14 @@ class GCProfiler : public Profiler
virtual HRESULT STDMETHODCALLTYPE Shutdown();
virtual HRESULT STDMETHODCALLTYPE GarbageCollectionStarted(int cGenerations, BOOL generationCollected[], COR_PRF_GC_REASON reason);
virtual HRESULT STDMETHODCALLTYPE GarbageCollectionFinished();
virtual HRESULT STDMETHODCALLTYPE ObjectsAllocatedByClass(ULONG cClassCount, ClassID classIds[], ULONG cObjects[]);
virtual HRESULT STDMETHODCALLTYPE ObjectReferences(ObjectID objectId, ClassID classId, ULONG cObjectRefs, ObjectID objectRefIds[]);
virtual HRESULT STDMETHODCALLTYPE RootReferences(ULONG cRootRefs, ObjectID rootRefIds[]);

private:
std::atomic<int> _gcStarts;
std::atomic<int> _gcFinishes;
std::atomic<int> _allocatedByClassCalls;
std::atomic<int> _failures;
std::atomic<int> _pohObjectsSeenRootReferences;
std::atomic<int> _pohObjectsSeenObjectReferences;
Expand Down