Closed
Support linux host UT for ets_utils #2691
wang_zhaoyongAdd on Oct 18Closed at 28 days ago
Support linux host UT for ets_utils #2691
Closed
Total: 47 files changed+2304-1803
| @@ -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_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/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_H | 16 | #ifndef JS_CONCURRENT_MODULE_TASKPOOL_TASK_H |
| 17 | #define JS_CONCURRENT_MODULE_TASKPOOL_TASK_H | 17 | #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_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/test/BUILD.gn+17-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 | ||
| 2341 | HWTEST_F(NativeEngineTest, TaskpoolTest136, testing::ext::TestSize.Level0) | 2350 | HWTEST_F(NativeEngineTest, TaskpoolTest136, testing::ext::TestSize.Level0) |
Mjs_concurrent_module/utils/test/test_locks.cpp+73-12File content is under review, please try again later
Mjs_concurrent_module/worker/test/test_worker.cpp+10-4File content is under review, please try again later