• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2025 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
16const helper = requireNapiPreview('libinterop_test_helper.so', false);
17
18function runTest(test) {
19    print('Running test ' + test);
20    const gtestAbcPath = helper.getEnvironmentVar('ARK_ETS_INTEROP_JS_GTEST_ABC_PATH');
21    const stdlibPath = helper.getEnvironmentVar('ARK_ETS_STDLIB_PATH');
22    const packageName = helper.getEnvironmentVar('PACKAGE_NAME');
23	if (!packageName) {
24		throw Error('PACKAGE_NAME is not set');
25	}
26	const globalName = 'L' + packageName + '/ETSGLOBAL;';
27
28    let etsVm = requireNapiPreview('ets_interop_js_napi.so', false);
29    const etsOpts = {
30        'panda-files': gtestAbcPath,
31        'boot-panda-files': `${stdlibPath}:${gtestAbcPath}`,
32        'gc-trigger-type': 'heap-trigger',
33        'load-runtimes': 'ets',
34        'compiler-enable-jit': 'false',
35        'xgc-trigger-type': 'never',
36    };
37    if (!etsVm.createRuntime(etsOpts)) {
38        throw Error('Cannot create ETS runtime');
39    }
40    const runTestImpl = etsVm.getFunction(globalName, test);
41    runTestImpl();
42    let tId = 0;
43    let checkFn = () => {
44        const is_unset = etsVm.getFunction(globalName, 'is_unset');
45        if (is_unset()) {
46            return;
47        }
48        clearInterval(tId);
49        const check = etsVm.getFunction(globalName, 'check');
50        check();
51    };
52    tId = setInterval(checkFn);
53}
54
55let args = helper.getArgv();
56if (args.length !== 6) {
57    throw Error('Expected test name');
58}
59runTest(args[5]);
60