!9666 Add UT for GC

Merge pull request !9666 from Sandee/ut_20241010
This commit is contained in:
openharmony_ci 2024-10-15 17:42:49 +00:00 committed by Gitee
commit 0798656e68
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 112 additions and 2 deletions

View File

@ -164,7 +164,7 @@ void JitFort::UpdateFreeSpace()
{
LockHolder lock(mutex_);
if (!regionList_.GetLength()) {
if (!regionList_.GetLength()) { // LCOV_EXCL_BR_LINE
return;
}
@ -318,7 +318,7 @@ MemDesc *MemDescPool::GetDesc()
if (IsEmpty(freeList_)) {
Expand();
}
if (!IsEmpty(freeList_)) {
if (!IsEmpty(freeList_)) { // LCOV_EXCL_BR_LINE
MemDesc *res = freeList_;
freeList_ = freeList_->GetNext();
allocated_++;

View File

@ -53,6 +53,18 @@ HWTEST_F_L0(IdleGCTriggerTest, NotifyLooperIdleStartTest001)
trigger->NotifyLooperIdleStart(1, 1);
}
HWTEST_F_L0(IdleGCTriggerTest, NotifyLooperIdleStartTest002)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
SharedHeap *sheap = SharedHeap::GetInstance();
heap->GetConcurrentMarker()->Mark();
heap->GetJSThread()->SetMarkStatus(MarkStatus::MARK_FINISHED);
IdleGCTrigger *trigger = new IdleGCTrigger(heap, sheap, thread);
trigger->ClearPostGCTask(TRIGGER_IDLE_GC_TYPE::LOCAL_CONCURRENT_MARK);
trigger->SetPostGCTask(TRIGGER_IDLE_GC_TYPE::LOCAL_CONCURRENT_MARK);
trigger->NotifyLooperIdleStart(1, 1);
}
HWTEST_F_L0(IdleGCTriggerTest, NotifyLooperIdleEndTest001)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
@ -83,6 +95,26 @@ HWTEST_F_L0(IdleGCTriggerTest, TryTriggerLocalConcurrentMarkTest001)
trigger->TryTriggerLocalConcurrentMark();
}
HWTEST_F_L0(IdleGCTriggerTest, TryTriggerLocalConcurrentMarkTest002)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
SharedHeap *sheap = SharedHeap::GetInstance();
heap->SetIdleTask(IdleTaskType::NO_TASK);
heap->GetConcurrentMarker()->ConfigConcurrentMark(false);
IdleGCTrigger *trigger = new IdleGCTrigger(heap, sheap, thread);
trigger->TryTriggerLocalConcurrentMark();
}
HWTEST_F_L0(IdleGCTriggerTest, TryTriggerLocalConcurrentMarkTest003)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
SharedHeap *sheap = SharedHeap::GetInstance();
heap->SetIdleTask(IdleTaskType::NO_TASK);
thread->SetMarkStatus(MarkStatus::MARK_FINISHED);
IdleGCTrigger *trigger = new IdleGCTrigger(heap, sheap, thread);
trigger->TryTriggerLocalConcurrentMark();
}
HWTEST_F_L0(IdleGCTriggerTest, TryTriggerIdleSharedOldGCTest001)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
@ -116,6 +148,16 @@ HWTEST_F_L0(IdleGCTriggerTest, TryTriggerIdleSharedOldGCTest003)
ASSERT_EQ(trigger->TryTriggerIdleSharedOldGC(), true);
}
HWTEST_F_L0(IdleGCTriggerTest, TryTriggerIdleSharedOldGCTest004)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
SharedHeap *sheap = SharedHeap::GetInstance();
heap->SetOnSerializeEvent(true);
IdleGCTrigger *trigger = new IdleGCTrigger(heap, sheap, thread);
ASSERT_EQ(trigger->TryTriggerIdleSharedOldGC(), false);
}
HWTEST_F_L0(IdleGCTriggerTest, TryTriggerIdleLocalOldGCTest001)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
@ -166,6 +208,34 @@ HWTEST_F_L0(IdleGCTriggerTest, TryTriggerIdleLocalOldGCTest004)
ASSERT_EQ(trigger->TryTriggerIdleLocalOldGC(), true);
}
HWTEST_F_L0(IdleGCTriggerTest, TryTriggerIdleLocalOldGCTest005)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
SharedHeap *sheap = SharedHeap::GetInstance();
heap->GetConcurrentMarker()->Mark();
heap->GetJSThread()->SetMarkStatus(MarkStatus::MARK_FINISHED);
IdleGCTrigger *trigger = new IdleGCTrigger(heap, sheap, thread);
trigger->ClearPostGCTask(TRIGGER_IDLE_GC_TYPE::LOCAL_CONCURRENT_MARK);
trigger->SetPostGCTask(TRIGGER_IDLE_GC_TYPE::LOCAL_CONCURRENT_MARK);
ASSERT_EQ(trigger->TryTriggerIdleLocalOldGC(), true);
}
HWTEST_F_L0(IdleGCTriggerTest, TryTriggerIdleLocalOldGCTest006)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
SharedHeap *sheap = SharedHeap::GetInstance();
heap->SetIdleTask(IdleTaskType::FINISH_MARKING);
heap->GetOldSpace()->SetInitialCapacity(10000);
heap->GetOldSpace()->IncreaseLiveObjectSize(5242889);
heap->NotifyHeapAliveSizeAfterGC(1);
IdleGCTrigger *trigger = new IdleGCTrigger(heap, sheap, thread);
TriggerGCTaskCallback callback = [](TriggerGCData& data) {
data.second = 1;
};
trigger->SetTriggerGCTaskCallback(callback);
ASSERT_EQ(trigger->TryTriggerIdleLocalOldGC(), true);
}
HWTEST_F_L0(IdleGCTriggerTest, ReachIdleLocalOldGCThresholdsTest001)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
@ -235,6 +305,37 @@ HWTEST_F_L0(IdleGCTriggerTest, TryTriggerIdleGCTest004)
trigger->TryTriggerIdleGC(TRIGGER_IDLE_GC_TYPE::LOCAL_REMARK);
}
HWTEST_F_L0(IdleGCTriggerTest, TryTriggerIdleGCTest011)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
SharedHeap *sheap = SharedHeap::GetInstance();
heap->SetOnSerializeEvent(true);
IdleGCTrigger *trigger = new IdleGCTrigger(heap, sheap, thread);
trigger->TryTriggerIdleGC(TRIGGER_IDLE_GC_TYPE::LOCAL_REMARK);
}
HWTEST_F_L0(IdleGCTriggerTest, TryTriggerIdleGCTest012)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
SharedHeap *sheap = SharedHeap::GetInstance();
sheap->NotifyHeapAliveSizeAfterGC(0);
sheap->GetOldSpace()->SetInitialCapacity(10000);
sheap->GetOldSpace()->IncreaseLiveObjectSize(5242889);
IdleGCTrigger *trigger = new IdleGCTrigger(heap, sheap, thread);
trigger->TryTriggerIdleGC(TRIGGER_IDLE_GC_TYPE::FULL_GC);
}
HWTEST_F_L0(IdleGCTriggerTest, TryTriggerIdleGCTest013)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
SharedHeap *sheap = SharedHeap::GetInstance();
sheap->NotifyHeapAliveSizeAfterGC(0);
sheap->GetOldSpace()->SetInitialCapacity(10000);
sheap->GetOldSpace()->IncreaseLiveObjectSize(5242889);
IdleGCTrigger *trigger = new IdleGCTrigger(heap, sheap, thread);
trigger->TryTriggerIdleGC(TRIGGER_IDLE_GC_TYPE::SHARED_FULL_GC);
}
HWTEST_F_L0(IdleGCTriggerTest, ShouldCheckIdleOldGCTest001)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());

View File

@ -101,6 +101,15 @@ HWTEST_F_L0(JitFortTest, UpdateFreeSpaceTest001)
jitFort->UpdateFreeSpace();
}
HWTEST_F_L0(JitFortTest, UpdateFreeSpaceTest002)
{
JitFort *jitFort = new JitFort();
jitFort->SetMachineCodeGC(false);
ASSERT_EQ(jitFort->IsMachineCodeGC(), false);
ASSERT_NE(jitFort, nullptr);
jitFort->UpdateFreeSpace();
}
HWTEST_F_L0(JitFortTest, GetDescTest001)
{
MemDescPool *pool = new MemDescPool(1, 1);