1# Copyright (c) 2021 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
14import("//build/ohos.gni")
15
16import("//build/ohos_var.gni")
17import("//build/test.gni")
18import("../../ffrt.gni")
19
20module_output_path = "ffrttest/"
21
22gtest_public_deps = [ "//third_party/googletest:gtest_main" ]
23
24ffrt_ut_base_deps = [
25  "../..:libffrt",
26  "//third_party/googletest:gtest",
27]
28
29ffrt_ut_base_external_deps = [
30  "c_utils:utils",
31  "faultloggerd:libbacktrace_local",
32  "faultloggerd:libdfx_dumpcatcher",
33  "hilog:libhilog",
34  "hitrace:libhitracechain",
35]
36
37config("ffrt_test_config") {
38  include_dirs = [
39    "../../src",
40    "../../src/dfx/log",
41    "../../src/dfx/trace",
42    "../../src/sched",
43  ]
44
45  cflags = [
46    "-fno-rtti",
47    "-Wno-unused-variable",
48    "-Wno-unused-function",
49  ]
50
51  defines = [
52    "QOS_INTERVAL",
53    "QOS_DISPATCH",
54    "QOS_RTG",
55    "QOS_MULTI_RTG",
56    "QOS_RTG_RT",
57    "QOS_CHECKPOINT",
58    "QOS_SUBMIT",
59    "QOS_DEMO",
60    "ATRACE_MODE=0",  # 0 is off, 5 is bytrace, 6 is pmu
61    "ATRACE_LEVEL=0",
62    "ATRACE_LOGI_ENABLE=0",
63    "ATRACE_LOGD_ENABLE=0",
64    "ATRACE_SCOPE_LOG_ENABLE=0",
65    "ATRACE_DURATION_LOG_ENABLE=0",
66    "FFRT_RELEASE",
67    "DISABLE_MONITOR",
68  ]
69  if (use_musl) {
70    defines += [ "TDD_MUSL" ]
71  }
72  if (ffrt_async_stack_enable) {
73    defines += [ "FFRT_ASYNC_STACKTRACE" ]
74  }
75}
76
77ohos_unittest("frame_interval_test") {
78  module_out_path = module_output_path
79
80  configs = [ ":ffrt_test_config" ]
81  include_dirs = [ "../testfunc" ]
82
83  cflags_cc = [
84    "-frtti",
85    "-Xclang",
86    "-fcxx-exceptions",
87    "-std=c++11",
88    "-DFFRT_PERF_EVENT_ENABLE",
89  ]
90
91  sources = [ "frame_interval_test.cpp" ]
92  deps = ffrt_ut_base_deps
93  external_deps = ffrt_ut_base_external_deps
94
95  if (is_standard_system) {
96    public_deps = gtest_public_deps
97  }
98
99  install_enable = true
100  part_name = "ffrt"
101}
102
103ohos_unittest("deadline_test") {
104  module_out_path = module_output_path
105
106  configs = [ ":ffrt_test_config" ]
107  include_dirs = [ "../testfunc" ]
108
109  cflags_cc = [
110    "-frtti",
111    "-Xclang",
112    "-fcxx-exceptions",
113    "-std=c++11",
114    "-DFFRT_PERF_EVENT_ENABLE",
115  ]
116
117  sources = [ "deadline_test.cpp" ]
118  deps = ffrt_ut_base_deps
119  external_deps = ffrt_ut_base_external_deps
120
121  if (is_standard_system) {
122    public_deps = gtest_public_deps
123  }
124
125  install_enable = true
126  part_name = "ffrt"
127}
128
129ohos_unittest("task_ctx_test") {
130  module_out_path = module_output_path
131
132  configs = [ ":ffrt_test_config" ]
133  include_dirs = [ "../testfunc" ]
134
135  cflags_cc = [
136    "-frtti",
137    "-Xclang",
138    "-fcxx-exceptions",
139    "-std=c++11",
140    "-DFFRT_PERF_EVENT_ENABLE",
141  ]
142
143  sources = [ "task_ctx_test.cpp" ]
144  deps = ffrt_ut_base_deps
145  external_deps = ffrt_ut_base_external_deps
146
147  if (is_standard_system) {
148    public_deps = gtest_public_deps
149  }
150
151  install_enable = true
152  part_name = "ffrt"
153}
154
155ohos_unittest("cpu_monitor_test") {
156  module_out_path = module_output_path
157
158  configs = [ ":ffrt_test_config" ]
159  include_dirs = [ "../testfunc" ]
160
161  cflags_cc = [
162    "-frtti",
163    "-Xclang",
164    "-fcxx-exceptions",
165    "-std=c++11",
166    "-DFFRT_PERF_EVENT_ENABLE",
167  ]
168
169  sources = [ "cpu_monitor_test.cpp" ]
170  deps = ffrt_ut_base_deps
171  external_deps = ffrt_ut_base_external_deps
172
173  if (is_standard_system) {
174    public_deps = gtest_public_deps
175  }
176
177  install_enable = true
178  part_name = "ffrt"
179}
180
181ohos_unittest("cpuworker_manager_test") {
182  module_out_path = module_output_path
183
184  configs = [ ":ffrt_test_config" ]
185  include_dirs = [ "../testfunc" ]
186
187  cflags_cc = [
188    "-frtti",
189    "-Xclang",
190    "-fcxx-exceptions",
191    "-std=c++11",
192    "-DFFRT_PERF_EVENT_ENABLE",
193  ]
194
195  sources = [ "cpuworker_manager_test.cpp" ]
196  deps = ffrt_ut_base_deps
197  external_deps = ffrt_ut_base_external_deps
198
199  if (is_standard_system) {
200    public_deps = gtest_public_deps
201  }
202
203  install_enable = true
204  part_name = "ffrt"
205}
206
207ohos_unittest("execute_unit_test") {
208  module_out_path = module_output_path
209
210  configs = [ ":ffrt_test_config" ]
211  include_dirs = [ "../testfunc" ]
212
213  cflags_cc = [
214    "-frtti",
215    "-Xclang",
216    "-fcxx-exceptions",
217    "-std=c++11",
218    "-DFFRT_PERF_EVENT_ENABLE",
219  ]
220
221  sources = [ "execute_unit_test.cpp" ]
222  deps = ffrt_ut_base_deps
223  external_deps = ffrt_ut_base_external_deps
224
225  if (is_standard_system) {
226    public_deps = gtest_public_deps
227  }
228
229  install_enable = true
230  part_name = "ffrt"
231}
232
233ohos_unittest("worker_thread_test") {
234  module_out_path = module_output_path
235
236  configs = [ ":ffrt_test_config" ]
237  include_dirs = [ "../testfunc" ]
238
239  cflags_cc = [
240    "-frtti",
241    "-Xclang",
242    "-fcxx-exceptions",
243    "-std=c++11",
244    "-DFFRT_PERF_EVENT_ENABLE",
245  ]
246
247  sources = [ "worker_thread_test.cpp" ]
248  deps = ffrt_ut_base_deps
249  external_deps = ffrt_ut_base_external_deps
250
251  if (is_standard_system) {
252    public_deps = gtest_public_deps
253  }
254
255  install_enable = true
256  part_name = "ffrt"
257}
258
259ohos_unittest("qos_convert_test") {
260  module_out_path = module_output_path
261
262  configs = [ ":ffrt_test_config" ]
263  include_dirs = [ "../testfunc" ]
264
265  cflags_cc = [
266    "-frtti",
267    "-Xclang",
268    "-fcxx-exceptions",
269    "-std=c++11",
270    "-DFFRT_PERF_EVENT_ENABLE",
271  ]
272
273  sources = [ "qos_convert_test.cpp" ]
274  deps = ffrt_ut_base_deps
275  external_deps = ffrt_ut_base_external_deps
276
277  if (is_standard_system) {
278    public_deps = gtest_public_deps
279  }
280
281  install_enable = true
282  part_name = "ffrt"
283}
284
285ohos_unittest("ut_coroutine") {
286  module_out_path = module_output_path
287
288  configs = [ ":ffrt_test_config" ]
289  include_dirs = [ "../testfunc" ]
290
291  cflags_cc = [
292    "-frtti",
293    "-Xclang",
294    "-fcxx-exceptions",
295    "-std=c++11",
296    "-DFFRT_PERF_EVENT_ENABLE",
297  ]
298
299  sources = [ "testcase/ut_coroutine.cpp" ]
300  deps = ffrt_ut_base_deps
301  external_deps = ffrt_ut_base_external_deps
302
303  if (is_standard_system) {
304    public_deps = gtest_public_deps
305  }
306
307  install_enable = true
308  part_name = "ffrt"
309}
310
311ohos_unittest("ut_core_test") {
312  module_out_path = module_output_path
313
314  configs = [ ":ffrt_test_config" ]
315  include_dirs = [ "../testfunc" ]
316
317  cflags_cc = [
318    "-frtti",
319    "-Xclang",
320    "-fcxx-exceptions",
321    "-std=c++11",
322    "-DFFRT_PERF_EVENT_ENABLE",
323  ]
324
325  sources = [ "testcase/ut_core_test.cpp" ]
326  deps = ffrt_ut_base_deps
327  external_deps = ffrt_ut_base_external_deps
328
329  if (is_standard_system) {
330    public_deps = gtest_public_deps
331  }
332
333  install_enable = true
334  part_name = "ffrt"
335}
336
337ohos_unittest("cpu_worker_test") {
338  module_out_path = module_output_path
339
340  configs = [ ":ffrt_test_config" ]
341  include_dirs = [ "../testfunc" ]
342
343  cflags_cc = [
344    "-frtti",
345    "-Xclang",
346    "-fcxx-exceptions",
347    "-std=c++11",
348    "-DFFRT_PERF_EVENT_ENABLE",
349  ]
350
351  sources = [ "cpu_worker_test.cpp" ]
352  deps = ffrt_ut_base_deps
353  external_deps = ffrt_ut_base_external_deps
354
355  if (is_standard_system) {
356    public_deps = gtest_public_deps
357  }
358
359  install_enable = true
360  part_name = "ffrt"
361}
362
363ohos_unittest("inherit_test") {
364  module_out_path = module_output_path
365
366  configs = [ ":ffrt_test_config" ]
367  include_dirs = [ "../testfunc" ]
368
369  cflags_cc = [
370    "-frtti",
371    "-Xclang",
372    "-fcxx-exceptions",
373    "-std=c++11",
374    "-DFFRT_PERF_EVENT_ENABLE",
375  ]
376
377  sources = [ "testcase/inherit_test.cpp" ]
378  deps = ffrt_ut_base_deps
379  external_deps = ffrt_ut_base_external_deps
380
381  if (is_standard_system) {
382    public_deps = gtest_public_deps
383  }
384
385  install_enable = true
386  part_name = "ffrt"
387}
388
389ohos_unittest("qos_interface_test") {
390  module_out_path = module_output_path
391
392  configs = [ ":ffrt_test_config" ]
393  include_dirs = [ "../testfunc" ]
394
395  cflags_cc = [
396    "-frtti",
397    "-Xclang",
398    "-fcxx-exceptions",
399    "-std=c++11",
400    "-DFFRT_PERF_EVENT_ENABLE",
401  ]
402
403  sources = [ "qos_interface_test.cpp" ]
404  deps = ffrt_ut_base_deps
405  external_deps = ffrt_ut_base_external_deps
406
407  if (is_standard_system) {
408    public_deps = gtest_public_deps
409  }
410
411  install_enable = true
412  part_name = "ffrt"
413}
414
415ohos_unittest("ut_condition") {
416  module_out_path = module_output_path
417
418  configs = [ ":ffrt_test_config" ]
419  include_dirs = [ "../testfunc" ]
420
421  cflags_cc = [
422    "-frtti",
423    "-Xclang",
424    "-fcxx-exceptions",
425    "-std=c++11",
426    "-DFFRT_PERF_EVENT_ENABLE",
427  ]
428
429  sources = [ "testcase/ut_condition.cpp" ]
430  deps = ffrt_ut_base_deps
431  external_deps = ffrt_ut_base_external_deps
432
433  if (is_standard_system) {
434    public_deps = gtest_public_deps
435  }
436
437  install_enable = true
438  part_name = "ffrt"
439}
440
441ohos_unittest("ut_core") {
442  module_out_path = module_output_path
443
444  configs = [ ":ffrt_test_config" ]
445  include_dirs = [ "../testfunc" ]
446
447  cflags_cc = [
448    "-frtti",
449    "-Xclang",
450    "-fcxx-exceptions",
451    "-std=c++11",
452    "-DFFRT_PERF_EVENT_ENABLE",
453  ]
454
455  sources = [ "testcase/ut_core.cpp" ]
456  deps = ffrt_ut_base_deps
457  external_deps = ffrt_ut_base_external_deps
458
459  if (is_standard_system) {
460    public_deps = gtest_public_deps
461  }
462
463  install_enable = true
464  part_name = "ffrt"
465}
466
467ohos_unittest("ut_csync") {
468  module_out_path = module_output_path
469
470  configs = [ ":ffrt_test_config" ]
471  include_dirs = [ "../testfunc" ]
472
473  cflags_cc = [
474    "-frtti",
475    "-Xclang",
476    "-fcxx-exceptions",
477    "-std=c++11",
478    "-DFFRT_PERF_EVENT_ENABLE",
479  ]
480
481  sources = [ "testcase/ut_csync.cpp" ]
482  deps = ffrt_ut_base_deps
483  external_deps = ffrt_ut_base_external_deps
484
485  if (is_standard_system) {
486    public_deps = gtest_public_deps
487  }
488
489  install_enable = true
490  part_name = "ffrt"
491}
492
493ohos_unittest("ut_deadline") {
494  module_out_path = module_output_path
495
496  configs = [ ":ffrt_test_config" ]
497  include_dirs = [ "../testfunc" ]
498
499  cflags_cc = [
500    "-frtti",
501    "-Xclang",
502    "-fcxx-exceptions",
503    "-std=c++11",
504    "-DFFRT_PERF_EVENT_ENABLE",
505  ]
506
507  sources = [ "testcase/ut_deadline.cpp" ]
508  deps = ffrt_ut_base_deps
509  external_deps = ffrt_ut_base_external_deps
510
511  if (is_standard_system) {
512    public_deps = gtest_public_deps
513  }
514
515  install_enable = true
516  part_name = "ffrt"
517}
518
519ohos_unittest("ut_dependency") {
520  module_out_path = module_output_path
521
522  configs = [ ":ffrt_test_config" ]
523  include_dirs = [ "../testfunc" ]
524
525  cflags_cc = [
526    "-frtti",
527    "-Xclang",
528    "-fcxx-exceptions",
529    "-std=c++11",
530    "-DFFRT_PERF_EVENT_ENABLE",
531  ]
532
533  sources = [ "testcase/ut_dependency.cpp" ]
534  deps = ffrt_ut_base_deps
535  external_deps = ffrt_ut_base_external_deps
536
537  if (is_standard_system) {
538    public_deps = gtest_public_deps
539  }
540
541  install_enable = true
542  part_name = "ffrt"
543}
544
545ohos_unittest("ut_execute_unit") {
546  module_out_path = module_output_path
547
548  configs = [ ":ffrt_test_config" ]
549  include_dirs = [ "../testfunc" ]
550
551  cflags_cc = [
552    "-frtti",
553    "-Xclang",
554    "-fcxx-exceptions",
555    "-std=c++11",
556    "-DFFRT_PERF_EVENT_ENABLE",
557  ]
558
559  sources = [ "testcase/ut_execute_unit.cpp" ]
560  deps = ffrt_ut_base_deps
561  external_deps = ffrt_ut_base_external_deps
562
563  if (is_standard_system) {
564    public_deps = gtest_public_deps
565  }
566
567  install_enable = true
568  part_name = "ffrt"
569}
570
571ohos_unittest("ut_ffrt_io") {
572  module_out_path = module_output_path
573
574  configs = [ ":ffrt_test_config" ]
575  include_dirs = [ "../testfunc" ]
576
577  cflags_cc = [
578    "-frtti",
579    "-Xclang",
580    "-fcxx-exceptions",
581    "-std=c++11",
582    "-DFFRT_PERF_EVENT_ENABLE",
583  ]
584
585  sources = [ "testcase/ut_ffrt_io.cpp" ]
586  deps = ffrt_ut_base_deps
587  external_deps = ffrt_ut_base_external_deps
588
589  if (is_standard_system) {
590    public_deps = gtest_public_deps
591  }
592
593  install_enable = true
594  part_name = "ffrt"
595}
596
597ohos_unittest("ut_graphCheck") {
598  module_out_path = module_output_path
599
600  configs = [ ":ffrt_test_config" ]
601  include_dirs = [ "../testfunc" ]
602
603  cflags_cc = [
604    "-frtti",
605    "-Xclang",
606    "-fcxx-exceptions",
607    "-std=c++11",
608    "-DFFRT_PERF_EVENT_ENABLE",
609  ]
610
611  sources = [ "testcase/ut_graphCheck.cpp" ]
612  deps = ffrt_ut_base_deps
613  external_deps = ffrt_ut_base_external_deps
614
615  if (is_standard_system) {
616    public_deps = gtest_public_deps
617  }
618
619  install_enable = true
620  part_name = "ffrt"
621}
622
623ohos_unittest("ut_interval") {
624  module_out_path = module_output_path
625
626  configs = [ ":ffrt_test_config" ]
627  include_dirs = [ "../testfunc" ]
628
629  cflags_cc = [
630    "-frtti",
631    "-Xclang",
632    "-fcxx-exceptions",
633    "-std=c++11",
634    "-DFFRT_PERF_EVENT_ENABLE",
635  ]
636
637  sources = [ "testcase/ut_interval.cpp" ]
638  deps = ffrt_ut_base_deps
639  external_deps = ffrt_ut_base_external_deps
640
641  if (is_standard_system) {
642    public_deps = gtest_public_deps
643  }
644
645  install_enable = true
646  part_name = "ffrt"
647}
648
649ohos_unittest("ut_loop") {
650  module_out_path = module_output_path
651
652  configs = [ ":ffrt_test_config" ]
653  include_dirs = [ "../testfunc" ]
654
655  cflags_cc = [
656    "-frtti",
657    "-Xclang",
658    "-fcxx-exceptions",
659    "-std=c++11",
660    "-DFFRT_PERF_EVENT_ENABLE",
661  ]
662
663  sources = [ "testcase/ut_loop.cpp" ]
664  deps = ffrt_ut_base_deps
665  external_deps = ffrt_ut_base_external_deps
666
667  if (is_standard_system) {
668    public_deps = gtest_public_deps
669  }
670
671  install_enable = true
672  part_name = "ffrt"
673}
674
675ohos_unittest("ut_queue") {
676  module_out_path = module_output_path
677
678  configs = [ ":ffrt_test_config" ]
679  include_dirs = [ "../testfunc" ]
680
681  cflags_cc = [
682    "-frtti",
683    "-Xclang",
684    "-fcxx-exceptions",
685    "-std=c++11",
686    "-DFFRT_PERF_EVENT_ENABLE",
687  ]
688
689  sources = [ "testcase/ut_queue.cpp" ]
690  deps = ffrt_ut_base_deps
691  external_deps = ffrt_ut_base_external_deps
692
693  if (is_standard_system) {
694    public_deps = gtest_public_deps
695  }
696
697  install_enable = true
698  part_name = "ffrt"
699}
700
701ohos_unittest("ut_rtg") {
702  module_out_path = module_output_path
703
704  configs = [ ":ffrt_test_config" ]
705  include_dirs = [ "../testfunc" ]
706
707  cflags_cc = [
708    "-frtti",
709    "-Xclang",
710    "-fcxx-exceptions",
711    "-std=c++11",
712    "-DFFRT_PERF_EVENT_ENABLE",
713  ]
714
715  sources = [ "testcase/ut_rtg.cpp" ]
716  deps = ffrt_ut_base_deps
717  external_deps = ffrt_ut_base_external_deps
718
719  if (is_standard_system) {
720    public_deps = gtest_public_deps
721  }
722
723  install_enable = true
724  part_name = "ffrt"
725}
726
727ohos_unittest("ut_scheduler") {
728  module_out_path = module_output_path
729
730  configs = [ ":ffrt_test_config" ]
731  include_dirs = [ "../testfunc" ]
732
733  cflags_cc = [
734    "-frtti",
735    "-Xclang",
736    "-fcxx-exceptions",
737    "-std=c++11",
738    "-DFFRT_PERF_EVENT_ENABLE",
739  ]
740
741  sources = [ "testcase/ut_scheduler.cpp" ]
742  deps = ffrt_ut_base_deps
743  external_deps = ffrt_ut_base_external_deps
744
745  if (is_standard_system) {
746    public_deps = gtest_public_deps
747  }
748
749  install_enable = true
750  part_name = "ffrt"
751}
752
753ohos_unittest("ut_thread") {
754  module_out_path = module_output_path
755
756  configs = [ ":ffrt_test_config" ]
757  include_dirs = [ "../testfunc" ]
758
759  cflags_cc = [
760    "-frtti",
761    "-Xclang",
762    "-fcxx-exceptions",
763    "-std=c++11",
764    "-DFFRT_PERF_EVENT_ENABLE",
765  ]
766
767  sources = [ "testcase/ut_thread.cpp" ]
768  deps = ffrt_ut_base_deps
769  external_deps = ffrt_ut_base_external_deps
770
771  if (is_standard_system) {
772    public_deps = gtest_public_deps
773  }
774
775  install_enable = true
776  part_name = "ffrt"
777}
778
779ohos_unittest("ut_mem") {
780  module_out_path = module_output_path
781
782  configs = [ ":ffrt_test_config" ]
783  include_dirs = [ "../testfunc" ]
784
785  cflags_cc = [
786    "-frtti",
787    "-Xclang",
788    "-fcxx-exceptions",
789    "-std=c++11",
790    "-DFFRT_PERF_EVENT_ENABLE",
791  ]
792
793  sources = [
794    "../testfunc/func_pool.cpp",
795    "../testfunc/util.cpp",
796    "testcase/ut_mem.cpp",
797  ]
798  deps = ffrt_ut_base_deps
799  external_deps = ffrt_ut_base_external_deps
800
801  if (is_standard_system) {
802    public_deps = gtest_public_deps
803  }
804
805  install_enable = true
806  part_name = "ffrt"
807}
808
809ohos_unittest("worker_manager_test") {
810  module_out_path = module_output_path
811
812  configs = [ ":ffrt_test_config" ]
813  include_dirs = [ "../testfunc" ]
814
815  cflags_cc = [
816    "-frtti",
817    "-Xclang",
818    "-fcxx-exceptions",
819    "-std=c++11",
820    "-DFFRT_PERF_EVENT_ENABLE",
821  ]
822
823  sources = [ "worker_manager_test.cpp" ]
824  deps = ffrt_ut_base_deps
825  external_deps = ffrt_ut_base_external_deps
826
827  if (is_standard_system) {
828    public_deps = gtest_public_deps
829  }
830
831  install_enable = true
832  part_name = "ffrt"
833}
834
835group("ffrt_unittest_ffrt") {
836  testonly = true
837
838  deps = []
839  if (!is_asan) {
840    deps += [
841      ":cpu_monitor_test",
842      ":cpu_worker_test",
843      ":cpuworker_manager_test",
844      ":deadline_test",
845      ":execute_unit_test",
846      ":frame_interval_test",
847      ":inherit_test",
848      ":qos_convert_test",
849      ":qos_interface_test",
850      ":task_ctx_test",
851      ":ut_condition",
852      ":ut_core",
853      ":ut_core_test",
854      ":ut_coroutine",
855      ":ut_csync",
856      ":ut_deadline",
857      ":ut_dependency",
858      ":ut_execute_unit",
859      ":ut_ffrt_io",
860      ":ut_graphCheck",
861      ":ut_interval",
862      ":ut_loop",
863      ":ut_mem",
864      ":ut_queue",
865      ":ut_rtg",
866      ":ut_scheduler",
867      ":ut_thread",
868      ":worker_manager_test",
869      ":worker_thread_test",
870    ]
871  }
872}
873