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/global_env.h"
17 #include "ecmascript/object_factory-inl.h"
18 #include "ecmascript/tests/test_helper.h"
19 #include "ecmascript/jit/jit_task.h"
20
21 using namespace panda::ecmascript;
22
23 namespace panda::test {
24 class JitTest : public testing::Test {
25 public:
SetUpTestCase()26 static void SetUpTestCase()
27 {
28 GTEST_LOG_(INFO) << "SetUpTestCase";
29 }
30
TearDownTestCase()31 static void TearDownTestCase()
32 {
33 GTEST_LOG_(INFO) << "TearDownCase";
34 }
35
SetUp()36 void SetUp() override
37 {
38 TestHelper::CreateEcmaVMWithScope(instance_, thread_, scope_, false, false, true, true);
39 thread_ = instance_->GetJSThread();
40 JitTaskpool::GetCurrentTaskpool()->WaitForJitTaskPoolReady();
41 compilerVm_ = JitTaskpool::GetCurrentTaskpool()->GetCompilerVm();
42 jit_ = Jit::GetInstance();
43 }
44
TearDown()45 void TearDown() override
46 {
47 TestHelper::DestroyEcmaVMWithScope(instance_, scope_);
48 }
49
50 EcmaVM *instance_ {nullptr};
51 EcmaHandleScope *scope_ {nullptr};
52 JSThread *thread_ {nullptr};
53 EcmaVM *compilerVm_ {nullptr};
54 Jit *jit_ {nullptr};
55 };
56
57 /**
58 * @tc.name: IsEnableFastJit
59 * @tc.desc: check jit is enable fast.
60 * @tc.type: FUNC
61 * @tc.require:
62 */
HWTEST_F_L0(JitTest,IsEnableFastJit)63 HWTEST_F_L0(JitTest, IsEnableFastJit)
64 {
65 EXPECT_TRUE(jit_->IsEnableFastJit());
66 }
67
68 /**
69 * @tc.name: NewJitTask
70 * @tc.desc: check new jit task.
71 * @tc.type: FUNC
72 * @tc.require:
73 */
HWTEST_F_L0(JitTest,NewJitTask)74 HWTEST_F_L0(JitTest, NewJitTask)
75 {
76 JSHandle<JSFunction> emptyHandle;
77 CString methodName("methodName");
78 std::shared_ptr<JitTask> jitTask = std::make_shared<JitTask>(thread_, compilerVm_->GetJSThreadNoCheck(),
79 jit_, emptyHandle, CompilerTier(CompilerTier::Tier::FAST), methodName, 0,
80 JitCompileMode(JitCompileMode::Mode::SYNC));
81 EXPECT_TRUE(jitTask->GetHostThread() == thread_);
82 }
83 } // namespace panda::test
84