14
14
15
15
import (" //build_overrides/build.gni" )
16
16
import (" //build_overrides/chip.gni" )
17
+ import (" //build_overrides/pigweed.gni" )
17
18
18
- import (" ${ chip_root } /build/chip/chip_test.gni" )
19
19
import (" ${ chip_root } /build/chip/tests.gni" )
20
20
import (" ${ dir_pw_unit_test } /test.gni" )
21
21
22
22
assert (chip_build_tests )
23
23
24
+ declare_args () {
25
+ # These may be overridden in args.gni to build platform-specific test binaries.
26
+ test_executable_output_name = " "
27
+ test_executable_output_name_suffix = " "
28
+ test_executable_ldflags = []
29
+ }
30
+
24
31
# Define CHIP unit tests
25
32
#
26
33
# Simple usage
@@ -41,50 +48,23 @@ assert(chip_build_tests)
41
48
# "${chip_root}/src/lib/foo", # add dependencies here
42
49
# ]
43
50
# }
44
- #
45
- #
46
- # Deprecated usage (writing own driver files):
47
- #
48
- # chip_test_suite("tests") {
49
- # output_name = "libFooTests"
50
- #
51
- # sources = [
52
- # "TestDeclarations.h",
53
- # "TestFoo.cpp",
54
- # "TestBar.cpp",
55
- # ]
56
- #
57
- # public_deps = [
58
- # "${chip_root}/src/lib/foo", # add dependencies here
59
- # ]
60
- #
61
- # tests = [
62
- # "TestFoo", # Assumes TestFooDriver.cpp exists
63
- # "TestBar", # Assumes TestBarDriver.cpp exists
64
- # ]
65
- # }
66
51
67
52
#
68
53
template (" chip_test_suite" ) {
69
54
_suite_name = target_name
70
55
71
- # Ensures that the common library has sources containing both common
72
- # and individual unit tests.
73
- if (! defined (invoker .sources )) {
74
- invoker .sources = []
75
- }
76
-
77
- if (defined (invoker .test_sources )) {
78
- invoker .sources += invoker .test_sources
79
- }
80
-
81
56
if (chip_build_test_static_libraries ) {
82
57
_target_type = " static_library"
83
58
} else {
84
59
_target_type = " source_set"
85
60
}
86
61
target (_target_type , " ${ _suite_name } .lib" ) {
87
- forward_variables_from (invoker , " *" , [ " tests" ])
62
+ forward_variables_from (invoker ,
63
+ " *" ,
64
+ [
65
+ " tests" ,
66
+ " test_sources" ,
67
+ ])
88
68
89
69
output_dir = " ${ root_out_dir } /lib"
90
70
@@ -102,79 +82,62 @@ template("chip_test_suite") {
102
82
public_deps += [ " ${ chip_root } /src/platform/logging:default" ]
103
83
}
104
84
}
105
- if (chip_link_tests ) {
106
- tests = []
107
85
108
- if (defined (invoker .test_sources )) {
109
- foreach (_test , invoker .test_sources ) {
110
- _test_name = string_replace (_test , " .cpp" , " " )
86
+ tests = []
111
87
112
- _test_output_dir = " ${ root_out_dir } /tests"
113
- if (defined (invoker .output_dir )) {
114
- _test_output_dir = invoker .output_dir
115
- }
88
+ if (defined (invoker .test_sources )) {
89
+ foreach (_test , invoker .test_sources ) {
90
+ _test_name = string_replace (_test , " .cpp" , " " )
116
91
117
- pw_test (_test_name ) {
118
- forward_variables_from (invoker ,
119
- [
120
- " deps" ,
121
- " public_deps" ,
122
- " cflags" ,
123
- " configs" ,
124
- ])
125
- public_deps += [ " :${ _suite_name } .lib" ]
126
- sources = [ _test ]
127
- output_dir = _test_output_dir
128
- }
129
- tests += [ _test_name ]
92
+ _test_output_dir = " ${ root_out_dir } /tests"
93
+ if (defined (invoker .output_dir )) {
94
+ _test_output_dir = invoker .output_dir
130
95
}
131
- }
132
96
133
- if (defined (invoker .tests )) {
134
- foreach (_test , invoker .tests ) {
135
- _test_output_dir = " ${ root_out_dir } /tests"
136
- if (defined (invoker .output_dir )) {
137
- _test_output_dir = invoker .output_dir
97
+ pw_test (_test_name ) {
98
+ # Forward certain variables from the invoker.
99
+ forward_variables_from (invoker ,
100
+ [
101
+ " deps" ,
102
+ " public_deps" ,
103
+ " cflags" ,
104
+ " configs" ,
105
+ ])
106
+
107
+ # Link to the common lib for this suite so we get its `sources`.
108
+ public_deps += [ " :${ _suite_name } .lib" ]
109
+
110
+ # Set variables that the platform executable may need.
111
+ if (test_executable_output_name != " " ) {
112
+ output_name = test_executable_output_name + _test_name +
113
+ test_executable_output_name_suffix
138
114
}
115
+ ldflags = test_executable_ldflags
139
116
140
- pw_test (_test ) {
141
- forward_variables_from (invoker ,
142
- [
143
- " deps" ,
144
- " public_deps" ,
145
- " cflags" ,
146
- " configs" ,
147
- ])
148
- public_deps += [ " :${ _suite_name } .lib" ]
149
- test_main = " "
150
- sources = [
151
- " ${ _test } .cpp" ,
152
- " ${ _test } Driver.cpp" ,
153
- ]
154
- output_dir = _test_output_dir
155
- }
156
- tests += [ _test ]
117
+ # Add the individual test source file (e.g. "TestSomething.cpp").
118
+ sources = [ _test ]
119
+
120
+ output_dir = _test_output_dir
157
121
}
122
+ tests += [ _test_name ]
158
123
}
124
+ }
159
125
160
- group (_suite_name ) {
161
- deps = []
162
- foreach (_test , tests ) {
163
- deps += [ " :${ _test } " ]
164
- }
126
+ group (_suite_name ) {
127
+ deps = []
128
+
129
+ # Add each individual unit test.
130
+ foreach (_test , tests ) {
131
+ deps += [ " :${ _test } " ]
165
132
}
133
+ }
166
134
167
- if (chip_pw_run_tests ) {
168
- group (" ${ _suite_name } _run" ) {
169
- deps = []
170
- foreach (_test , tests ) {
171
- deps += [ " :${ _test } .run" ]
172
- }
135
+ if (chip_pw_run_tests ) {
136
+ group (" ${ _suite_name } _run" ) {
137
+ deps = []
138
+ foreach (_test , tests ) {
139
+ deps += [ " :${ _test } .run" ]
173
140
}
174
141
}
175
- } else {
176
- group (_suite_name ) {
177
- deps = [ " :${ _suite_name } .lib" ]
178
- }
179
142
}
180
- }
143
+ }
0 commit comments