@@ -89,6 +89,7 @@ def __init__(self,
89
89
use_asan : bool = False ,
90
90
use_tsan : bool = False ,
91
91
use_ubsan : bool = False ,
92
+ use_coverage : bool = False ,
92
93
with_ui : bool = False ,
93
94
):
94
95
super (TizenBuilder , self ).__init__ (
@@ -130,9 +131,59 @@ def __init__(self,
130
131
raise Exception ("TSAN sanitizer not supported by Tizen toolchain" )
131
132
if use_ubsan :
132
133
self .extra_gn_options .append ('is_ubsan=true' )
134
+ self .use_coverage = use_coverage
135
+ if use_coverage :
136
+ self .extra_gn_options .append ('use_coverage=true' )
133
137
if with_ui :
134
138
self .extra_gn_options .append ('chip_examples_enable_ui=true' )
135
139
140
+ def generate (self ):
141
+ super (TizenBuilder , self ).generate ()
142
+ if self .app == TizenApp .TESTS and self .use_coverage :
143
+ self .coverage_dir = os .path .join (self .output_dir , 'coverage' )
144
+ self ._Execute (['mkdir' , '-p' , self .coverage_dir ], title = "Create coverage output location" )
145
+
146
+ def lcov_args (self ):
147
+ gcov = os .path .join (os .environ ['TIZEN_SDK_TOOLCHAIN' ], 'bin/arm-linux-gnueabi-gcov' )
148
+ return [
149
+ 'lcov' , '--gcov-tool' , gcov , '--ignore-errors' , 'unused,mismatch' , '--capture' , '--directory' , os .path .join (
150
+ self .output_dir , 'obj' ),
151
+ '--exclude' , '**/src/controller/*' ,
152
+ '--exclude' , '**/connectedhomeip/zzz_generated/*' ,
153
+ '--exclude' , '**/connectedhomeip/third_party/*' ,
154
+ '--exclude' , '/opt/*' ,
155
+ ]
156
+
157
+ def PreBuildCommand (self ):
158
+ if self .app == TizenApp .TESTS and self .use_coverage :
159
+ cmd = ['ninja' , '-C' , self .output_dir ]
160
+
161
+ if self .ninja_jobs is not None :
162
+ cmd .append ('-j' + str (self .ninja_jobs ))
163
+
164
+ cmd .append ('Tizen' )
165
+
166
+ self ._Execute (cmd , title = "Build-only" )
167
+
168
+ self ._Execute (self .lcov_args () + [
169
+ '--initial' ,
170
+ '--output-file' , os .path .join (self .coverage_dir , 'lcov_base.info' )
171
+ ], title = "Initial coverage baseline" )
172
+
173
+ def PostBuildCommand (self ):
174
+ if self .app == TizenApp .TESTS and self .use_coverage :
175
+
176
+ self ._Execute (self .lcov_args () + ['--output-file' , os .path .join (self .coverage_dir ,
177
+ 'lcov_test.info' )], title = "Update coverage" )
178
+
179
+ gcov = os .path .join (os .environ ['TIZEN_SDK_TOOLCHAIN' ], 'bin/arm-linux-gnueabi-gcov' )
180
+ self ._Execute (['lcov' , '--gcov-tool' , gcov , '--add-tracefile' , os .path .join (self .coverage_dir , 'lcov_base.info' ),
181
+ '--add-tracefile' , os .path .join (self .coverage_dir , 'lcov_test.info' ),
182
+ '--output-file' , os .path .join (self .coverage_dir , 'lcov_final.info' )
183
+ ], title = "Final coverage info" )
184
+ self ._Execute (['genhtml' , os .path .join (self .coverage_dir , 'lcov_final.info' ), '--output-directory' ,
185
+ os .path .join (self .coverage_dir , 'html' )], title = "HTML coverage" )
186
+
136
187
def GnBuildArgs (self ):
137
188
# Make sure that required ENV variables are defined
138
189
for env in ('TIZEN_SDK_ROOT' , 'TIZEN_SDK_SYSROOT' ):
0 commit comments