Skip to content

Commit 4726936

Browse files
authored
Add Pigweed support for efr32 (#32506)
* Add Pigweed support for efr32 * Remove manual test call * Date update
1 parent 0ea614e commit 4726936

File tree

10 files changed

+211
-2
lines changed

10 files changed

+211
-2
lines changed

src/BUILD.gn

+2-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ if (chip_build_tests) {
145145
# TODO [PW_MIGRATION] There will be a list of already migrated platforms
146146
if (chip_device_platform == "esp32" ||
147147
chip_device_platform == "nrfconnect" ||
148-
chip_device_platform == "openiotsdk") {
148+
chip_device_platform == "openiotsdk" ||
149+
chip_device_platform == "efr32") {
149150
deps += [ "${chip_root}/src/lib/support:pw_tests_wrapper" ]
150151
}
151152
build_monolithic_library = true

src/test_driver/efr32/.gn

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import("//build_overrides/build.gni")
16+
import("//build_overrides/pigweed.gni")
1617

1718
# The location of the build configuration file.
1819
buildconfig = "${build_root}/config/BUILDCONFIG.gn"

src/test_driver/efr32/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ silabs_executable("efr32_device_tests") {
8080
deps = [
8181
":nl_test_service.nanopb_rpc",
8282
":sdk",
83+
"$dir_pw_unit_test:rpc_service",
8384
"${chip_root}/config/efr32/lib/pw_rpc:pw_rpc",
8485
"${chip_root}/examples/common/pigweed:system_rpc_server",
8586
"${chip_root}/src:tests",
8687
"${chip_root}/src/lib",
88+
"${chip_root}/src/lib/support:pw_tests_wrapper",
8789
"${chip_root}/src/lib/support:testing_nlunit",
8890
"${examples_common_plat_dir}/pw_sys_io:pw_sys_io_silabs",
8991
"${nlunit_test_root}:nlunit-test",

src/test_driver/efr32/args.gni

+5
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ openthread_external_platform =
3030
"${chip_root}/third_party/openthread/platforms/efr32:libopenthread-efr32"
3131

3232
pw_rpc_CONFIG = "$dir_pw_rpc:disable_global_mutex"
33+
34+
pw_assert_BACKEND = "$dir_pw_assert_log"
35+
pw_log_BACKEND = "$dir_pw_log_basic"
36+
37+
pw_unit_test_BACKEND = "$dir_pw_unit_test:light"

src/test_driver/efr32/py/BUILD.gn

+25
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import("$dir_pw_build/python.gni")
1919
import("$dir_pw_build/python_dist.gni")
2020
import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")
2121

22+
# TODO [PW_MIGRATION]: remove nl test runner script once transition away from nlunit-test is completed
2223
pw_python_package("nl_test_runner") {
2324
setup = [
2425
"pyproject.toml",
@@ -43,3 +44,27 @@ pw_python_wheels("nl_test_runner_wheel") {
4344
packages = [ ":nl_test_runner" ]
4445
directory = "$root_out_dir/chip_nl_test_runner_wheels"
4546
}
47+
48+
pw_python_package("pw_test_runner") {
49+
setup = [
50+
"pw_test_runner/pyproject.toml",
51+
"pw_test_runner/setup.cfg",
52+
"pw_test_runner/setup.py",
53+
]
54+
55+
sources = [
56+
"pw_test_runner/__init__.py",
57+
"pw_test_runner/pw_test_runner.py",
58+
]
59+
60+
python_deps = [
61+
"$dir_pw_hdlc/py",
62+
"$dir_pw_protobuf_compiler/py",
63+
"$dir_pw_rpc/py",
64+
]
65+
}
66+
67+
pw_python_wheels("pw_test_runner_wheel") {
68+
packages = [ ":pw_test_runner" ]
69+
directory = "$root_out_dir/chip_pw_test_runner_wheels"
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#
2+
# Copyright (c) 2024 Project CHIP Authors
3+
# All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
import argparse
19+
import logging
20+
import os
21+
import subprocess
22+
import sys
23+
import time
24+
from pathlib import Path
25+
from typing import Any
26+
27+
import serial # type: ignore
28+
from pw_hdlc import rpc
29+
from pw_unit_test.rpc import run_tests
30+
31+
PW_LOG = logging.getLogger(__name__)
32+
33+
PROTO = Path(os.environ["PW_ROOT"],
34+
"pw_unit_test/pw_unit_test_proto/unit_test.proto")
35+
36+
37+
class colors:
38+
HEADER = "\033[95m"
39+
OKBLUE = "\033[94m"
40+
OKCYAN = "\033[96m"
41+
OKGREEN = "\033[92m"
42+
WARNING = "\033[93m"
43+
FAIL = "\033[91m"
44+
ENDC = "\033[0m"
45+
BOLD = "\033[1m"
46+
47+
48+
PASS_STRING = colors.OKGREEN + "\N{check mark}" + colors.ENDC
49+
FAIL_STRING = colors.FAIL + "FAILED" + colors.ENDC
50+
51+
52+
def _parse_args():
53+
"""Parses and returns the command line arguments."""
54+
parser = argparse.ArgumentParser(
55+
description="CHIP on device unit test runner.")
56+
parser.add_argument("-d", "--device", help="the serial port to use")
57+
parser.add_argument(
58+
"-b", "--baudrate", type=int, default=115200, help="the baud rate to use"
59+
)
60+
parser.add_argument(
61+
"-f",
62+
"--flash_image",
63+
help="a firmware image which will be flashed berfore runnning the test",
64+
)
65+
parser.add_argument(
66+
"-o",
67+
"--output",
68+
type=argparse.FileType("wb"),
69+
default=sys.stdout.buffer,
70+
help=(
71+
"The file to which to write device output (HDLC channel 1); "
72+
"provide - or omit for stdout."
73+
),
74+
)
75+
return parser.parse_args()
76+
77+
78+
def flash_device(device: str, flash_image: str, **kwargs):
79+
"""flashes the EFR32 device using commander"""
80+
err = subprocess.call(
81+
["commander", "flash", "--device", "EFR32", flash_image])
82+
if err:
83+
raise Exception("flash failed")
84+
85+
86+
def get_hdlc_rpc_client(device: str, baudrate: int, output: Any, **kwargs):
87+
"""Get the HdlcRpcClient based on arguments."""
88+
serial_device = serial.Serial(device, baudrate, timeout=1)
89+
reader = rpc.SerialReader(serial_device, 8192)
90+
write = serial_device.write
91+
return rpc.HdlcRpcClient(
92+
reader,
93+
PROTO,
94+
rpc.default_channels(write),
95+
lambda data: rpc.write_to_file(data, output),
96+
)
97+
98+
99+
def runner(client: rpc.HdlcRpcClient) -> int:
100+
"""Run the tests"""
101+
102+
test_records = run_tests(client.rpcs())
103+
104+
return len(test_records.failing_tests)
105+
106+
107+
def main() -> int:
108+
args = _parse_args()
109+
if args.flash_image:
110+
flash_device(**vars(args))
111+
time.sleep(1) # Give time for device to boot
112+
113+
with get_hdlc_rpc_client(**vars(args)) as client:
114+
return runner(client)
115+
116+
117+
if __name__ == "__main__":
118+
sys.exit(main())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
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
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
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.
14+
[build-system]
15+
requires = ['setuptools', 'wheel']
16+
build-backend = 'setuptools.build_meta'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
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
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
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.
14+
[metadata]
15+
name = pw_test_runner
16+
version = 0.0.1
17+
18+
[options]
19+
packages = find:
20+
zip_safe = False
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
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
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
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.
14+
15+
import setuptools # type: ignore
16+
17+
setuptools.setup() # Package definition in setup.cfg

src/test_driver/efr32/src/main.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18+
// TODO To prevent config with nl headers has to be included before nl test headers
19+
#include <pw_unit_test/unit_test_service.h>
20+
1821
#include <AppConfig.h>
1922
#include <FreeRTOS.h>
2023
#include <PigweedLogger.h>
@@ -166,10 +169,11 @@ StaticTask_t sTestTaskBuffer;
166169
StackType_t sTestTaskStack[TEST_TASK_STACK_SIZE];
167170

168171
chip::rpc::NlTest nl_test_service;
172+
pw::unit_test::UnitTestService unit_test_service;
169173

170174
void RegisterServices(pw::rpc::Server & server)
171175
{
172-
server.RegisterService(nl_test_service);
176+
server.RegisterService(nl_test_service, unit_test_service);
173177
}
174178

175179
void RunRpcService(void *)

0 commit comments

Comments
 (0)