14d6c458bSopenharmony_ci/*
24d6c458bSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
34d6c458bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44d6c458bSopenharmony_ci * you may not use this file except in compliance with the License.
54d6c458bSopenharmony_ci * You may obtain a copy of the License at
64d6c458bSopenharmony_ci *
74d6c458bSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84d6c458bSopenharmony_ci *
94d6c458bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104d6c458bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114d6c458bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124d6c458bSopenharmony_ci * See the License for the specific language governing permissions and
134d6c458bSopenharmony_ci * limitations under the License.
144d6c458bSopenharmony_ci */
154d6c458bSopenharmony_ci
164d6c458bSopenharmony_ci#include "test.h"
174d6c458bSopenharmony_ci
184d6c458bSopenharmony_ci#include "ark_native_engine.h"
194d6c458bSopenharmony_ci#include "tools/log.h"
204d6c458bSopenharmony_ci
214d6c458bSopenharmony_ciusing panda::RuntimeOption;
224d6c458bSopenharmony_cistatic NativeEngine *g_nativeEngine = nullptr;
234d6c458bSopenharmony_ci
244d6c458bSopenharmony_ciNativeEngineTest::NativeEngineTest()
254d6c458bSopenharmony_ci{
264d6c458bSopenharmony_ci    engine_ = g_nativeEngine;
274d6c458bSopenharmony_ci}
284d6c458bSopenharmony_ci
294d6c458bSopenharmony_ciNativeEngineTest::~NativeEngineTest() {}
304d6c458bSopenharmony_ci
314d6c458bSopenharmony_ciint main(int argc, char **argv)
324d6c458bSopenharmony_ci{
334d6c458bSopenharmony_ci    testing::GTEST_FLAG(output) = "xml:./";
344d6c458bSopenharmony_ci    testing::InitGoogleTest(&argc, argv);
354d6c458bSopenharmony_ci
364d6c458bSopenharmony_ci    // Setup
374d6c458bSopenharmony_ci    RuntimeOption option;
384d6c458bSopenharmony_ci    option.SetGcType(RuntimeOption::GC_TYPE::GEN_GC);
394d6c458bSopenharmony_ci
404d6c458bSopenharmony_ci    const int64_t poolSize = 0x1000000;  // 16M
414d6c458bSopenharmony_ci    option.SetGcPoolSize(poolSize);
424d6c458bSopenharmony_ci
434d6c458bSopenharmony_ci    option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
444d6c458bSopenharmony_ci    option.SetDebuggerLibraryPath("");
454d6c458bSopenharmony_ci    EcmaVM *vm = panda::JSNApi::CreateJSVM(option);
464d6c458bSopenharmony_ci    if (vm == nullptr) {
474d6c458bSopenharmony_ci        return 0;
484d6c458bSopenharmony_ci    }
494d6c458bSopenharmony_ci
504d6c458bSopenharmony_ci    g_nativeEngine = new ArkNativeEngine(vm, nullptr);
514d6c458bSopenharmony_ci
524d6c458bSopenharmony_ci    int ret = testing::UnitTest::GetInstance()->Run();
534d6c458bSopenharmony_ci
544d6c458bSopenharmony_ci    g_nativeEngine->Loop(LOOP_NOWAIT);
554d6c458bSopenharmony_ci
564d6c458bSopenharmony_ci    delete g_nativeEngine;
574d6c458bSopenharmony_ci    g_nativeEngine = nullptr;
584d6c458bSopenharmony_ci    panda::JSNApi::DestroyJSVM(vm);
594d6c458bSopenharmony_ci    vm = nullptr;
604d6c458bSopenharmony_ci
614d6c458bSopenharmony_ci    return ret;
624d6c458bSopenharmony_ci}
63