• 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	};
33	if (!etsVm.createRuntime(etsOpts)) {
34		throw Error('Cannot create ETS runtime');
35	}
36
37	const runTestImpl = etsVm.getFunction(globalName, test);
38	runTestImpl();
39	let counter = 0;
40	const maxCounter = 5;
41	const checkDelay = 1000;
42	let tId = 0;
43	let checkCallback = () => {
44		++counter;
45		if (counter === maxCounter) {
46			throw new Error('Test failed: timeout.');
47		}
48		const check = etsVm.getFunction(globalName, 'check');
49		let result = check();
50		if (result) {
51			clearInterval(tId);
52		}
53	};
54	tId = setInterval(checkCallback, checkDelay);
55}
56
57let args = helper.getArgv();
58if (args.length !== 6) {
59	throw Error('Expected test name');
60}
61runTest(args[5]);
62