1/** 2 * Copyright (c) 2021-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 'xgc-trigger-type': 'never', 33 }; 34 if (!etsVm.createRuntime(etsOpts)) { 35 throw Error('Cannot create ETS runtime'); 36 } 37 const runTestImpl = etsVm.getFunction(globalName, test); 38 let res = runTestImpl(); 39 let tId = 0; 40 let checkFn = () => { 41 const is_unset = etsVm.getFunction(globalName, 'is_unset'); 42 if (is_unset()) { 43 return; 44 } 45 clearInterval(tId); 46 const check = etsVm.getFunction(globalName, 'check'); 47 check(); 48 }; 49 tId = setInterval(checkFn, 0); 50} 51 52let args = helper.getArgv(); 53if (args.length !== 6) { 54 throw Error('Expected test name'); 55} 56runTest(args[5]); 57