1 # Copyright (c) 2020 Project CHIP Authors
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 import("//build_overrides/build.gni")
16 import("//build_overrides/chip.gni")
18 import("${chip_root}/build/chip/chip_test.gni")
19 import("${chip_root}/build/chip/tests.gni")
20 import("${dir_pw_unit_test}/test.gni")
22 assert(chip_build_tests)
24 # Define CHIP unit tests
27 # chip_test_suite("tests") {
28 # output_name = "libFooTests"
31 # "Common.h", # add common sources here
36 # "TestFoo.cpp", # Files are parsed for `CHIP_REGISTER_TEST_SUITE(...)`
37 # "TestBar.cpp", # and a driver is created automatically
41 # "${chip_root}/src/lib/foo", # add dependencies here
42 # "${nlunit_test_root}:nlunit-test",
47 # Deprecated usage (writing own driver files):
49 # chip_test_suite("tests") {
50 # output_name = "libFooTests"
53 # "TestDeclarations.h",
59 # "${chip_root}/src/lib/foo", # add dependencies here
60 # "${nlunit_test_root}:nlunit-test",
64 # "TestFoo", # Assumes TestFooDriver.cpp exists
65 # "TestBar", # Assumes TestBarDriver.cpp exists
70 template("chip_test_suite") {
71 _suite_name = target_name
73 # Ensures that the common library has sources containing both common
74 # and individual unit tests.
75 if (!defined(invoker.sources)) {
79 if (defined(invoker.test_sources)) {
80 invoker.sources += invoker.test_sources
83 static_library("${_suite_name}_lib") {
84 forward_variables_from(invoker, "*", [ "tests" ])
86 output_dir = "${root_out_dir}/lib"
88 if (!defined(invoker.public_deps)) {
92 # TODO: figure out a way to auto-define dependency on stdio logging.
93 # This dep is required since libSupportLayer now does not include
94 # a default implementation.
96 # Tests such as TestInetEndPoint need to exercise the system event
97 # loop however they do not seem to include a logging binding so this
98 # is forcefully added here.
99 if (current_os != "zephyr") {
100 public_deps += [ "${chip_root}/src/platform/logging:stdio" ]
104 if (chip_link_tests) {
107 if (defined(invoker.test_sources)) {
108 foreach(_test, invoker.test_sources) {
109 _test_name = string_replace(_test, ".cpp", "")
111 _driver_name = "${root_gen_dir}/${_test_name}.driver.cpp"
113 action("${_test_name}_generate_driver") {
114 script = "${chip_root}/scripts/gen_test_driver.py"
117 outputs = [ _driver_name ]
119 "--input_file=" + rebase_path(_test, root_build_dir),
120 "--output_file=" + rebase_path(_driver_name, root_build_dir),
124 chip_test(_test_name) {
125 sources = [ _driver_name ]
127 ":${_suite_name}_lib",
128 ":${_test_name}_generate_driver",
132 tests += [ _test_name ]
136 if (defined(invoker.tests)) {
137 foreach(_test, invoker.tests) {
139 sources = [ "${_test}Driver.cpp" ]
141 public_deps = [ ":${_suite_name}_lib" ]
150 foreach(_test, tests) {
151 deps += [ ":${_test}" ]
155 group("${_suite_name}_run") {
157 foreach(_test, tests) {
158 deps += [ ":${_test}_run" ]
163 deps = [ ":${_suite_name}_lib" ]