!9587 Add UT for GC

Merge pull request !9587 from Sandee/ut_20240928
This commit is contained in:
openharmony_ci 2024-10-06 10:27:40 +00:00 committed by Gitee
commit 348fba8064
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 267 additions and 5 deletions

View File

@ -2226,7 +2226,7 @@ void Heap::TriggerIdleCollection(int idleMicroSec)
case IdleTaskType::INCREMENTAL_MARK:
incrementalMarker_->TriggerIncrementalMark(idleMicroSec);
break;
default:
default: // LCOV_EXCL_BR_LINE
break;
}
ClearIdleTask();

View File

@ -79,7 +79,8 @@ bool MachineCode::SetText(const MachineCodeDesc &desc)
uint8_t *pText = textStart;
if (desc.rodataSizeBeforeTextAlign != 0) {
if (memcpy_s(pText, desc.rodataSizeBeforeTextAlign,
reinterpret_cast<uint8_t*>(desc.rodataAddrBeforeText), desc.rodataSizeBeforeText) != EOK) {
reinterpret_cast<uint8_t*>(desc.rodataAddrBeforeText),
desc.rodataSizeBeforeText) != EOK) { // LCOV_EXCL_BR_LINE
LOG_JIT(ERROR) << "memcpy fail in copy fast jit code";
return false;
}
@ -94,7 +95,8 @@ bool MachineCode::SetText(const MachineCodeDesc &desc)
pText += desc.codeSizeAlign;
if (desc.rodataSizeAfterTextAlign != 0) {
if (memcpy_s(pText, desc.rodataSizeAfterTextAlign,
reinterpret_cast<uint8_t*>(desc.rodataAddrAfterText), desc.rodataSizeAfterText) != EOK) {
reinterpret_cast<uint8_t*>(desc.rodataAddrAfterText),
desc.rodataSizeAfterText) != EOK) { // LCOV_EXCL_BR_LINE
LOG_JIT(ERROR) << "memcpy fail in copy fast jit code";
return false;
}
@ -108,7 +110,7 @@ bool MachineCode::SetNonText(const MachineCodeDesc &desc, EntityId methodId)
uint8_t *stackmapAddr = GetStackMapOrOffsetTableAddress();
if (memcpy_s(stackmapAddr, desc.stackMapOrOffsetTableSize,
reinterpret_cast<uint8_t*>(desc.stackMapOrOffsetTableAddr),
desc.stackMapOrOffsetTableSize) != EOK) {
desc.stackMapOrOffsetTableSize) != EOK) { // LCOV_EXCL_BR_LINE
LOG_JIT(ERROR) << "memcpy fail in copy fast jit stackmap";
return false;
}
@ -224,7 +226,7 @@ bool MachineCode::SetBaselineCodeData(const MachineCodeDesc &desc,
uint8_t *stackmapAddr = GetStackMapOrOffsetTableAddress();
if (memcpy_s(stackmapAddr, desc.stackMapOrOffsetTableSize,
reinterpret_cast<uint8_t*>(desc.stackMapOrOffsetTableAddr),
desc.stackMapOrOffsetTableSize) != EOK) {
desc.stackMapOrOffsetTableSize) != EOK) { // LCOV_EXCL_BR_LINE
LOG_BASELINEJIT(ERROR) << "memcpy fail in copy fast baselineJIT offsetTable";
return false;
}

View File

