1/* 2 * Copyright (c) 2021 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 18#include "jerryscript_native_engine.h" 19 20static NativeEngine* g_nativeEngine = nullptr; 21static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024; 22NativeEngineTest::NativeEngineTest() 23{ 24 engine_ = g_nativeEngine; 25} 26 27NativeEngineTest::~NativeEngineTest() {} 28 29static void* context_alloc_fn(size_t size, void* cb_data) 30{ 31 (void)cb_data; 32 size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size; 33 return malloc(newSize); 34} 35static void LoopNewThread(void* data) 36{ 37 g_nativeEngine->Loop(LOOP_DEFAULT); 38} 39int main(int argc, char** argv) 40{ 41 testing::GTEST_FLAG(output) = "xml:./"; 42 testing::InitGoogleTest(&argc, argv); 43 // allocate 50MB space 44 jerry_context_t* ctx_p = jerry_create_context(1024 * 1024 * 50, context_alloc_fn, NULL); 45 jerry_port_default_set_current_context(ctx_p); 46 jerry_init(jerry_init_flag_t::JERRY_INIT_EMPTY); 47 g_nativeEngine = new JerryScriptNativeEngine(0); // default instance id 0 48 uv_thread_t tid; 49 uv_thread_create(&tid, LoopNewThread, nullptr); 50 int ret = RUN_ALL_TESTS(); 51 uv_thread_join(&tid); 52 delete g_nativeEngine; 53 g_nativeEngine = nullptr; 54 jerry_cleanup(); 55 free(ctx_p); 56 return ret; 57} 58