@@ -46,37 +46,45 @@ CHIP_ROOT=$(_normpath "$(dirname "$0")/..")
46
46
OUTPUT_ROOT=" $CHIP_ROOT /out/coverage"
47
47
COVERAGE_ROOT=" $OUTPUT_ROOT /coverage"
48
48
SUPPORTED_CODE=(core clusters all)
49
- SUPPORTED_TESTS=(unit yaml all)
50
49
CODE=" core"
51
- TESTS= " unit "
50
+
52
51
skip_gn=false
53
52
TEST_TARGET=check
54
53
55
- help () {
54
+ # By default, do not run YAML or Python tests
55
+ ENABLE_YAML=false
56
+ ENABLE_PYTHON=false
56
57
57
- echo " Usage: $file_name [--output_root=<output_root>] [--code=<core|clusters|all>] [--tests=<unit|yaml|all>]"
58
+ help () {
59
+ echo " Usage: $file_name [--output_root=<output_root>] [--code=<core|clusters|all>] [Test options"
60
+ echo
61
+ echo " Misc:"
62
+ echo " -h, --help Print this help, then exit."
63
+ echo
64
+ echo " Build/Output options:"
65
+ echo " -o, --output_root=DIR Set the build output directory."
66
+ echo " When set manually, script only runs lcov on the provided build output."
67
+ echo " This directory must be built with 'use_coverage=true' and 'ninja check' must have run."
68
+ echo
69
+ echo " -c, --code=TYPE Specify which scope to collect coverage data. One of:"
70
+ echo " core - (default) coverage from core stack in Matter SDK."
71
+ echo " clusters - coverage from cluster implementations in Matter SDK."
72
+ echo " all - coverage from entire Matter SDK."
58
73
echo
59
- echo " Misc:
60
- -h, --help Print this help, then exit."
74
+ echo " Test options:"
75
+ echo " --yaml In addition to unit tests, run YAML-based tests."
76
+ echo " --python In addition to unit tests, run Python-based tests."
77
+ echo " Both can be combined if needed."
78
+ echo
79
+ echo " --target=TARGET Specific test target to run for unit tests (e.g. 'TestEmberAttributeBuffer.run')."
61
80
echo
62
- echo " Options:
63
- -o, --output_root Set the build output directory. When set manually, performs only lcov stage
64
- on provided build output. Assumes output_root has been built with 'use_coverage=true'
65
- and that 'ninja check' was run.
66
- -c, --code Specify which scope to collect coverage data.
67
- 'core': collect coverage data from core stack in Matter SDK. --default
68
- 'clusters': collect coverage data from clusters implementation in Matter SDK.
69
- 'all': collect coverage data from Matter SDK.
70
- -t, --tests Specify which tools to run the coverage check.
71
- 'unit': Run unit test to drive the coverage check. --default
72
- 'yaml': Run yaml test to drive the coverage check.
73
- 'all': Run unit & yaml test to drive the coverage check.
74
- --target Specific test target to run (e.g. TestEmberAttributeBuffer.run)
75
- "
76
81
}
77
82
78
83
file_name=${0##*/ }
79
84
85
+ # ------------------------------------------------------------------------------
86
+ # Parse arguments
87
+ # ------------------------------------------------------------------------------
80
88
for i in " $@ " ; do
81
89
case $i in
82
90
-h | --help)
@@ -87,19 +95,24 @@ for i in "$@"; do
87
95
CODE=" ${i#* =} "
88
96
shift
89
97
;;
90
- -t=* | --tests=* )
91
- TESTS=" ${i#* =} "
92
- shift
93
- ;;
94
98
--target=* )
95
99
TEST_TARGET=" ${i#* =} "
100
+ shift
96
101
;;
97
102
-o=* | --output_root=* )
98
103
OUTPUT_ROOT=" ${i#* =} "
99
104
COVERAGE_ROOT=" $OUTPUT_ROOT /coverage"
100
105
skip_gn=true
101
106
shift
102
107
;;
108
+ --yaml)
109
+ ENABLE_YAML=true
110
+ shift
111
+ ;;
112
+ --python)
113
+ ENABLE_PYTHON=true
114
+ shift
115
+ ;;
103
116
* )
104
117
echo " Unknown Option \" $1 \" "
105
118
echo
@@ -109,49 +122,63 @@ for i in "$@"; do
109
122
esac
110
123
done
111
124
125
+ # Validate code argument
112
126
if [[ ! " ${SUPPORTED_CODE[@]} " =~ " ${CODE} " ]]; then
113
127
echo " ERROR: Code $CODE not supported"
114
128
exit 1
115
129
fi
116
130
117
- if [[ ! " ${SUPPORTED_TESTS[@]} " =~ " ${TESTS} " ]]; then
118
- echo " ERROR: Tests $TESTS not supported"
119
- exit 1
120
- fi
121
-
131
+ # ------------------------------------------------------------------------------
132
+ # Build & Test
133
+ # ------------------------------------------------------------------------------
122
134
if [ " $skip_gn " == false ]; then
123
- # Ensure we have a compilation environment
135
+ # Ensure environment is set
124
136
source " $CHIP_ROOT /scripts/activate.sh"
125
137
126
- # Generates ninja files
138
+ # Generate ninja files
127
139
EXTRA_GN_ARGS=" "
128
- if [[ " $TESTS " == " yaml" || " $TESTS " == " all" ]]; then
140
+
141
+ # We only need 'chip_build_all_clusters_app' if we run YAML tests
142
+ if [ " $ENABLE_YAML " == true ]; then
129
143
EXTRA_GN_ARGS=" $EXTRA_GN_ARGS chip_build_all_clusters_app=true"
130
144
else
145
+ # Otherwise skip building tools
131
146
EXTRA_GN_ARGS=" $EXTRA_GN_ARGS chip_build_tools=false"
132
147
fi
133
- gn --root=" $CHIP_ROOT " gen " $OUTPUT_ROOT " --args=" use_coverage=true$EXTRA_GN_ARGS "
134
148
135
- # Run unit tests
136
- if [[ " $TESTS " == " unit" || " $TESTS " == " all" ]]; then
137
- ninja -C " $OUTPUT_ROOT " " $TEST_TARGET "
138
- fi
149
+ gn --root=" $CHIP_ROOT " gen " $OUTPUT_ROOT " --args=" use_coverage=true $EXTRA_GN_ARGS "
150
+
151
+ #
152
+ # 1) Always run unit tests
153
+ #
154
+ ninja -C " $OUTPUT_ROOT " " $TEST_TARGET "
139
155
140
- # Run yaml tests
141
- if [[ " $TESTS " == " yaml" || " $TESTS " == " all" ]]; then
156
+ #
157
+ # 2) Run YAML tests if requested
158
+ #
159
+ if [ " $ENABLE_YAML " == true ]; then
142
160
ninja -C " $OUTPUT_ROOT "
143
161
144
162
scripts/run_in_build_env.sh \
145
163
" ./scripts/tests/run_test_suite.py \
146
- --chip-tool " " $OUTPUT_ROOT /chip-tool \
164
+ --chip-tool \" $OUTPUT_ROOT /chip-tool\" \
147
165
run \
148
166
--iterations 1 \
149
167
--test-timeout-seconds 120 \
150
- --all-clusters-app " " $OUTPUT_ROOT /chip-all-clusters-app
151
- "
168
+ --all-clusters-app \" $OUTPUT_ROOT /chip-all-clusters-app\" "
169
+ fi
170
+
171
+ #
172
+ # 3) Run Python tests if requested
173
+ #
174
+ if [ " $ENABLE_PYTHON " == true ]; then
175
+ echo " Running Python tests ..."
176
+ # TODO: run python tests.
152
177
fi
153
178
154
- # Remove misc support components from coverage statistics
179
+ # ----------------------------------------------------------------------------
180
+ # Remove objects we do NOT want included in coverage
181
+ # ----------------------------------------------------------------------------
155
182
rm -rf " $OUTPUT_ROOT /obj/src/app/app-platform"
156
183
rm -rf " $OUTPUT_ROOT /obj/src/app/common"
157
184
rm -rf " $OUTPUT_ROOT /obj/src/app/util/mock"
@@ -162,24 +189,45 @@ if [ "$skip_gn" == false ]; then
162
189
rm -rf " $OUTPUT_ROOT /obj/src/platform"
163
190
rm -rf " $OUTPUT_ROOT /obj/src/tools"
164
191
165
- # Remove unit test itself from coverage statistics
192
+ # Remove unit test objects from coverage
166
193
find " $OUTPUT_ROOT /obj/src/" -depth -name ' tests' -exec rm -rf {} \;
167
194
195
+ # Restrict coverage to 'core' or 'clusters' if specified
168
196
if [ " $CODE " == " core" ]; then
169
197
rm -rf " $OUTPUT_ROOT /obj/src/app/clusters"
170
198
elif [ " $CODE " == " clusters" ]; then
171
199
mv " $OUTPUT_ROOT /obj/src/app/clusters" " $OUTPUT_ROOT /obj/clusters"
172
200
rm -rf " $OUTPUT_ROOT /obj/src"
173
- mkdir " $OUTPUT_ROOT /obj/src"
201
+ mkdir -p " $OUTPUT_ROOT /obj/src"
174
202
mv " $OUTPUT_ROOT /obj/clusters" " $OUTPUT_ROOT /obj/src/clusters"
175
203
fi
176
204
fi
177
205
206
+ # ------------------------------------------------------------------------------
207
+ # Coverage Generation
208
+ # ------------------------------------------------------------------------------
178
209
mkdir -p " $COVERAGE_ROOT "
179
- lcov --initial --capture --ignore-errors inconsistent --directory " $OUTPUT_ROOT /obj/src" --exclude=" $PWD " /zzz_generated/* --exclude=" $PWD " /third_party/* --exclude=/usr/include/* --output-file " $COVERAGE_ROOT /lcov_base.info"
180
- lcov --capture --ignore-errors inconsistent --directory " $OUTPUT_ROOT /obj/src" --exclude=" $PWD " /zzz_generated/* --exclude=" $PWD " /third_party/* --exclude=/usr/include/* --output-file " $COVERAGE_ROOT /lcov_test.info"
181
- lcov --ignore-errors inconsistent --add-tracefile " $COVERAGE_ROOT /lcov_base.info" --add-tracefile " $COVERAGE_ROOT /lcov_test.info" --output-file " $COVERAGE_ROOT /lcov_final.info"
182
- genhtml " $COVERAGE_ROOT /lcov_final.info" --output-directory " $COVERAGE_ROOT /html" --title " SHA:$( git rev-parse HEAD) " --header-title " Matter SDK Coverage Report"
183
210
184
- # Copy webapp's YAML file to the coverage output directory
185
- cp " $CHIP_ROOT /integrations/appengine/webapp_config.yaml" " $COVERAGE_ROOT /webapp_config.yaml"
211
+ lcov --initial --capture --directory " $OUTPUT_ROOT /obj/src" \
212
+ --exclude=" $PWD " /zzz_generated/* \
213
+ --exclude=" $PWD " /third_party/* \
214
+ --exclude=/usr/include/* \
215
+ --output-file " $COVERAGE_ROOT /lcov_base.info"
216
+
217
+ lcov --capture --directory " $OUTPUT_ROOT /obj/src" \
218
+ --exclude=" $PWD " /zzz_generated/* \
219
+ --exclude=" $PWD " /third_party/* \
220
+ --exclude=/usr/include/* \
221
+ --output-file " $COVERAGE_ROOT /lcov_test.info"
222
+
223
+ lcov --add-tracefile " $COVERAGE_ROOT /lcov_base.info" \
224
+ --add-tracefile " $COVERAGE_ROOT /lcov_test.info" \
225
+ --output-file " $COVERAGE_ROOT /lcov_final.info"
226
+
227
+ genhtml " $COVERAGE_ROOT /lcov_final.info" \
228
+ --output-directory " $COVERAGE_ROOT /html" \
229
+ --title " SHA:$( git rev-parse HEAD) " \
230
+ --header-title " Matter SDK Coverage Report"
231
+
232
+ cp " $CHIP_ROOT /integrations/appengine/webapp_config.yaml" \
233
+ " $COVERAGE_ROOT /webapp_config.yaml"
0 commit comments