1484543d1Sopenharmony_ci/* 2484543d1Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3484543d1Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4484543d1Sopenharmony_ci * you may not use this file except in compliance with the License. 5484543d1Sopenharmony_ci * You may obtain a copy of the License at 6484543d1Sopenharmony_ci * 7484543d1Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8484543d1Sopenharmony_ci * 9484543d1Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10484543d1Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11484543d1Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12484543d1Sopenharmony_ci * See the License for the specific language governing permissions and 13484543d1Sopenharmony_ci * limitations under the License. 14484543d1Sopenharmony_ci */ 15484543d1Sopenharmony_ci#include <array> 16484543d1Sopenharmony_ci#include <gtest/gtest.h> 17484543d1Sopenharmony_ci#include <regex> 18484543d1Sopenharmony_ci#include <thread> 19484543d1Sopenharmony_ci#include "c/ffrt_dump.h" 20484543d1Sopenharmony_ci#include "dfx/log/ffrt_log_api.h" 21484543d1Sopenharmony_ci#include "ffrt_inner.h" 22484543d1Sopenharmony_ci#include "securec.h" 23484543d1Sopenharmony_ci#include "util.h" 24484543d1Sopenharmony_ci#include "../common.h" 25484543d1Sopenharmony_ci 26484543d1Sopenharmony_cistatic const int BUFFER_SIZE = 120000; 27484543d1Sopenharmony_cistatic const int SLEEP_MS = 3 * 1000; 28484543d1Sopenharmony_cistatic const int TASK_NUM_9 = 9; 29484543d1Sopenharmony_cistatic const int TASK_NUM_10 = 10; 30484543d1Sopenharmony_cistatic const int TASK_NUM_29 = 29; 31484543d1Sopenharmony_cistatic const int TASK_NUM_40 = 40; 32484543d1Sopenharmony_cistatic const int TASK_NUM_600 = 600; 33484543d1Sopenharmony_cistatic const int TASK_NUM_610 = 610; 34484543d1Sopenharmony_ci 35484543d1Sopenharmony_ciusing namespace std; 36484543d1Sopenharmony_ciusing namespace ffrt; 37484543d1Sopenharmony_ciusing namespace testing; 38484543d1Sopenharmony_ci#ifdef HWTEST_TESTING_EXT_ENABLE 39484543d1Sopenharmony_ciusing namespace testing::ext; 40484543d1Sopenharmony_ci#endif 41484543d1Sopenharmony_ci 42484543d1Sopenharmony_ciclass QueueDumpTest : public testing::Test { 43484543d1Sopenharmony_ciprotected: 44484543d1Sopenharmony_ci static void SetUpTestCase() 45484543d1Sopenharmony_ci { 46484543d1Sopenharmony_ci } 47484543d1Sopenharmony_ci 48484543d1Sopenharmony_ci static void TearDownTestCase() 49484543d1Sopenharmony_ci { 50484543d1Sopenharmony_ci } 51484543d1Sopenharmony_ci 52484543d1Sopenharmony_ci virtual void SetUp() 53484543d1Sopenharmony_ci { 54484543d1Sopenharmony_ci } 55484543d1Sopenharmony_ci 56484543d1Sopenharmony_ci virtual void TearDown() 57484543d1Sopenharmony_ci { 58484543d1Sopenharmony_ci } 59484543d1Sopenharmony_ci}; 60484543d1Sopenharmony_ci 61484543d1Sopenharmony_ciint g_cnt = 0; 62484543d1Sopenharmony_cistd::function<void()>&& basicFunc = []() { g_cnt += 1; }; 63484543d1Sopenharmony_cistd::function<void()>&& sleepFunc = []() { std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MS)); }; 64484543d1Sopenharmony_ci 65484543d1Sopenharmony_cistatic void QueueDumpTask1Test(ffrt_queue_t& queue_handle, char* buf) 66484543d1Sopenharmony_ci{ 67484543d1Sopenharmony_ci ffrt_task_attr_t task_attr; 68484543d1Sopenharmony_ci (void)ffrt_task_attr_init(&task_attr); 69484543d1Sopenharmony_ci ffrt_task_attr_set_name(&task_attr, "task1"); 70484543d1Sopenharmony_ci for (int i = 0; i < TASK_NUM_9; ++i) { 71484543d1Sopenharmony_ci ffrt_queue_submit(queue_handle, create_function_wrapper(basicFunc, ffrt_function_kind_queue), &task_attr); 72484543d1Sopenharmony_ci } 73484543d1Sopenharmony_ci ffrt_task_handle_t t = 74484543d1Sopenharmony_ci ffrt_queue_submit_h(queue_handle, create_function_wrapper(basicFunc, ffrt_function_kind_queue), &task_attr); 75484543d1Sopenharmony_ci ffrt_queue_wait(t); 76484543d1Sopenharmony_ci EXPECT_EQ(g_cnt, TASK_NUM_10); 77484543d1Sopenharmony_ci // dump队列信息 78484543d1Sopenharmony_ci int ret = ffrt_queue_dump(queue_handle, "eventHandler1", buf, BUFFER_SIZE, true); 79484543d1Sopenharmony_ci EXPECT_TRUE(ret > 0); 80484543d1Sopenharmony_ci // 预期dump信息: 81484543d1Sopenharmony_ci // 1.tag为eventHandler1 82484543d1Sopenharmony_ci // 2.当前执行任务名称为task1 83484543d1Sopenharmony_ci // 3.有10条历史执行的任务,且任务名称都是task1 84484543d1Sopenharmony_ci // 4.无剩余未执行的任务 85484543d1Sopenharmony_ci std::string str(buf); 86484543d1Sopenharmony_ci std::regex pattern(R"(eventHandler1 Current Running: start at (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), Event \{ send thread = (\d+), send time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), handle time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), task name = (.*task1.*) \} 87484543d1Sopenharmony_cieventHandler1 History event queue information: 88484543d1Sopenharmony_ci(eventHandler1 No. (\d+) : Event \{ send thread = (\d+), send time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), handle time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), trigger time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), complete time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), task name = (.*task1.*) \} 89484543d1Sopenharmony_ci){10}eventHandler1 Immediate priority event queue information: 90484543d1Sopenharmony_cieventHandler1 Total size of Immediate events : 0 91484543d1Sopenharmony_cieventHandler1 High priority event queue information: 92484543d1Sopenharmony_cieventHandler1 Total size of High events : 0 93484543d1Sopenharmony_cieventHandler1 Low priority event queue information: 94484543d1Sopenharmony_cieventHandler1 Total size of Low events : 0 95484543d1Sopenharmony_cieventHandler1 Idle priority event queue information: 96484543d1Sopenharmony_cieventHandler1 Total size of Idle events : 0 97484543d1Sopenharmony_cieventHandler1 Vip priority event queue information: 98484543d1Sopenharmony_cieventHandler1 Total size of Vip events : 0 99484543d1Sopenharmony_cieventHandler1 Total event size : 0 100484543d1Sopenharmony_ci)"); 101484543d1Sopenharmony_ci EXPECT_TRUE(std::regex_match(str, pattern)); 102484543d1Sopenharmony_ci ffrt_task_handle_destroy(t); 103484543d1Sopenharmony_ci ffrt_task_attr_destroy(&task_attr); 104484543d1Sopenharmony_ci} 105484543d1Sopenharmony_ci 106484543d1Sopenharmony_cistatic void QueueDumpTask2Test(ffrt_queue_t& queue_handle, char* buf) 107484543d1Sopenharmony_ci{ 108484543d1Sopenharmony_ci ffrt_task_attr_t task_attr; 109484543d1Sopenharmony_ci (void)ffrt_task_attr_init(&task_attr); 110484543d1Sopenharmony_ci ffrt_task_attr_set_name(&task_attr, "task2"); 111484543d1Sopenharmony_ci for (int i = 0; i < TASK_NUM_29; ++i) { 112484543d1Sopenharmony_ci ffrt_queue_submit(queue_handle, create_function_wrapper(basicFunc, ffrt_function_kind_queue), &task_attr); 113484543d1Sopenharmony_ci } 114484543d1Sopenharmony_ci ffrt_task_handle_t t = 115484543d1Sopenharmony_ci ffrt_queue_submit_h(queue_handle, create_function_wrapper(basicFunc, ffrt_function_kind_queue), &task_attr); 116484543d1Sopenharmony_ci ffrt_queue_wait(t); 117484543d1Sopenharmony_ci EXPECT_EQ(g_cnt, TASK_NUM_40); 118484543d1Sopenharmony_ci // dump队列信息 119484543d1Sopenharmony_ci memset_s(buf, sizeof(char) * BUFFER_SIZE, 0, sizeof(char) * BUFFER_SIZE); 120484543d1Sopenharmony_ci int ret = ffrt_queue_dump(queue_handle, "eventHandler2", buf, BUFFER_SIZE, true); 121484543d1Sopenharmony_ci EXPECT_TRUE(ret > 0); 122484543d1Sopenharmony_ci // 预期dump信息: 123484543d1Sopenharmony_ci // 1.tag为eventHandler2 124484543d1Sopenharmony_ci // 2.当前执行任务名称为task2 125484543d1Sopenharmony_ci // 3.有32条历史执行的任务 126484543d1Sopenharmony_ci // 4.无剩余未执行的任务 127484543d1Sopenharmony_ci std::string str(buf); 128484543d1Sopenharmony_ci std::regex pattern(R"(eventHandler2 Current Running: start at (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), Event \{ send thread = (\d+), send time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), handle time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), task name = (.*task2.*) \} 129484543d1Sopenharmony_cieventHandler2 History event queue information: 130484543d1Sopenharmony_ci(eventHandler2 No. (\d+) : Event \{ send thread = (\d+), send time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), handle time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), trigger time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), complete time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), task name = ([^\}]*?) \} 131484543d1Sopenharmony_ci){32}eventHandler2 Immediate priority event queue information: 132484543d1Sopenharmony_cieventHandler2 Total size of Immediate events : 0 133484543d1Sopenharmony_cieventHandler2 High priority event queue information: 134484543d1Sopenharmony_cieventHandler2 Total size of High events : 0 135484543d1Sopenharmony_cieventHandler2 Low priority event queue information: 136484543d1Sopenharmony_cieventHandler2 Total size of Low events : 0 137484543d1Sopenharmony_cieventHandler2 Idle priority event queue information: 138484543d1Sopenharmony_cieventHandler2 Total size of Idle events : 0 139484543d1Sopenharmony_cieventHandler2 Vip priority event queue information: 140484543d1Sopenharmony_cieventHandler2 Total size of Vip events : 0 141484543d1Sopenharmony_cieventHandler2 Total event size : 0 142484543d1Sopenharmony_ci)"); 143484543d1Sopenharmony_ci EXPECT_TRUE(std::regex_match(str, pattern)); 144484543d1Sopenharmony_ci ffrt_task_handle_destroy(t); 145484543d1Sopenharmony_ci ffrt_task_attr_destroy(&task_attr); 146484543d1Sopenharmony_ci} 147484543d1Sopenharmony_ci 148484543d1Sopenharmony_cistatic void QueueDumpTask3Test(ffrt_queue_t& queue_handle, char* buf) 149484543d1Sopenharmony_ci{ 150484543d1Sopenharmony_ci ffrt_task_attr_t task_attr; 151484543d1Sopenharmony_ci (void)ffrt_task_attr_init(&task_attr); 152484543d1Sopenharmony_ci ffrt_task_attr_set_name(&task_attr, "task3"); 153484543d1Sopenharmony_ci ffrt_queue_submit(queue_handle, create_function_wrapper(sleepFunc, ffrt_function_kind_queue), &task_attr); 154484543d1Sopenharmony_ci // dump队列信息 155484543d1Sopenharmony_ci memset_s(buf, sizeof(char) * BUFFER_SIZE, 0, sizeof(char) * BUFFER_SIZE); 156484543d1Sopenharmony_ci int ret = ffrt_queue_dump(queue_handle, "eventHandler3", buf, BUFFER_SIZE, true); 157484543d1Sopenharmony_ci EXPECT_TRUE(ret > 0); 158484543d1Sopenharmony_ci // 预期dump信息: 159484543d1Sopenharmony_ci // 1.tag为eventHandler3 160484543d1Sopenharmony_ci // 2.当前执行任务名称为task3 161484543d1Sopenharmony_ci // 3.有32条历史执行的任务 162484543d1Sopenharmony_ci // 4.无剩余未执行的任务 163484543d1Sopenharmony_ci std::string str(buf); 164484543d1Sopenharmony_ci std::regex pattern(R"(eventHandler3 Current Running: start at (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), Event \{ send thread = (\d+), send time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), handle time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), task name = (.*task3.*) \} 165484543d1Sopenharmony_cieventHandler3 History event queue information: 166484543d1Sopenharmony_ci(eventHandler3 No. (\d+) : Event \{ send thread = (\d+), send time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), handle time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), trigger time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), complete time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), task name = ([^\}]*?) \} 167484543d1Sopenharmony_ci){32}eventHandler3 Immediate priority event queue information: 168484543d1Sopenharmony_cieventHandler3 Total size of Immediate events : 0 169484543d1Sopenharmony_cieventHandler3 High priority event queue information: 170484543d1Sopenharmony_cieventHandler3 Total size of High events : 0 171484543d1Sopenharmony_cieventHandler3 Low priority event queue information: 172484543d1Sopenharmony_cieventHandler3 Total size of Low events : 0 173484543d1Sopenharmony_cieventHandler3 Idle priority event queue information: 174484543d1Sopenharmony_cieventHandler3 Total size of Idle events : 0 175484543d1Sopenharmony_cieventHandler3 Vip priority event queue information: 176484543d1Sopenharmony_cieventHandler3 Total size of Vip events : 0 177484543d1Sopenharmony_cieventHandler3 Total event size : 0 178484543d1Sopenharmony_ci)"); 179484543d1Sopenharmony_ci EXPECT_TRUE(std::regex_match(str, pattern)); 180484543d1Sopenharmony_ci ffrt_task_attr_destroy(&task_attr); 181484543d1Sopenharmony_ci} 182484543d1Sopenharmony_ci 183484543d1Sopenharmony_cistatic void QueueDumpPriorityTest(ffrt_queue_t& queue_handle, ffrt_task_attr_t& task_attr, 184484543d1Sopenharmony_ci ffrt_inner_queue_priority_t priority, const char* name) 185484543d1Sopenharmony_ci{ 186484543d1Sopenharmony_ci (void)ffrt_task_attr_init(&task_attr); 187484543d1Sopenharmony_ci ffrt_task_attr_set_queue_priority(&task_attr, static_cast<ffrt_queue_priority_t>(priority)); 188484543d1Sopenharmony_ci ffrt_task_attr_set_name(&task_attr, name); 189484543d1Sopenharmony_ci for (int i = 0; i < TASK_NUM_10; ++i) { 190484543d1Sopenharmony_ci ffrt_queue_submit(queue_handle, create_function_wrapper(basicFunc, ffrt_function_kind_queue), &task_attr); 191484543d1Sopenharmony_ci } 192484543d1Sopenharmony_ci} 193484543d1Sopenharmony_ci 194484543d1Sopenharmony_cistatic void QueueDumpPriorityTest(ffrt_queue_t& queue_handle, char* buf) 195484543d1Sopenharmony_ci{ 196484543d1Sopenharmony_ci ffrt_task_attr_t task_attr4; 197484543d1Sopenharmony_ci QueueDumpPriorityTest(queue_handle, task_attr4, ffrt_inner_queue_priority_immediate, "task4"); 198484543d1Sopenharmony_ci ffrt_task_attr_t task_attr5; 199484543d1Sopenharmony_ci QueueDumpPriorityTest(queue_handle, task_attr5, ffrt_inner_queue_priority_high, "task5"); 200484543d1Sopenharmony_ci ffrt_task_attr_t task_attr6; 201484543d1Sopenharmony_ci QueueDumpPriorityTest(queue_handle, task_attr6, ffrt_inner_queue_priority_low, "task6"); 202484543d1Sopenharmony_ci ffrt_task_attr_t task_attr7; 203484543d1Sopenharmony_ci QueueDumpPriorityTest(queue_handle, task_attr7, ffrt_inner_queue_priority_idle, "task7"); 204484543d1Sopenharmony_ci ffrt_task_attr_t task_attr8; 205484543d1Sopenharmony_ci QueueDumpPriorityTest(queue_handle, task_attr8, ffrt_inner_queue_priority_vip, "task8"); 206484543d1Sopenharmony_ci memset_s(buf, sizeof(char) * BUFFER_SIZE, 0, sizeof(char) * BUFFER_SIZE); 207484543d1Sopenharmony_ci int ret = ffrt_queue_dump(queue_handle, "eventHandler4", buf, BUFFER_SIZE, true); 208484543d1Sopenharmony_ci EXPECT_TRUE(ret > 0); 209484543d1Sopenharmony_ci // 预期dump信息: 210484543d1Sopenharmony_ci // 1.tag为eventHandler4 211484543d1Sopenharmony_ci // 2.当前执行任务名称为task3 212484543d1Sopenharmony_ci // 3.有32条历史执行的任务 213484543d1Sopenharmony_ci // 4.5种优先级各有10条任务 214484543d1Sopenharmony_ci std::string str(buf); 215484543d1Sopenharmony_ci std::regex pattern(R"(eventHandler4 Current Running: start at (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), Event \{ send thread = (\d+), send time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), handle time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), task name = (.*task3.*) \} 216484543d1Sopenharmony_cieventHandler4 History event queue information: 217484543d1Sopenharmony_ci(eventHandler4 No. (\d+) : Event \{ send thread = (\d+), send time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), handle time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), trigger time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), complete time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), task name = ([^\}]*?) \} 218484543d1Sopenharmony_ci){32}eventHandler4 Immediate priority event queue information: 219484543d1Sopenharmony_ci(eventHandler4 No. (\d+) : Event \{ send thread = (\d+), send time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), handle time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), task name = (.*task4.*) \} 220484543d1Sopenharmony_ci){10}eventHandler4 Total size of Immediate events : 10 221484543d1Sopenharmony_cieventHandler4 High priority event queue information: 222484543d1Sopenharmony_ci(eventHandler4 No. (\d+) : Event \{ send thread = (\d+), send time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), handle time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), task name = (.*task5.*) \} 223484543d1Sopenharmony_ci){10}eventHandler4 Total size of High events : 10 224484543d1Sopenharmony_cieventHandler4 Low priority event queue information: 225484543d1Sopenharmony_ci(eventHandler4 No. (\d+) : Event \{ send thread = (\d+), send time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), handle time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), task name = (.*task6.*) \} 226484543d1Sopenharmony_ci){10}eventHandler4 Total size of Low events : 10 227484543d1Sopenharmony_cieventHandler4 Idle priority event queue information: 228484543d1Sopenharmony_ci(eventHandler4 No. (\d+) : Event \{ send thread = (\d+), send time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), handle time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), task name = (.*task7.*) \} 229484543d1Sopenharmony_ci){10}eventHandler4 Total size of Idle events : 10 230484543d1Sopenharmony_cieventHandler4 Vip priority event queue information: 231484543d1Sopenharmony_ci(eventHandler4 No. (\d+) : Event \{ send thread = (\d+), send time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), handle time = (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}), task name = (.*task8.*) \} 232484543d1Sopenharmony_ci){10}eventHandler4 Total size of Vip events : 10 233484543d1Sopenharmony_cieventHandler4 Total event size : 50 234484543d1Sopenharmony_ci)"); 235484543d1Sopenharmony_ci EXPECT_TRUE(std::regex_match(str, pattern)); 236484543d1Sopenharmony_ci ffrt_task_attr_destroy(&task_attr4); 237484543d1Sopenharmony_ci ffrt_task_attr_destroy(&task_attr5); 238484543d1Sopenharmony_ci ffrt_task_attr_destroy(&task_attr6); 239484543d1Sopenharmony_ci ffrt_task_attr_destroy(&task_attr7); 240484543d1Sopenharmony_ci ffrt_task_attr_destroy(&task_attr8); 241484543d1Sopenharmony_ci} 242484543d1Sopenharmony_ci 243484543d1Sopenharmony_cistatic void QueueDumpMaxDumpSizeTest(ffrt_queue_t& queue_handle, char* buf) 244484543d1Sopenharmony_ci{ 245484543d1Sopenharmony_ci ffrt_task_attr_t task_attr; 246484543d1Sopenharmony_ci (void)ffrt_task_attr_init(&task_attr); 247484543d1Sopenharmony_ci ffrt_task_attr_set_queue_priority(&task_attr, static_cast<ffrt_queue_priority_t>(ffrt_inner_queue_priority_high)); 248484543d1Sopenharmony_ci ffrt_task_attr_set_name(&task_attr, "task9"); 249484543d1Sopenharmony_ci for (int i = 0; i < TASK_NUM_600; ++i) { 250484543d1Sopenharmony_ci ffrt_queue_submit(queue_handle, create_function_wrapper(basicFunc, ffrt_function_kind_queue), &task_attr); 251484543d1Sopenharmony_ci } 252484543d1Sopenharmony_ci // dump队列信息 253484543d1Sopenharmony_ci memset_s(buf, sizeof(char) * BUFFER_SIZE, 0, sizeof(char) * BUFFER_SIZE); 254484543d1Sopenharmony_ci int ret = ffrt_queue_dump(queue_handle, "eventHandler9", buf, BUFFER_SIZE, false); 255484543d1Sopenharmony_ci EXPECT_TRUE(ret > 0); 256484543d1Sopenharmony_ci ffrt_task_attr_destroy(&task_attr); 257484543d1Sopenharmony_ci} 258484543d1Sopenharmony_ci 259484543d1Sopenharmony_ci/** 260484543d1Sopenharmony_ci * @brief queue dump interface user cases 261484543d1Sopenharmony_ci */ 262484543d1Sopenharmony_ciHWTEST_F(QueueDumpTest, queue_dump_case, TestSize.Level1) 263484543d1Sopenharmony_ci{ 264484543d1Sopenharmony_ci // 创建类型为ffrt_queue_eventhandler_adapter的队列 265484543d1Sopenharmony_ci ffrt_queue_attr_t queue_attr; 266484543d1Sopenharmony_ci (void)ffrt_queue_attr_init(&queue_attr); 267484543d1Sopenharmony_ci ffrt_queue_attr_set_max_concurrency(&queue_attr, 1); 268484543d1Sopenharmony_ci ffrt_queue_t queue_handle = ffrt_queue_create(static_cast<ffrt_queue_type_t>(ffrt_queue_eventhandler_adapter), 269484543d1Sopenharmony_ci "queue_dump", &queue_attr); 270484543d1Sopenharmony_ci char* buf = new char[BUFFER_SIZE]; 271484543d1Sopenharmony_ci // 提交10个任务并等待任务执行完成(任务名称:task1) 272484543d1Sopenharmony_ci QueueDumpTask1Test(queue_handle, buf); 273484543d1Sopenharmony_ci // 提交30个任务并等待任务执行完成(任务名称:task2) 274484543d1Sopenharmony_ci QueueDumpTask2Test(queue_handle, buf); 275484543d1Sopenharmony_ci // 提交1个睡眠3s的任务(任务名称:task3) 276484543d1Sopenharmony_ci QueueDumpTask3Test(queue_handle, buf); 277484543d1Sopenharmony_ci // 5种优先级各提交10个任务 278484543d1Sopenharmony_ci QueueDumpPriorityTest(queue_handle, buf); 279484543d1Sopenharmony_ci // 提交600个优先级为ffrt_inner_queue_priority_high的任务 280484543d1Sopenharmony_ci QueueDumpMaxDumpSizeTest(queue_handle, buf); 281484543d1Sopenharmony_ci // 验证ffrt_queue_size_dump结果 282484543d1Sopenharmony_ci EXPECT_EQ(ffrt_queue_size_dump(queue_handle, ffrt_inner_queue_priority_immediate), TASK_NUM_10); 283484543d1Sopenharmony_ci EXPECT_EQ(ffrt_queue_size_dump(queue_handle, ffrt_inner_queue_priority_high), TASK_NUM_610); 284484543d1Sopenharmony_ci EXPECT_EQ(ffrt_queue_size_dump(queue_handle, ffrt_inner_queue_priority_low), TASK_NUM_10); 285484543d1Sopenharmony_ci EXPECT_EQ(ffrt_queue_size_dump(queue_handle, ffrt_inner_queue_priority_idle), TASK_NUM_10); 286484543d1Sopenharmony_ci EXPECT_EQ(ffrt_queue_size_dump(queue_handle, ffrt_inner_queue_priority_vip), TASK_NUM_10); 287484543d1Sopenharmony_ci 288484543d1Sopenharmony_ci delete[] buf; 289484543d1Sopenharmony_ci ffrt_queue_destroy(queue_handle); 290484543d1Sopenharmony_ci ffrt_queue_attr_destroy(&queue_attr); 291484543d1Sopenharmony_ci} 292