Skip to content

Commit 4e057b7

Browse files
committed
Modified the builder script for efr32-brdxxxx-unit-test to generate the flashbundle for the whole set of tests, and fixed what files get copied to the artifacts directory.
1 parent 6a8641b commit 4e057b7

File tree

4 files changed

+61
-18
lines changed

4 files changed

+61
-18
lines changed

build/chip/chip_test_suite.gni

+13-11
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ template("chip_test_suite") {
5959
_target_type = "source_set"
6060
}
6161
target(_target_type, "${_suite_name}.lib") {
62-
forward_variables_from(invoker, "*", [ "tests", "test_sources" ])
62+
forward_variables_from(invoker,
63+
"*",
64+
[
65+
"tests",
66+
"test_sources",
67+
])
6368

6469
output_dir = "${root_out_dir}/lib"
6570

@@ -92,15 +97,12 @@ template("chip_test_suite") {
9297
pw_test(_test_name) {
9398
# Forward certain variables from the invoker.
9499
forward_variables_from(invoker,
95-
[
96-
"deps",
97-
"public_deps",
98-
"cflags",
99-
"configs",
100-
])
101-
102-
# Link to the common lib for this suite so we get its `sources`.
103-
public_deps += [ ":${_suite_name}.lib" ]
100+
[
101+
"deps",
102+
"public_deps",
103+
"cflags",
104+
"configs",
105+
])
104106

105107
# Set variables that the platform executable may need.
106108
if (test_executable_output_name != "") {
@@ -126,7 +128,7 @@ template("chip_test_suite") {
126128
deps += [ ":${_test}" ]
127129
}
128130

129-
# Add the common library.
131+
# Add the common lib for this suite so we get its `sources`.
130132
deps += [ ":${_suite_name}.lib" ]
131133
}
132134

scripts/build/builders/efr32.py

+45-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import glob
16+
import logging
1517
import os
1618
import shlex
1719
import subprocess
@@ -78,7 +80,7 @@ def FlashBundleName(self):
7880
elif self == Efr32App.PUMP:
7981
return 'pump_app.flashbundle.txt'
8082
elif self == Efr32App.UNIT_TEST:
81-
return 'efr32_device_tests.flashbundle.txt'
83+
return os.path.join('tests', 'efr32_device_tests.flashbundle.txt')
8284
else:
8385
raise Exception('Unknown app type: %r' % self)
8486

@@ -259,13 +261,44 @@ def __init__(self,
259261
def GnBuildArgs(self):
260262
return self.extra_gn_options
261263

264+
def _bundle(self):
265+
# Only unit-test needs to generate the flashbundle here. All other examples will generate a flashbundle via the silabs_executable template.
266+
if self.app == Efr32App.UNIT_TEST:
267+
flash_bundle_path = os.path.join(self.output_dir, self.app.FlashBundleName())
268+
logging.info(f'Generating flashbundle {flash_bundle_path}')
269+
270+
patterns = [
271+
os.path.join(self.output_dir, "tests", "*.flash.py"),
272+
os.path.join(self.output_dir, "tests", "*.s37"),
273+
os.path.join(self.output_dir, "tests", "silabs_firmware_utils.py"),
274+
os.path.join(self.output_dir, "tests", "firmware_utils.py"),
275+
]
276+
277+
# Generate the list of files by globbing each pattern.
278+
files = []
279+
for pattern in patterns:
280+
files += list(map(lambda x: os.path.basename(x), glob.glob(pattern)))
281+
282+
# Create the bundle file.
283+
with open(flash_bundle_path, 'w') as bundle_file:
284+
bundle_file.write("\n".join(files))
285+
262286
def build_outputs(self):
263287
extensions = ["out", "hex"]
264288
if self.options.enable_link_map_file:
265289
extensions.append("out.map")
266-
for ext in extensions:
267-
name = f"{self.app.AppNamePrefix()}.{ext}"
268-
yield BuilderOutput(os.path.join(self.output_dir, name), name)
290+
291+
if self.app == Efr32App.UNIT_TEST:
292+
# Efr32 unit-test generates the "tests" subdir with a set of files for each individual unit test source.
293+
for ext in extensions:
294+
pattern = os.path.join(self.output_dir, "tests", f"*.{ext}")
295+
for name in map(lambda x: os.path.basename(x), glob.glob(pattern)):
296+
yield BuilderOutput(os.path.join(self.output_dir, "tests", name), name)
297+
else:
298+
# All other examples have just one set of files.
299+
for ext in extensions:
300+
name = f"{self.app.AppNamePrefix()}.{ext}"
301+
yield BuilderOutput(os.path.join(self.output_dir, name), name)
269302

270303
if self.app == Efr32App.UNIT_TEST:
271304
# Include test runner python wheels
@@ -275,11 +308,17 @@ def build_outputs(self):
275308
os.path.join(root, file),
276309
os.path.join("chip_pw_test_runner_wheels", file))
277310

278-
# Figure out flash bundle files and build accordingly
311+
def bundle_outputs(self):
312+
# If flashbundle creation is enabled, the outputs will include the s37 and flash.py files, plus the two firmware utils scripts that support flash.py.
313+
# For the unit-test example, there will be a s37 and flash.py file for each unit test source.
279314
with open(os.path.join(self.output_dir, self.app.FlashBundleName())) as f:
280315
for name in filter(None, [x.strip() for x in f.readlines()]):
316+
if self.app == Efr32App.UNIT_TEST:
317+
sourcepath = os.path.join(self.output_dir, "tests", name) # Unit tests are in the "tests" subdir.
318+
else:
319+
sourcepath = os.path.join(self.output_dir, name)
281320
yield BuilderOutput(
282-
os.path.join(self.output_dir, name),
321+
sourcepath,
283322
os.path.join("flashbundle", name))
284323

285324
def generate(self):

src/test_driver/efr32/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ source_set("efr32_test_main") {
105105
include_dirs = [ "${chip_root}/examples/common/pigweed/efr32" ]
106106
}
107107

108+
# This target is referred to by BuildRoot in scripts/build/builders/efr32.py, as well as the example in README.md.
109+
# It builds the root target "src:tests", which builds the chip_test_suite target in each test directory, which builds a pw_test target for each test source file, which builds a silabs_executable, which includes the "efr32_test_main" target defined above.
108110
group("efr32") {
109111
deps = [ "${chip_root}/src:tests" ]
110112
}

src/test_driver/efr32/args.gni

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pw_unit_test_EXECUTABLE_TARGET_TYPE_FILE =
4343
pw_unit_test_MAIN = "//:efr32_test_main"
4444

4545
# Additional variables needed by silabs_executable that must be passed in to pw_test.
46-
test_executable_output_name = "matter-silabs-device_tests_"
46+
test_executable_output_name = "matter-silabs-device_tests-"
4747
test_executable_output_name_suffix = ".out"
4848
_ldscript =
4949
"${chip_root}/examples/platform/silabs/ldscripts/${silabs_family}.ld"

0 commit comments

Comments
 (0)