@ -1456,6 +1456,33 @@ host_unittest_action("EcmaVm_053_Test") {
deps += hiviewdfx_deps
}
host_unittest_action("EcmaVm_054_Test") {
module_out_path = module_output_path
sources = [
# test file
"machine_code_test.cpp",
]
configs = [
"../../:ecma_test_config",
"$ark_root/assembler:arkassembler_public_config",
"$ark_root/libpandafile:arkfile_public_config",
]
deps = [
"$ark_third_party_root/icu/icu4c:shared_icui18n",
"$ark_third_party_root/icu/icu4c:shared_icuuc",
"../../:libark_jsruntime_test",
"../../../runtime_core/assembler:libarkassembler_static",
sdk_libc_secshared_dep,
]
# hiviewdfx libraries
external_deps = hiviewdfx_ext_deps
deps += hiviewdfx_deps
}
group("unittest") {
testonly = true
@ -1511,6 +1538,7 @@ group("unittest") {
":EcmaVm_051_Test",
":EcmaVm_052_Test",
":EcmaVm_053_Test",
":EcmaVm_054_Test",
]
}
@ -1569,6 +1597,7 @@ group("host_unittest") {
":EcmaVm_051_TestAction",
":EcmaVm_052_TestAction",
":EcmaVm_053_TestAction",
":EcmaVm_054_TestAction",
]
if (is_mac) {
@ -1623,6 +1652,7 @@ group("host_unittest") {
":EcmaVm_051_TestAction",
":EcmaVm_052_TestAction",
":EcmaVm_053_TestAction",
":EcmaVm_054_TestAction",
]
}
}

View File

@ -20,6 +20,7 @@
#include "ecmascript/mem/concurrent_marker.h"
#include "ecmascript/mem/stw_young_gc.h"
#include "ecmascript/mem/partial_gc.h"
#include "ecmascript/mem/incremental_marker.h"
#include "ecmascript/tests/ecma_test_common.h"
using namespace panda;
@ -419,4 +420,35 @@ HWTEST_F_L0(GCTest, CollectGarbageTest002)
heap->CollectGarbage(TriggerGCType::EDEN_GC, GCReason::IDLE);
}
HWTEST_F_L0(GCTest, CollectGarbageTest003)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
heap->GetJSThread()->SetMarkStatus(MarkStatus::READY_TO_MARK);
heap->CollectGarbage(TriggerGCType::FULL_GC, GCReason::IDLE);
}
HWTEST_F_L0(GCTest, NeedStopCollectionTest002)
{
SharedHeap *heap = SharedHeap::GetInstance();
heap->SetSensitiveStatus(AppSensitiveStatus::ENTER_HIGH_SENSITIVE);
ASSERT_EQ(heap->NeedStopCollection(), true);
}
HWTEST_F_L0(GCTest, NeedStopCollectionTest003)
{
SharedHeap *heap = SharedHeap::GetInstance();
heap->SetSensitiveStatus(AppSensitiveStatus::ENTER_HIGH_SENSITIVE);
heap->GetOldSpace()->SetInitialCapacity(1000);
ASSERT_EQ(heap->NeedStopCollection(), false);
}
HWTEST_F_L0(GCTest, TriggerIdleCollectionTest007)
{
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
heap->SetIdleTask(IdleTaskType::INCREMENTAL_MARK);
ASSERT_EQ(heap->GetIncrementalMarker()->GetIncrementalGCStates(), IncrementalGCStates::ROOT_SCAN);
heap->GetIncrementalMarker()->TriggerIncrementalMark(1000);
heap->TriggerIdleCollection(1000);
}
} // namespace panda::test

View File

