1 /*
2 * Copyright (c) 2021 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
16 #include "main_ability.h"
17 #include "hilog_wrapper.h"
18 #include "test_utils.h"
19 #include <algorithm>
20 #include <condition_variable>
21 #include <chrono>
22 #include <functional>
23
24 namespace OHOS {
25 namespace AppExecFwk {
26 using namespace OHOS::EventFwk;
27 using namespace OHOS::STtools;
28 namespace {
29 int terminated_task_num = 0;
30 std::condition_variable cv;
31 std::mutex cv_mutex;
32 constexpr int testTaskCount = 3;
33 std::string innerSyncBarrierId = "innerSyncBarrierId";
34 std::string innerAsyncBarrierId = "innerAsyncBarrierId";
35 std::string innerGroupWaitId = "innerGroupWaitId";
36 std::string innerGroupNotifyId = "innerGroupNotifyId";
37 std::string outerSyncBarrierId = "outerSyncBarrierId";
38 std::string outerAsyncBarrierId = "outerAsyncBarrierId";
39 std::string outerGroupWaitId = "outerGroupWaitId";
40 std::string outerGroupNotifyId = "outerGroupNotifyId";
41 std::string delimiter = "_";
42 std::string innerDelimiter = "-";
43 std::string task_execution_sequence = delimiter;
44 std::vector<std::shared_ptr<AppExecFwk::TaskDispatcher>> allDispatchers;
45 std::mutex dispatcher_mutex;
46 constexpr int numZero = 0;
47 constexpr int numOne = 1;
48 constexpr int numTwo = 2;
49 constexpr int numThree = 3;
50 } // namespace
51
Wait(const int task_num)52 bool Wait(const int task_num)
53 {
54 HILOG_INFO("-- -- -- -- -- --MainAbility::Wait");
55 std::unique_lock<std::mutex> ulock(cv_mutex);
56 using namespace std::chrono_literals;
57 bool result = cv.wait_for(ulock, 5000ms, [task_num] { return terminated_task_num == task_num; });
58 if (result) {
59 allDispatchers.clear();
60 }
61 HILOG_INFO("-- -- -- -- -- --MainAbility::Wait result:%{public}d", result);
62 return result;
63 }
64
TestTask(const std::string & task_id)65 void TestTask(const std::string &task_id)
66 {
67 {
68 std::lock_guard<std::mutex> lock(cv_mutex);
69 terminated_task_num++;
70 task_execution_sequence += task_id + delimiter;
71 }
72 HILOG_INFO("-- -- -- -- -- --MainAbility::TestTask: %{public}d %{public}s", terminated_task_num, task_id.c_str());
73 TestUtils::PublishEvent(g_EVENT_RESP_FIRST_B, terminated_task_num, task_execution_sequence);
74 cv.notify_one();
75 }
76
Reset()77 void Reset()
78 {
79 HILOG_INFO("-- -- -- -- -- --MainAbility::Reset");
80 terminated_task_num = 0;
81 task_execution_sequence = delimiter;
82 allDispatchers.clear();
83 }
84
IsAscend(const std::vector<size_t> & vec)85 bool IsAscend(const std::vector<size_t> &vec)
86 {
87 HILOG_INFO("-- -- -- -- -- --MainAbility::IsAscend begin");
88 auto pos = std::adjacent_find(std::begin(vec), std::end(vec), std::greater<size_t>());
89 return pos == std::end(vec);
90 HILOG_INFO("-- -- -- -- -- --MainAbility::IsAscend end");
91 }
92
OuterTaskExecuted(TestSetting setting)93 bool OuterTaskExecuted(TestSetting setting)
94 {
95 HILOG_INFO("-- -- -- -- -- --MainAbility::OuterTaskExecuted begin");
96 std::string expectedTaskId;
97 bool executed = true;
98 for (int i = 0; i < testTaskCount; i++) {
99 expectedTaskId = delimiter + std::to_string(i) + delimiter;
100 executed = executed && (task_execution_sequence.find(expectedTaskId) != string::npos);
101 if (!executed) {
102 return executed;
103 }
104 }
105 if (setting.sync_barrier) {
106 expectedTaskId = delimiter + outerSyncBarrierId + delimiter;
107 executed = executed && (task_execution_sequence.find(expectedTaskId) != string::npos);
108 }
109 if (setting.async_barrier) {
110 expectedTaskId = delimiter + outerAsyncBarrierId + delimiter;
111 executed = executed && (task_execution_sequence.find(expectedTaskId) != string::npos);
112 }
113 if (setting.group_notify) {
114 expectedTaskId = delimiter + outerGroupNotifyId + delimiter;
115 executed = executed && (task_execution_sequence.find(expectedTaskId) != string::npos);
116 }
117 HILOG_INFO("-- -- -- -- -- --MainAbility::OuterTaskExecuted end");
118 return executed;
119 }
120
InnerTaskExecuted(TestSetting setting)121 bool InnerTaskExecuted(TestSetting setting)
122 {
123 HILOG_INFO("-- -- -- -- -- --MainAbility::InnerTaskExecuted begin");
124 std::string expectedTaskId;
125 bool executed = true;
126 for (int i = 0; i < testTaskCount; i++) {
127 for (int j = 0; j < testTaskCount; j++) {
128 expectedTaskId = delimiter + std::to_string(i) + innerDelimiter + std::to_string(j) + delimiter;
129 executed = executed && (task_execution_sequence.find(expectedTaskId) != string::npos);
130 if (!executed) {
131 return executed;
132 }
133 }
134 }
135 if (setting.sync_barrier) {
136 expectedTaskId = delimiter + innerSyncBarrierId + delimiter;
137 executed = executed && (task_execution_sequence.find(expectedTaskId) != string::npos);
138 }
139 if (setting.async_barrier) {
140 expectedTaskId = delimiter + innerAsyncBarrierId + delimiter;
141 executed = executed && (task_execution_sequence.find(expectedTaskId) != string::npos);
142 }
143 if (setting.group_notify) {
144 expectedTaskId = delimiter + innerGroupNotifyId + delimiter;
145 executed = executed && (task_execution_sequence.find(expectedTaskId) != string::npos);
146 }
147 HILOG_INFO("-- -- -- -- -- --MainAbility::InnerTaskExecuted end");
148 return executed;
149 }
150
setTaskIndex(std::string taskId,std::vector<size_t> & taskIndex)151 void setTaskIndex(std::string taskId, std::vector<size_t> &taskIndex)
152 {
153 HILOG_INFO("-- -- -- -- -- --MainAbility::setTaskIndex begin");
154 std::size_t indx = task_execution_sequence.find(taskId);
155 if (indx != string::npos) {
156 taskIndex.push_back(indx);
157 }
158 HILOG_INFO("-- -- -- -- -- --MainAbility::setTaskIndex end");
159 }
160
GetTaskIndex(std::vector<size_t> & outerTaskIndex,std::vector<std::vector<size_t>> & innerTaskIndex,const int outerCnt=testTaskCount,const int innerCnt=testTaskCount)161 void GetTaskIndex(std::vector<size_t> &outerTaskIndex, std::vector<std::vector<size_t>> &innerTaskIndex,
162 const int outerCnt = testTaskCount, const int innerCnt = testTaskCount)
163 {
164 HILOG_INFO("-- -- -- -- -- --MainAbility::GetTaskIndex begin");
165 std::string outerTaskId;
166 std::string innerTaskId;
167 outerTaskIndex.resize(outerCnt);
168 HILOG_INFO("-- -- -- -- -- --MainAbility::GetTaskIndex outersize : %{public}zu", outerTaskIndex.size());
169 innerTaskIndex.resize(outerCnt);
170 HILOG_INFO("-- -- -- -- -- --MainAbility::GetTaskIndex innersize : %{public}zu", innerTaskIndex.size());
171 for (auto &inner : innerTaskIndex) {
172 inner.resize(innerCnt);
173 HILOG_INFO("-- -- -- -- -- --MainAbility::GetTaskIndex inner :%{public}zu", inner.size());
174 }
175 HILOG_INFO("-- -- -- -- -- --MainAbility::GetTaskIndex mid1");
176 for (int i = 0; i < outerCnt; i++) {
177 outerTaskId = delimiter + std::to_string(i) + delimiter;
178 HILOG_INFO("-- -- -- -- -- --MainAbility::GetTaskIndex mid2");
179 outerTaskIndex[i] = task_execution_sequence.find(outerTaskId);
180 HILOG_INFO("-- -- -- -- -- --MainAbility::GetTaskIndex mid3");
181 for (int j = 0; j < innerCnt; j++) {
182 innerTaskId = delimiter + std::to_string(i) + innerDelimiter + std::to_string(j) + delimiter;
183 HILOG_INFO("-- -- -- -- -- --MainAbility::GetTaskIndex mid4");
184 innerTaskIndex[i][j] = task_execution_sequence.find(innerTaskId);
185 HILOG_INFO("-- -- -- -- -- --MainAbility::GetTaskIndex mid5");
186 }
187 std::string taskId = innerSyncBarrierId + std::to_string(i);
188 setTaskIndex(taskId, innerTaskIndex[i]);
189 taskId = innerAsyncBarrierId + std::to_string(i);
190 setTaskIndex(taskId, innerTaskIndex[i]);
191 taskId = innerGroupNotifyId + std::to_string(i);
192 setTaskIndex(taskId, innerTaskIndex[i]);
193 }
194 setTaskIndex(outerSyncBarrierId, outerTaskIndex);
195 setTaskIndex(outerAsyncBarrierId, outerTaskIndex);
196 setTaskIndex(outerGroupNotifyId, outerTaskIndex);
197 HILOG_INFO("-- -- -- -- -- --MainAbility:: end");
198 }
199
Init(const std::shared_ptr<AbilityInfo> & abilityInfo,const std::shared_ptr<OHOSApplication> & application,std::shared_ptr<AbilityHandler> & handler,const sptr<IRemoteObject> & token)200 void MainAbility::Init(const std::shared_ptr<AbilityInfo> &abilityInfo,
201 const std::shared_ptr<OHOSApplication> &application, std::shared_ptr<AbilityHandler> &handler,
202 const sptr<IRemoteObject> &token)
203 {
204 HILOG_INFO("MainAbility::Init");
205 Ability::Init(abilityInfo, application, handler, token);
206 }
207
~MainAbility()208 MainAbility::~MainAbility()
209 {
210 CommonEventManager::UnSubscribeCommonEvent(subscriber_);
211 }
212
OnStart(const Want & want)213 void MainAbility::OnStart(const Want &want)
214 {
215 HILOG_INFO("MainAbility::onStart");
216 SubscribeEvent();
217 Ability::OnStart(want);
218 TestUtils::PublishEvent(g_EVENT_RESP_FIRST_B, Ability::GetState(), "onStart");
219 }
220
OnStop()221 void MainAbility::OnStop()
222 {
223 HILOG_INFO("MainAbility::OnStop");
224 Ability::OnStop();
225 CommonEventManager::UnSubscribeCommonEvent(subscriber_);
226 TestUtils::PublishEvent(g_EVENT_RESP_FIRST_B, Ability::GetState(), "OnStop");
227 }
228
OnActive()229 void MainAbility::OnActive()
230 {
231 HILOG_INFO("MainAbility::OnActive");
232 Ability::OnActive();
233 TestUtils::PublishEvent(g_EVENT_RESP_FIRST_B, 0, "OnActive");
234 }
235
OnInactive()236 void MainAbility::OnInactive()
237 {
238 HILOG_INFO("MainAbility::OnInactive");
239 Ability::OnInactive();
240 TestUtils::PublishEvent(g_EVENT_RESP_FIRST_B, Ability::GetState(), "OnInactive");
241 }
242
OnBackground()243 void MainAbility::OnBackground()
244 {
245 HILOG_INFO("MainAbility::OnBackground");
246 Ability::OnBackground();
247 TestUtils::PublishEvent(g_EVENT_RESP_FIRST_B, Ability::GetState(), "OnBackground");
248 }
249
OnForeground(const Want & want)250 void MainAbility::OnForeground(const Want &want)
251 {
252 HILOG_INFO("MainAbility::OnForeground");
253 Ability::OnForeground(want);
254 TestUtils::PublishEvent(g_EVENT_RESP_FIRST_B, Ability::GetState(), "OnForeground");
255 }
256
SubscribeEvent()257 void MainAbility::SubscribeEvent()
258 {
259 std::vector<std::string> eventList = {
260 g_EVENT_REQU_FIRST_B,
261 };
262 MatchingSkills matchingSkills;
263 for (const auto &e : eventList) {
264 matchingSkills.AddEvent(e);
265 }
266 CommonEventSubscribeInfo subscribeInfo(matchingSkills);
267 subscribeInfo.SetPriority(1);
268 subscriber_ = std::make_shared<FirstEventSubscriber>(subscribeInfo);
269 subscriber_->mainAbility = this;
270 CommonEventManager::SubscribeCommonEvent(subscriber_);
271 }
272
OnReceiveEvent(const CommonEventData & data)273 void FirstEventSubscriber::OnReceiveEvent(const CommonEventData &data)
274 {
275 HILOG_INFO("FirstEventSubscriber::OnReceiveEvent:event=%{public}s", data.GetWant().GetAction().c_str());
276 HILOG_INFO("FirstEventSubscriber::OnReceiveEvent:data=%{public}s", data.GetData().c_str());
277 HILOG_INFO("FirstEventSubscriber::OnReceiveEvent:code=%{public}d", data.GetCode());
278 auto eventName = data.GetWant().GetAction();
279 if (std::strcmp(eventName.c_str(), g_EVENT_REQU_FIRST_B.c_str()) == 0) {
280 auto target = data.GetData();
281 auto caseInfo = TestUtils::split(target, "_");
282 HILOG_INFO("FirstEventSubscriber::OnReceiveEvent:caseInfo.size()=%{public}zu", caseInfo.size());
283 if (caseInfo.size() < numThree) {
284 return;
285 }
286 if (mapTestFunc_.find(caseInfo[numZero]) != mapTestFunc_.end()) {
287 mapTestFunc_[caseInfo[numZero]](std::stoi(caseInfo[numOne]), std::stoi(caseInfo[numTwo]), data.GetCode());
288 } else {
289 HILOG_INFO("OnReceiveEvent: CommonEventData error(%{public}s)", target.c_str());
290 }
291 }
292 }
293
TestDispatcher(int apiIndex,int caseIndex,int code)294 void MainAbility::TestDispatcher(int apiIndex, int caseIndex, int code)
295 {
296 if (mapCase_.find(apiIndex) != mapCase_.end()) {
297 if (caseIndex < (int)mapCase_[apiIndex].size()) {
298 mapCase_[apiIndex][caseIndex](code);
299 }
300 }
301 }
302
SetInnerTask(TaskList & innerDispatcher,TestSetting innerSetting,std::string outerTaskId,int innerTaskSeq)303 void SetInnerTask(TaskList &innerDispatcher, TestSetting innerSetting, std::string outerTaskId, int innerTaskSeq)
304 {
305 std::string innerTaskId = outerTaskId + innerDelimiter + std::to_string(innerTaskSeq);
306 auto innerTask = std::make_shared<Runnable>([=]() { TestTask(innerTaskId); });
307 innerDispatcher.addOperation(innerSetting.op);
308 if (innerSetting.op == TestOperation::APPLY && innerSetting.apply > 0) {
309 innerDispatcher.addApply(innerSetting.apply);
310 }
311 if (innerSetting.op == TestOperation::DELAY && innerSetting.delay > 0) {
312 innerDispatcher.addDelay(innerSetting.delay);
313 }
314 innerDispatcher.addFunc(innerTask);
315 }
316
SetInnerTaskOther(TaskList & innerDispatcher,TestSetting innerSetting,int outerTaskSeq)317 void SetInnerTaskOther(TaskList &innerDispatcher, TestSetting innerSetting, int outerTaskSeq)
318 {
319 if (innerSetting.sync_barrier) {
320 std::string taskId = innerSyncBarrierId + std::to_string(outerTaskSeq);
321 auto task = std::make_shared<Runnable>([=]() { TestTask(taskId); });
322 innerDispatcher.addOperation(TestOperation::SYNC_BARRIER).addFunc(task);
323 }
324 if (innerSetting.async_barrier) {
325 std::string taskId = innerAsyncBarrierId + std::to_string(outerTaskSeq);
326 auto task = std::make_shared<Runnable>([=]() { TestTask(taskId); });
327 innerDispatcher.addOperation(TestOperation::ASYNC_BARRIER).addFunc(task);
328 }
329 if (innerSetting.group_wait) {
330 innerDispatcher.addOperation(TestOperation::GROUP_WAIT).addWaitTime(innerSetting.group_timeout);
331 }
332 if (innerSetting.group_notify) {
333 std::string taskId = innerGroupNotifyId + std::to_string(outerTaskSeq);
334 auto task = std::make_shared<Runnable>([=]() { TestTask(taskId); });
335 innerDispatcher.addOperation(TestOperation::GROUP_NOTIFY).addFunc(task);
336 }
337 }
338
SetOuterTaskOther(TaskList & outerDispatcher,TestSetting outerSetting)339 void SetOuterTaskOther(TaskList &outerDispatcher, TestSetting outerSetting)
340 {
341 if (outerSetting.sync_barrier) {
342 auto task = std::make_shared<Runnable>([=]() { TestTask(outerSyncBarrierId); });
343 outerDispatcher.addOperation(TestOperation::SYNC_BARRIER).addFunc(task);
344 }
345 if (outerSetting.async_barrier) {
346 auto task = std::make_shared<Runnable>([=]() { TestTask(outerAsyncBarrierId); });
347 outerDispatcher.addOperation(TestOperation::ASYNC_BARRIER).addFunc(task);
348 }
349 if (outerSetting.group_wait) {
350 outerDispatcher.addOperation(TestOperation::GROUP_WAIT).addWaitTime(outerSetting.group_timeout);
351 }
352 if (outerSetting.group_notify) {
353 auto task = std::make_shared<Runnable>([=]() { TestTask(outerGroupNotifyId); });
354 outerDispatcher.addOperation(TestOperation::GROUP_NOTIFY).addFunc(task);
355 }
356 }
357
CountTask(TestSetting outerSetting,TestSetting innerSetting)358 int CountTask(TestSetting outerSetting, TestSetting innerSetting)
359 {
360 int taskCount = 0;
361 taskCount = (innerSetting.op == TestOperation::APPLY) ? (innerSetting.apply * testTaskCount) : testTaskCount;
362 if (innerSetting.sync_barrier) {
363 taskCount++;
364 }
365 if (innerSetting.async_barrier) {
366 taskCount++;
367 }
368 if (innerSetting.group_notify) {
369 taskCount++;
370 }
371 taskCount = (outerSetting.op == TestOperation::APPLY)
372 ? (outerSetting.apply * testTaskCount + outerSetting.apply * testTaskCount * taskCount)
373 : (testTaskCount + testTaskCount * taskCount);
374 if (outerSetting.sync_barrier) {
375 taskCount++;
376 }
377 if (outerSetting.async_barrier) {
378 taskCount++;
379 }
380 if (outerSetting.group_notify) {
381 taskCount++;
382 }
383 return taskCount;
384 }
385
Dispatch(TestSetting outerSetting,TestSetting innerSetting)386 int MainAbility::Dispatch(TestSetting outerSetting, TestSetting innerSetting)
387 {
388 std::string outerName = "outerDispatcher";
389 std::string innerName = "innerDispatcher";
390 std::string outerTaskId;
391 auto context = GetContext();
392 TaskList outerDispatcher {outerSetting.dispatcher, context, outerName};
393 if (outerSetting.create_group) {
394 outerDispatcher.addOperation(TestOperation::CREATE_GROUP);
395 }
396 for (int i = 0; i < testTaskCount; i++) {
397 outerTaskId = std::to_string(i);
398 auto outerTask = std::make_shared<Runnable>([=]() {
399 auto context = this->GetContext();
400 TaskList innerDispatcher {innerSetting.dispatcher, context, innerName + std::to_string(i)};
401 if (innerSetting.create_group) {
402 innerDispatcher.addOperation(TestOperation::CREATE_GROUP);
403 }
404 for (int j = 0; j < testTaskCount; j++) {
405 SetInnerTask(innerDispatcher, innerSetting, outerTaskId, j);
406 }
407 SetInnerTaskOther(innerDispatcher, innerSetting, i);
408 innerDispatcher.executedTask();
409 {
410 std::lock_guard<std::mutex> lock(dispatcher_mutex);
411 allDispatchers.push_back(innerDispatcher.getDispatcher());
412 }
413 TestTask(outerTaskId);
414 });
415 outerDispatcher.addOperation(outerSetting.op);
416 if (outerSetting.op == TestOperation::APPLY && outerSetting.apply > 0) {
417 outerDispatcher.addApply(outerSetting.apply);
418 }
419 if (outerSetting.op == TestOperation::DELAY && outerSetting.delay > 0) {
420 outerDispatcher.addDelay(outerSetting.delay);
421 }
422 outerDispatcher.addFunc(outerTask);
423 }
424 SetOuterTaskOther(outerDispatcher, outerSetting);
425 outerDispatcher.executedTask();
426 {
427 std::lock_guard<std::mutex> lock(dispatcher_mutex);
428 allDispatchers.push_back(outerDispatcher.getDispatcher());
429 }
430 int taskCount = CountTask(outerSetting, innerSetting);
431 return taskCount;
432 }
433
addTaskFromList(TaskList & dispatcher,const std::vector<TestOperation> & operationList,int & taskId,const int apply=0,const long delay=0)434 static void addTaskFromList(TaskList &dispatcher, const std::vector<TestOperation> &operationList, int &taskId,
435 const int apply = 0, const long delay = 0)
436 {
437 for (auto op : operationList) {
438 if (op == TestOperation::CREATE_GROUP) {
439 dispatcher.addOperation(op);
440 continue;
441 }
442 if (op == TestOperation::APPLY) {
443 dispatcher.addApply(apply);
444 }
445 if (op == TestOperation::DELAY) {
446 dispatcher.addDelay(delay);
447 }
448 dispatcher.addOperation(op).addFunc(std::make_shared<Runnable>([=]() { TestTask(std::to_string(taskId)); }));
449 taskId++;
450 }
451 }
452
MultiAppCase1(int code)453 void MainAbility::MultiAppCase1(int code)
454 {
455 HILOG_INFO("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__);
456 Reset();
457 auto context = GetContext();
458 TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"};
459 std::vector<TestOperation> operationList = {
460 TestOperation::ASYNC,
461 TestOperation::ASYNC,
462 TestOperation::ASYNC,
463 TestOperation::ASYNC,
464 TestOperation::ASYNC,
465 TestOperation::ASYNC,
466 TestOperation::ASYNC,
467 TestOperation::ASYNC,
468 TestOperation::ASYNC,
469 TestOperation::ASYNC,
470 };
471 int taskId = 0;
472 addTaskFromList(globalDispatcher, operationList, taskId);
473 globalDispatcher.executedTask();
474 Wait(taskId);
475 bool result = task_execution_sequence.size() > 1;
476 std::vector<size_t> outerTaskIndex;
477 std::vector<std::vector<size_t>> innerTaskIndex;
478 GetTaskIndex(outerTaskIndex, innerTaskIndex, taskId, 0);
479 for (auto index : outerTaskIndex) {
480 result = result && (index != std::string::npos);
481 }
482 TestUtils::PublishEvent(g_EVENT_RESP_FIRST_B, code, std::to_string(result));
483 }
484
MultiAppCase2(int code)485 void MainAbility::MultiAppCase2(int code)
486 {
487 HILOG_INFO("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__);
488 Reset();
489 auto context = GetContext();
490 TaskList globalDispatcher = TaskList {TestDispatcher::PARALLEL, context, "parallel"};
491 std::vector<TestOperation> operationList = {
492 TestOperation::ASYNC,
493 TestOperation::ASYNC,
494 TestOperation::ASYNC,
495 TestOperation::ASYNC,
496 TestOperation::ASYNC,
497 TestOperation::ASYNC,
498 TestOperation::ASYNC,
499 TestOperation::ASYNC,
500 TestOperation::ASYNC,
501 TestOperation::ASYNC,
502 };
503 int taskId = 0;
504 addTaskFromList(globalDispatcher, operationList, taskId);
505 globalDispatcher.executedTask();
506 Wait(taskId);
507 bool result = task_execution_sequence.size() > 1;
508 std::vector<size_t> outerTaskIndex;
509 std::vector<std::vector<size_t>> innerTaskIndex;
510 GetTaskIndex(outerTaskIndex, innerTaskIndex, taskId, 0);
511 for (auto index : outerTaskIndex) {
512 result = result && (index != std::string::npos);
513 }
514 TestUtils::PublishEvent(g_EVENT_RESP_FIRST_B, code, std::to_string(result));
515 }
516
MultiAppCase3(int code)517 void MainAbility::MultiAppCase3(int code)
518 {
519 HILOG_INFO("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__);
520 Reset();
521 auto context = GetContext();
522 TaskList globalDispatcher = TaskList {TestDispatcher::SERIAL, context, "serial"};
523 std::vector<TestOperation> operationList = {
524 TestOperation::ASYNC,
525 TestOperation::ASYNC,
526 TestOperation::ASYNC,
527 TestOperation::ASYNC,
528 TestOperation::ASYNC,
529 TestOperation::ASYNC,
530 TestOperation::ASYNC,
531 TestOperation::ASYNC,
532 TestOperation::ASYNC,
533 TestOperation::ASYNC,
534 };
535 int taskId = 0;
536 addTaskFromList(globalDispatcher, operationList, taskId);
537 globalDispatcher.executedTask();
538 Wait(taskId);
539 bool result = task_execution_sequence.size() > 1;
540 std::vector<size_t> outerTaskIndex;
541 std::vector<std::vector<size_t>> innerTaskIndex;
542 GetTaskIndex(outerTaskIndex, innerTaskIndex, taskId, 0);
543 for (auto index : outerTaskIndex) {
544 result = result && (index != std::string::npos);
545 }
546 TestUtils::PublishEvent(g_EVENT_RESP_FIRST_B, code, std::to_string(result));
547 }
548
MultiAppCase4(int code)549 void MainAbility::MultiAppCase4(int code)
550 {
551 HILOG_INFO("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__);
552 Reset();
553 auto context = GetContext();
554 TaskList globalDispatcher = TaskList {TestDispatcher::MAIN, context, "main"};
555 std::vector<TestOperation> operationList = {
556 TestOperation::ASYNC,
557 TestOperation::ASYNC,
558 TestOperation::ASYNC,
559 TestOperation::ASYNC,
560 TestOperation::ASYNC,
561 TestOperation::ASYNC,
562 TestOperation::ASYNC,
563 TestOperation::ASYNC,
564 TestOperation::ASYNC,
565 TestOperation::ASYNC,
566 };
567 int taskId = 0;
568 addTaskFromList(globalDispatcher, operationList, taskId);
569 globalDispatcher.executedTask();
570 Wait(taskId);
571 bool result = task_execution_sequence.size() > 1;
572 std::vector<size_t> outerTaskIndex;
573 std::vector<std::vector<size_t>> innerTaskIndex;
574 GetTaskIndex(outerTaskIndex, innerTaskIndex, taskId, 0);
575 for (auto index : outerTaskIndex) {
576 result = result && (index != std::string::npos);
577 }
578 TestUtils::PublishEvent(g_EVENT_RESP_FIRST_B, code, std::to_string(result));
579 }
580 REGISTER_AA(MainAbility)
581 } // namespace AppExecFwk
582 } // namespace OHOS
583