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