1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ecmascript/checkpoint/thread_state_transition.h"
17 #include "ecmascript/global_env.h"
18 #include "ecmascript/object_factory-inl.h"
19 #include "ecmascript/tests/test_helper.h"
20 #include "ecmascript/jit/jit_task.h"
21
22 using namespace panda::ecmascript;
23
24 namespace panda::test {
25 class JitTest : public testing::Test {
26 public:
SetUpTestCase()27 static void SetUpTestCase()
28 {
29 GTEST_LOG_(INFO) << "SetUpTestCase";
30 }
31
TearDownTestCase()32 static void TearDownTestCase()
33 {
34 GTEST_LOG_(INFO) << "TearDownCase";
35 }
36
SetUp()37 void SetUp() override
38 {
39 TestHelper::CreateEcmaVMWithScope(instance_, thread_, scope_, false, false, true, true);
40 thread_ = instance_->GetJSThread();
41 ThreadNativeScope scope(thread_);
42 JitTaskpool::GetCurrentTaskpool()->WaitForJitTaskPoolReady();
43 compilerVm_ = JitTaskpool::GetCurrentTaskpool()->GetCompilerVm();
44 jit_ = Jit::GetInstance();
45 }
46
TearDown()47 void TearDown() override
48 {
49 TestHelper::DestroyEcmaVMWithScope(instance_, scope_);
50 }
51
52 EcmaVM *instance_ {nullptr};
53 EcmaHandleScope *scope_ {nullptr};
54 JSThread *thread_ {nullptr};
55 EcmaVM *compilerVm_ {nullptr};
56 Jit *jit_ {nullptr};
57 };
58
59 /**
60 * @tc.name: IsEnableFastJit
61 * @tc.desc: check jit is enable fast.
62 * @tc.type: FUNC
63 * @tc.require:
64 */
HWTEST_F_L0(JitTest,IsEnableFastJit)65 HWTEST_F_L0(JitTest, IsEnableFastJit)
66 {
67 EXPECT_TRUE(jit_->IsEnableFastJit());
68 }
69
70 /**
71 * @tc.name: NewJitTask
72 * @tc.desc: check new jit task.
73 * @tc.type: FUNC
74 * @tc.require:
75 */
HWTEST_F_L0(JitTest,NewJitTask)76 HWTEST_F_L0(JitTest, NewJitTask)
77 {
78 JSHandle<JSFunction> emptyHandle;
79 CString methodName("methodName");
80 std::shared_ptr<JitTask> jitTask = std::make_shared<JitTask>(thread_, compilerVm_->GetJSThreadNoCheck(),
81 jit_, emptyHandle, CompilerTier(CompilerTier::Tier::FAST), methodName, 0,
82 JitCompileMode(JitCompileMode::Mode::SYNC));
83 EXPECT_TRUE(jitTask->GetHostThread() == thread_);
84 }
85 } // namespace panda::test
86