[JIT] Add jit utest

Add jit utest

Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IB1JRH
Change-Id: Iacaeb77b42e5707f0a7fc2d1aa2874eae17f58b6
Signed-off-by: xiaoweidong <xiaoweidong@huawei.com>
This commit is contained in:
xiaoweidong 2024-11-01 21:17:33 +08:00
parent 13f627f1ea
commit ef20bff134
5 changed files with 165 additions and 4 deletions

View File

@ -107,6 +107,7 @@ group("ark_js_unittest") {
"ecmascript/dfx/stackinfo/tests:unittest",
"ecmascript/extractortool/tests:unittest",
"ecmascript/ic/tests:unittest",
"ecmascript/jit/tests:unittest",
"ecmascript/jobs/tests:unittest",
"ecmascript/jspandafile/tests:unittest",
"ecmascript/module/tests:unittest",
@ -147,6 +148,7 @@ group("ark_unittest") {
"ecmascript/dfx/stackinfo/tests:host_unittest",
"ecmascript/extractortool/tests:host_unittest",
"ecmascript/ic/tests:host_unittest",
"ecmascript/jit/tests:host_unittest",
"ecmascript/jobs/tests:host_unittest",
"ecmascript/jspandafile/tests:host_unittest",
"ecmascript/module/tests:host_unittest",

View File

@ -167,7 +167,9 @@ void Jit::SetEnableOrDisable(const JSRuntimeOptions &options, bool isEnableFastJ
isApp_ = options.IsEnableAPPJIT();
hotnessThreshold_ = options.GetJitHotnessThreshold();
initJitCompiler_(options);
if (initJitCompiler_ != nullptr) {
initJitCompiler_(options);
}
bool enableCodeSign = !ohos::JitTools::GetCodeSignDisable(options.GetDisableCodeSign());
bool shouldCompileMain =
options.IsEnableForceJitCompileMain() || options.IsEnableForceBaselineCompileMain();
@ -239,6 +241,8 @@ void Jit::SetEnableAsyncCopyToFort(bool isEnableAsyncCopyToFort)
void Jit::Initialize()
{
#if defined(OHOS_UNIT_TEST)
#else
static const std::string CREATEJITCOMPILETASK = "CreateJitCompilerTask";
static const std::string JITCOMPILEINIT = "InitJitCompiler";
static const std::string JITCOMPILE = "JitCompile";
@ -283,6 +287,7 @@ void Jit::Initialize()
LOG_JIT(ERROR) << "jit can't find symbol deleteJitCompile";
return;
}
#endif
initialized_= true;
return;
}
@ -327,7 +332,9 @@ bool Jit::SupportJIT(JSHandle<JSFunction> &jsFunction, [[maybe_unused]] EcmaVM *
void Jit::DeleteJitCompile(void *compiler)
{
deleteJitCompile_(compiler);
if (deleteJitCompile_ != nullptr) {
deleteJitCompile_(compiler);
}
}
void Jit::CountInterpExecFuncs(JSHandle<JSFunction> &jsFunction)
@ -533,7 +540,9 @@ bool Jit::JitFinalize(void *compiler, JitTask *jitTask)
void *Jit::CreateJitCompilerTask(JitTask *jitTask)
{
ASSERT(createJitCompilerTask_ != nullptr);
if (createJitCompilerTask_ == nullptr) {
return nullptr;
}
return createJitCompilerTask_(jitTask);
}

View File

@ -0,0 +1,64 @@
# 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.
import("//arkcompiler/ets_runtime/js_runtime_config.gni")
import("//arkcompiler/ets_runtime/test/test_helper.gni")
module_output_path = "arkcompiler/ets_runtime"
host_unittest_action("JIT_001_Test") {
module_out_path = module_output_path
sources = [
# test file
"jit_test.cpp",
]
configs = [
"../../../:asm_interp_enable_config",
"../../../: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",
sdk_libc_secshared_dep,
]
# hiviewdfx libraries
external_deps = hiviewdfx_ext_deps
deps += hiviewdfx_deps
}
group("unittest") {
testonly = true
# deps file
deps = [ ":JIT_001_Test" ]
}
group("host_unittest") {
testonly = true
# deps file
if (is_linux) {
deps = [ ":JIT_001_TestAction" ]
}
if (is_mac) {
deps -= [ ":JIT_001_TestAction" ]
}
}

View File

@ -0,0 +1,82 @@
/*
* 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/global_env.h"
#include "ecmascript/object_factory-inl.h"
#include "ecmascript/tests/test_helper.h"
#include "ecmascript/jit/jit_task.h"
using namespace panda::ecmascript;
namespace panda::test {
class JitTest : public testing::Test {
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "TearDownCase";
}
void SetUp() override
{
TestHelper::CreateEcmaVMWithScope(instance_, thread_, scope_, false, false, true, true);
thread_ = instance_->GetJSThread();
JitTaskpool::GetCurrentTaskpool()->WaitForJitTaskPoolReady();
compilerVm_ = JitTaskpool::GetCurrentTaskpool()->GetCompilerVm();
jit_ = Jit::GetInstance();
}
void TearDown() override
{
TestHelper::DestroyEcmaVMWithScope(instance_, scope_);
}
EcmaVM *instance_ {nullptr};
EcmaHandleScope *scope_ {nullptr};
JSThread *thread_ {nullptr};
EcmaVM *compilerVm_ {nullptr};
Jit *jit_ {nullptr};
};
/**
* @tc.name: IsEnableFastJit
* @tc.desc: check jit is enable fast.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F_L0(JitTest, IsEnableFastJit)
{
EXPECT_TRUE(jit_->IsEnableFastJit());
}
/**
* @tc.name: NewJitTask
* @tc.desc: check new jit task.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F_L0(JitTest, NewJitTask)
{
JSHandle<JSFunction> emptyHandle;
CString methodName("methodName");
std::shared_ptr<JitTask> jitTask = std::make_shared<JitTask>(thread_, compilerVm_->GetJSThreadNoCheck(),
jit_, emptyHandle, CompilerTier::FAST, methodName, 0, thread_->GetThreadId(), JitCompileMode::SYNC);
EXPECT_TRUE(jitTask->GetHostThread() == thread_);
}
} // namespace panda::test

View File

@ -106,7 +106,8 @@ public:
// If you want to call once create, you can refer to BuiltinsMathTest for detail.
static void CreateEcmaVMWithScope(EcmaVM *&instance, JSThread *&thread, EcmaHandleScope *&scope,
bool tryLoadStubFile = false, bool useCInterpreter = false, bool startManagedCode = true)
bool tryLoadStubFile = false, bool useCInterpreter = false, bool startManagedCode = true,
bool enableFastJit = false)
{
JSRuntimeOptions options;
options.SetEnableForceGC(true);
@ -116,6 +117,9 @@ public:
if (useCInterpreter) {
options.SetEnableAsmInterpreter(false);
}
if (enableFastJit) {
options.SetEnableJIT(true);
}
instance = JSNApi::CreateEcmaVM(options);
instance->SetEnableForceGC(true);
ASSERT_TRUE(instance != nullptr) << "Cannot create EcmaVM";