1 /*
2  * Copyright (c) 2022 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 "test.h"
17 #include "ark_native_engine.h"
18 #include "tools/log.h"
19 
20 using panda::RuntimeOption;
21 static NativeEngine *g_nativeEngine = nullptr;
22 
NativeEngineTest()23 NativeEngineTest::NativeEngineTest()
24 {
25     engine_ = g_nativeEngine;
26 }
27 
~NativeEngineTest()28 NativeEngineTest::~NativeEngineTest() {}
29 
main(int argc,char ** argv)30 int main(int argc, char **argv)
31 {
32     testing::GTEST_FLAG(output) = "xml:./";
33     testing::InitGoogleTest(&argc, argv);
34 
35     // Setup
36     RuntimeOption option;
37     option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC);
38 
39     const int64_t poolSize = 0x1000000;  // 16M
40     option.SetGcPoolSize(poolSize);
41 
42     option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
43     option.SetDebuggerLibraryPath("");
44     EcmaVM *vm = panda::JSNApi::CreateJSVM(option);
45     if (vm == nullptr) {
46         return 0;
47     }
48 
49     g_nativeEngine = new ArkNativeEngine(vm, nullptr);
50 
51     int ret = testing::UnitTest::GetInstance()->Run();
52 
53     g_nativeEngine->Loop(LOOP_NOWAIT);
54     if (g_nativeEngine) {
55         delete g_nativeEngine;
56         g_nativeEngine = nullptr;
57     }
58     panda::JSNApi::DestroyJSVM(vm);
59     vm = nullptr;
60 
61     return ret;
62 }
63