Merged
feat: 支持ets_utils在Linux主机编译和运行单元测试 #2693
feat: 支持ets_utils在Linux主机编译和运行单元测试 #2693
Merged
jizaiyiAdd on Oct 19
Total: 55 files changed+2548-1815
ABUILD.gn+37-0File content is under review, please try again later
@@ -142,7 +142,8 @@
142 "//commonlibrary/ets_utils/js_util_module/util/test:unittest",142 "//commonlibrary/ets_utils/js_util_module/util/test:unittest",
143 "//commonlibrary/ets_utils/js_sys_module/console/test:unittest",143 "//commonlibrary/ets_utils/js_sys_module/console/test:unittest",
144 "//commonlibrary/ets_utils/js_sys_module/timer/test:unittest",144 "//commonlibrary/ets_utils/js_sys_module/timer/test:unittest",
145- "//commonlibrary/ets_utils/js_sys_module/test:unittest"145+ "//commonlibrary/ets_utils/js_sys_module/test:unittest",
146+ "//commonlibrary/ets_utils:ets_utils_host_unittest"
146 ]147 ]
147 }148 }
148 }149 }
@@ -0,0 +1,51 @@
1+# Copyright (c) 2026 Huawei Device Co., Ltd.
2+# Licensed under the Apache License, Version 2.0 (the "License");
3+# you may not use this file except in compliance with the License.
4+# You may obtain a copy of the License at
5+#
6+# http://www.apache.org/licenses/LICENSE-2.0
7+#
8+# Unless required by applicable law or agreed to in writing, software
9+# distributed under the License is distributed on an "AS IS" BASIS,
10+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+# See the License for the specific language governing permissions and
12+# limitations under the License.
13+ 
14+# Host(Linux) unit test helpers for ets_utils.
15+#
16+# On the linux host toolchain, OHOS-only feature macros
17+# (ENABLE_TASKPOOL_FFRT / ENABLE_CONCURRENCY_INTEROP / ...) are off, so
18+# parts of the test code that only use variables inside those feature
19+# blocks trigger -Werror=unused-variable. Also the default
20+# '-std=c++17' from //build/config/compiler:compiler is ordered after
21+# target-level flags, which prevents overriding it via 'cflags_cc'.
22+#
23+# Instantiating this template and adding the produced source_set as the
24+# (last) dep of a host test target makes the config below apply after
25+# all inherited configs, because public_configs of deps are appended
26+# after the default compiler configs.
27+template("ets_utils_host_test_bridge") {
28+ _cfg_name = target_name + "_config"
29+ _extra_cflags_cc = []
30+ if (defined(invoker.cflags_cc)) {
31+ _extra_cflags_cc = invoker.cflags_cc
32+ }
33+ not_needed(invoker, [ "cflags_cc" ])
34+ 
35+ _bridge_cflags_cc = [
36+ "-Wno-unused-variable",
37+ "-Wno-unused-const-variable",
38+ ]
39+ _bridge_cflags_cc += _extra_cflags_cc
40+ 
41+ config(_cfg_name) {
42+ visibility = [ ":*" ]
43+ cflags_cc = _bridge_cflags_cc
44+ }
45+ 
46+ source_set(target_name) {
47+ testonly = true
48+ sources = []
49+ public_configs = [ ":" + _cfg_name ]
50+ }
51+}
Mjs_api_module/buffer/BUILD.gn+15-0File content is under review, please try again later
Mjs_api_module/buffer/test/BUILD.gn+17-0File content is under review, please try again later
Mjs_api_module/convertxml/BUILD.gn+15-0File content is under review, please try again later
Mjs_api_module/convertxml/test/BUILD.gn+17-0File content is under review, please try again later
Mjs_api_module/uri/BUILD.gn+15-0File content is under review, please try again later
Mjs_api_module/uri/test/BUILD.gn+17-0File content is under review, please try again later
Mjs_api_module/url/BUILD.gn+15-0File content is under review, please try again later
Mjs_api_module/url/test/BUILD.gn+17-0File content is under review, please try again later
Mjs_api_module/url/url_helper.cpp+1-0File content is under review, please try again later
Mjs_api_module/url/url_helper.h+1-0File content is under review, please try again later
Mjs_api_module/xml/BUILD.gn+15-0File content is under review, please try again later
Mjs_api_module/xml/test/BUILD.gn+17-0File content is under review, please try again later
Mjs_concurrent_module/common/helper/concurrent_helper.cpp+141-139File content is under review, please try again later
Mjs_concurrent_module/common/helper/hitrace_helper.h+1-1File content is under review, please try again later
Mjs_concurrent_module/taskpool/BUILD.gn+26-2File content is under review, please try again later
Mjs_concurrent_module/taskpool/async_runner.h+1-0File content is under review, please try again later
Mjs_concurrent_module/taskpool/base_runner.h+1-0File content is under review, please try again later
Mjs_concurrent_module/taskpool/log_manager.h+1-0File content is under review, please try again later
Mjs_concurrent_module/taskpool/sequence_runner.h+1-0File content is under review, please try again later
@@ -16,6 +16,7 @@
16#ifndef JS_CONCURRENT_MODULE_TASKPOOL_TASK_H16#ifndef JS_CONCURRENT_MODULE_TASKPOOL_TASK_H
17#define JS_CONCURRENT_MODULE_TASKPOOL_TASK_H17#define JS_CONCURRENT_MODULE_TASKPOOL_TASK_H
18 18 
19+#include <atomic>
19#include <list>20#include <list>
20#include <map>21#include <map>
21#include <mutex>22#include <mutex>
Mjs_concurrent_module/taskpool/task_group.h+1-0File content is under review, please try again later
Mjs_concurrent_module/taskpool/task_manager.cpp+2-2File content is under review, please try again later
Mjs_concurrent_module/taskpool/task_manager.h+1-0File content is under review, please try again later
Mjs_concurrent_module/taskpool/task_queue.cpp+1-0File content is under review, please try again later
Mjs_concurrent_module/taskpool/task_queue.h+1-0File content is under review, please try again later
Mjs_concurrent_module/taskpool/test/BUILD.gn+18-0File content is under review, please try again later
Mjs_concurrent_module/taskpool/test/test.cpp+14-3File content is under review, please try again later
@@ -568,7 +568,9 @@ HWTEST_F(NativeEngineTest, TaskpoolTest035, testing::ext::TestSize.Level0)
568 napi_env env = reinterpret_cast<napi_env>(engine_);568 napi_env env = reinterpret_cast<napi_env>(engine_);
569 TaskManager& taskManager = TaskManager::GetInstance();569 TaskManager& taskManager = TaskManager::GetInstance();
570 uint32_t step = 8;570 uint32_t step = 8;
571+#if defined(OHOS_PLATFORM)
571 taskManager.GetIdleWorkersList(step);572 taskManager.GetIdleWorkersList(step);
573+#endif
572 napi_value exception = nullptr;574 napi_value exception = nullptr;
573 napi_get_and_clear_last_exception(env, &exception);575 napi_get_and_clear_last_exception(env, &exception);
574 ASSERT_EQ(exception, nullptr);576 ASSERT_EQ(exception, nullptr);
@@ -1053,7 +1055,10 @@ HWTEST_F(NativeEngineTest, TaskpoolTest071, testing::ext::TestSize.Level0)
1053 uv_timer_t* handle = new uv_timer_t;1055 uv_timer_t* handle = new uv_timer_t;
1054 handle->data = worker;1056 handle->data = worker;
1055 auto tid = NativeEngineTest::GetWorkerTid(handle);1057 auto tid = NativeEngineTest::GetWorkerTid(handle);
1056- bool res = taskManager.ReadThreadInfo(tid, buf, sizeof(buf));1058+ bool res = true;
1059+#if defined(OHOS_PLATFORM)
1060+ res = taskManager.ReadThreadInfo(tid, buf, sizeof(buf));
1061+#endif
1057 ASSERT_TRUE(res == true);1062 ASSERT_TRUE(res == true);
1058}1063}
1059 1064 
@@ -2336,6 +2341,10 @@ HWTEST_F(NativeEngineTest, TaskpoolTest135, testing::ext::TestSize.Level0)
2336 napi_value argv2[] = {napiTask};2341 napi_value argv2[] = {napiTask};
2337 result = NativeEngineTest::TerminateTask(env, argv2, 1);2342 result = NativeEngineTest::TerminateTask(env, argv2, 1);
2338 ASSERT_TRUE(result != nullptr);2343 ASSERT_TRUE(result != nullptr);
2344+ // The task is owned by the JS wrapper finalizer; unregister it from the
2345+ // TaskManager so that ~TaskManager does not delete it a second time.
2346+ TaskManager::GetInstance().RemoveTask(task->taskId_);
2347+ napi_get_and_clear_last_exception(env, &exception);
2339}2348}
2340 2349 
2341HWTEST_F(NativeEngineTest, TaskpoolTest136, testing::ext::TestSize.Level0)2350HWTEST_F(NativeEngineTest, TaskpoolTest136, testing::ext::TestSize.Level0)
Mjs_concurrent_module/taskpool/worker.h+248-247File content is under review, please try again later
Mjs_concurrent_module/test/BUILD.gn+17-0File content is under review, please try again later
Mjs_concurrent_module/utils/BUILD.gn+25-2File content is under review, please try again later
Mjs_concurrent_module/utils/locks/common.h+3-0File content is under review, please try again later
Mjs_concurrent_module/utils/test/BUILD.gn+17-0File content is under review, please try again later
Mjs_concurrent_module/utils/test/test_locks.cpp+75-11File content is under review, please try again later
Mjs_concurrent_module/worker/BUILD.gn+30-2File content is under review, please try again later
Mjs_concurrent_module/worker/test/BUILD.gn+28-1File content is under review, please try again later
Mjs_concurrent_module/worker/test/test_worker.cpp+22-12File content is under review, please try again later
Mjs_concurrent_module/worker/worker.cpp+1-1File content is under review, please try again later
Mjs_sys_module/console/BUILD.gn+19-2File content is under review, please try again later
Mjs_sys_module/console/log.h+14-0File content is under review, please try again later
Mjs_sys_module/console/test/BUILD.gn+21-0File content is under review, please try again later
Mjs_sys_module/console/test/test_ark.cpp+4-0File content is under review, please try again later
Mjs_sys_module/process/BUILD.gn+28-0File content is under review, please try again later
Mjs_sys_module/process/js_childprocess.cpp+14-0File content is under review, please try again later
Mjs_sys_module/process/js_process.cpp+595-594File content is under review, please try again later
Mjs_sys_module/test/BUILD.gn+17-0File content is under review, please try again later
Mjs_sys_module/timer/BUILD.gn+39-2File content is under review, please try again later
Mjs_sys_module/timer/test/BUILD.gn+17-0File content is under review, please try again later
Mjs_util_module/util/BUILD.gn+16-0File content is under review, please try again later
Mjs_util_module/util/test/BUILD.gn+19-0File content is under review, please try again later
Mtools/log.h+14-0File content is under review, please try again later