@ -0,0 +1,193 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecmascript/mem/concurrent_marker.h"
#include "ecmascript/mem/machine_code.h"
#include "ecmascript/jit/jit.h"
#include "ecmascript/global_env.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/js_array.h"
#include "ecmascript/ecma_vm.h"
#include "ecmascript/object_factory-inl.h"
#include "ecmascript/tests/test_helper.h"
using namespace panda;
using namespace panda::ecmascript;
namespace panda::test {
class MachineCodeTest : public BaseTestWithScope<false> {
public:
void SetUp() override
{
JSRuntimeOptions options;
options.SetEnableEdenGC(true);
instance = JSNApi::CreateEcmaVM(options);
ASSERT_TRUE(instance != nullptr) << "Cannot create EcmaVM";
thread = instance->GetJSThread();
thread->ManagedCodeBegin();
scope = new EcmaHandleScope(thread);
auto heap = const_cast<Heap *>(thread->GetEcmaVM()->GetHeap());
heap->GetConcurrentMarker()->EnableConcurrentMarking(EnableConcurrentMarkType::ENABLE);
heap->GetSweeper()->EnableConcurrentSweep(EnableConcurrentSweepType::ENABLE);
}
};
HWTEST_F_L0(MachineCodeTest, SetMachineCodeObjectDataTest001)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSFunction> func(thread->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction());
JSHandle<Method> method(thread, func->GetMethod());
MachineCodeDesc desc;
desc.codeType = MachineCodeType::BASELINE_CODE;
desc.instructionsSize = 100;
desc.instructionsAddr = 1000;
desc.stackMapSizeAlign = 100;
TaggedObject *machineCode = factory->NewMachineCodeObject(100, desc);
factory->SetMachineCodeObjectData(machineCode, 100, desc, method);
}
HWTEST_F_L0(MachineCodeTest, SetMachineCodeObjectDataTest002)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSFunction> func(thread->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction());
JSHandle<Method> method(thread, func->GetMethod());
MachineCodeDesc desc;
desc.codeType = MachineCodeType::BASELINE_CODE;
desc.instructionsSize = 100;
desc.instructionsAddr = 1000;
desc.stackMapSizeAlign = 100;
Jit::GetInstance()->SetEnableJitFort(false);
ASSERT_EQ(Jit::GetInstance()->IsEnableJitFort(), false);
TaggedObject *machineCode = factory->NewMachineCodeObject(100, desc);
factory->SetMachineCodeObjectData(machineCode, 100, desc, method);
}
HWTEST_F_L0(MachineCodeTest, SetMachineCodeObjectDataTest003)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSFunction> func(thread->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction());
JSHandle<Method> method(thread, func->GetMethod());
MachineCodeDesc desc;
desc.codeType = MachineCodeType::FAST_JIT_CODE;
desc.instructionsSize = 100;
desc.instructionsAddr = 1000;
desc.stackMapSizeAlign = 100;
Jit::GetInstance()->SetEnableJitFort(false);
ASSERT_EQ(Jit::GetInstance()->IsEnableJitFort(), false);
TaggedObject *machineCode = factory->NewMachineCodeObject(100, desc);
factory->SetMachineCodeObjectData(machineCode, 100, desc, method);
}
HWTEST_F_L0(MachineCodeTest, SetMachineCodeObjectDataTest004)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSFunction> func(thread->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction());
JSHandle<Method> method(thread, func->GetMethod());
MachineCodeDesc desc;
desc.codeType = MachineCodeType::FAST_JIT_CODE;
desc.instructionsSize = 100;
desc.instructionsAddr = 1000;
desc.stackMapSizeAlign = 100;
desc.rodataSizeAfterTextAlign = 0;
desc.rodataSizeBeforeTextAlign = 0;
desc.isAsyncCompileMode = true;
Jit::GetInstance()->SetEnableAsyncCopyToFort(true);
Jit::GetInstance()->SetEnableJitFort(true);
ASSERT_EQ(Jit::GetInstance()->IsEnableAsyncCopyToFort(), true);
TaggedObject *machineCode = factory->NewMachineCodeObject(100, desc);
factory->SetMachineCodeObjectData(machineCode, 100, desc, method);
}
HWTEST_F_L0(MachineCodeTest, SetMachineCodeObjectDataTest005)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSFunction> func(thread->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction());
JSHandle<Method> method(thread, func->GetMethod());
MachineCodeDesc desc;
desc.codeType = MachineCodeType::FAST_JIT_CODE;
desc.instructionsSize = 100;
desc.instructionsAddr = 1000;
desc.stackMapSizeAlign = 100;
desc.rodataSizeAfterTextAlign = 0;
desc.rodataSizeBeforeTextAlign = 0;
desc.isAsyncCompileMode = true;
desc.stackMapOrOffsetTableSize = 100;
desc.stackMapOrOffsetTableAddr = 100;
Jit::GetInstance()->SetEnableJitFort(false);
ASSERT_EQ(Jit::GetInstance()->IsEnableJitFort(), false);
TaggedObject *machineCode = factory->NewMachineCodeObject(100, desc);
MachineCode *code = MachineCode::Cast(machineCode);
code->GetStackMapOrOffsetTableAddress();
}
HWTEST_F_L0(MachineCodeTest, SetMachineCodeObjectDataTest006)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSFunction> func(thread->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction());
JSHandle<Method> method(thread, func->GetMethod());
MachineCodeDesc desc;
desc.codeType = MachineCodeType::FAST_JIT_CODE;
desc.instructionsSize = 100;
desc.instructionsAddr = 1000;
desc.stackMapSizeAlign = 100;
desc.rodataSizeAfterTextAlign = 0;
desc.rodataSizeBeforeTextAlign = 0;
desc.codeSizeAlign = 0;
desc.isAsyncCompileMode = true;
desc.funcEntryDesSizeAlign = 0;
desc.stackMapOrOffsetTableSize = 100;
Jit::GetInstance()->SetEnableJitFort(true);
Jit::GetInstance()->SetEnableAsyncCopyToFort(true);
TaggedObject *machineCode = factory->NewMachineCodeObject(100, desc);
MachineCode *code = MachineCode::Cast(machineCode);
const char src[] = "hello";
const char src2[] = "world";
desc.stackMapOrOffsetTableAddr = reinterpret_cast<uintptr_t>(src);
desc.funcEntryDesAddr = reinterpret_cast<uintptr_t>(src2);
desc.funcEntryDesSize = 100;
ASSERT_EQ(code->SetData(desc, method, 100), true);
}
HWTEST_F_L0(MachineCodeTest, SetMachineCodeObjectDataTest007)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<JSFunction> func(thread->GetEcmaVM()->GetGlobalEnv()->GetArrayFunction());
JSHandle<Method> method(thread, func->GetMethod());
MachineCodeDesc desc;
desc.codeType = MachineCodeType::FAST_JIT_CODE;
desc.instructionsSize = 100;
desc.instructionsAddr = 1000;
desc.stackMapSizeAlign = -100;
desc.rodataSizeAfterTextAlign = 0;
desc.rodataSizeBeforeTextAlign = 0;
desc.codeSizeAlign = 0;
desc.isAsyncCompileMode = true;
desc.funcEntryDesSizeAlign = 0;
desc.stackMapOrOffsetTableSize = 100;
Jit::GetInstance()->SetEnableJitFort(true);
Jit::GetInstance()->SetEnableAsyncCopyToFort(true);
TaggedObject *machineCode = factory->NewMachineCodeObject(100, desc);
MachineCode *code = MachineCode::Cast(machineCode);
const char src[] = "hello";
const char src2[] = "world";
desc.stackMapOrOffsetTableAddr = reinterpret_cast<uintptr_t>(src);
desc.funcEntryDesAddr = reinterpret_cast<uintptr_t>(src2);
desc.funcEntryDesSize = 100;
ASSERT_EQ(code->SetData(desc, method, -100), true);
}
}

View File

@ -746,6 +746,11 @@
<option name="push" value="test/test/libark_jsruntime_test.so -> /data/test" src="out"/>
</preparer>
</target>
<target name="EcmaVm_054_Test">
<preparer>
<option name="push" value="test/test/libark_jsruntime_test.so -> /data/test" src="out"/>
</preparer>
</target>
<target name="OhosTest">
<preparer>
<option name="push" value="test/test/libark_jsruntime_test.so -> /data/test" src="out"/>