Skip to content

Commit fa92b5c

Browse files
committed
Removed NL infrastructure
1 parent 55e748a commit fa92b5c

File tree

15 files changed

+145
-338
lines changed

15 files changed

+145
-338
lines changed

scripts/build/builders/efr32.py

-6
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,6 @@ def build_outputs(self):
277277
for file in files:
278278
items["chip_pw_test_runner_wheels/" +
279279
file] = os.path.join(root, file)
280-
# TODO [PW_MIGRATION]: remove the nl wheels once transition away from nlunit-test is completed
281-
for root, dirs, files in os.walk(os.path.join(self.output_dir, 'chip_nl_test_runner_wheels')):
282-
for file in files:
283-
yield BuilderOutput(
284-
os.path.join(root, file),
285-
os.path.join("chip_nl_test_runner_wheels", file))
286280

287281
# Figure out flash bundle files and build accordingly
288282
with open(os.path.join(self.output_dir, self.app.FlashBundleName())) as f:

scripts/build/builders/host.py

-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ def OutputNames(self):
217217
yield 'controller/python' # Directory containing WHL files
218218
elif self == HostApp.EFR32_TEST_RUNNER:
219219
yield 'chip_pw_test_runner_wheels'
220-
yield 'chip_nl_test_runner_wheels'
221220
elif self == HostApp.TV_CASTING:
222221
yield 'chip-tv-casting-app'
223222
yield 'chip-tv-casting-app.map'

src/test_driver/efr32/BUILD.gn

-3
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ group("runner") {
132132
deps = [
133133
"${efr32_project_dir}/py:pw_test_runner.install",
134134
"${efr32_project_dir}/py:pw_test_runner_wheel",
135-
# TODO [PW_MIGRATION]: remove the following when transition from nlunit-test is complete.
136-
"${efr32_project_dir}/py:nl_test_runner.install",
137-
"${efr32_project_dir}/py:nl_test_runner_wheel",
138135
]
139136
}
140137

src/test_driver/efr32/py/BUILD.gn

+2-27
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,13 @@ 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
23-
pw_python_package("nl_test_runner") {
22+
pw_python_package("pw_test_runner") {
2423
setup = [
2524
"pyproject.toml",
2625
"setup.cfg",
2726
"setup.py",
2827
]
2928

30-
sources = [
31-
"nl_test_runner/__init__.py",
32-
"nl_test_runner/nl_test_runner.py",
33-
]
34-
35-
python_deps = [
36-
"$dir_pw_hdlc/py",
37-
"$dir_pw_protobuf_compiler/py",
38-
"$dir_pw_rpc/py",
39-
"${chip_root}/src/test_driver/efr32:nl_test_service.python",
40-
]
41-
}
42-
43-
pw_python_wheels("nl_test_runner_wheel") {
44-
packages = [ ":nl_test_runner" ]
45-
directory = "$root_out_dir/chip_nl_test_runner_wheels"
46-
}
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-
5529
sources = [
5630
"pw_test_runner/__init__.py",
5731
"pw_test_runner/pw_test_runner.py",
@@ -61,6 +35,7 @@ pw_python_package("pw_test_runner") {
6135
"$dir_pw_hdlc/py",
6236
"$dir_pw_protobuf_compiler/py",
6337
"$dir_pw_rpc/py",
38+
#"${chip_root}/src/test_driver/efr32:nl_test_service.python", #++++ is this still needed?
6439
]
6540
}
6641

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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 glob
20+
import logging
21+
import os
22+
import subprocess
23+
import sys
24+
import time
25+
from pathlib import Path
26+
from typing import Any
27+
28+
import serial # type: ignore
29+
from pw_hdlc import rpc
30+
from pw_unit_test.rpc import run_tests
31+
32+
PW_LOG = logging.getLogger(__name__)
33+
34+
PROTO = Path(os.environ["PW_ROOT"],
35+
"pw_unit_test/pw_unit_test_proto/unit_test.proto")
36+
37+
38+
class colors:
39+
HEADER = "\033[95m"
40+
OKBLUE = "\033[94m"
41+
OKCYAN = "\033[96m"
42+
OKGREEN = "\033[92m"
43+
WARNING = "\033[93m"
44+
FAIL = "\033[91m"
45+
ENDC = "\033[0m"
46+
BOLD = "\033[1m"
47+
48+
49+
PASS_STRING = colors.OKGREEN + "\N{check mark}" + colors.ENDC
50+
FAIL_STRING = colors.FAIL + "FAILED" + colors.ENDC
51+
52+
53+
def _parse_args():
54+
"""Parses and returns the command line arguments."""
55+
parser = argparse.ArgumentParser(
56+
description="CHIP on device unit test runner.")
57+
parser.add_argument("-d", "--device", help="the serial port to use")
58+
parser.add_argument(
59+
"-b", "--baudrate", type=int, default=115200, help="the baud rate to use"
60+
)
61+
parser.add_argument(
62+
"-f",
63+
"--flash_image",
64+
help="A firmware image which will be flashed berfore runnning the test. Or a directory containing firmware images, each of which will be flashed and then run.",
65+
)
66+
parser.add_argument(
67+
"-o",
68+
"--output",
69+
type=argparse.FileType("wb"),
70+
default=sys.stdout.buffer,
71+
help=(
72+
"The file to which to write device output (HDLC channel 1); "
73+
"provide - or omit for stdout."
74+
),
75+
)
76+
return parser.parse_args()
77+
78+
79+
def flash_device(device: str, flash_image: str):
80+
"""flashes the EFR32 device using commander"""
81+
err = subprocess.call(
82+
["commander", "flash", "--device", "EFR32", flash_image])
83+
if err:
84+
raise Exception("flash failed")
85+
86+
87+
def get_hdlc_rpc_client(device: str, baudrate: int, output: Any, **kwargs):
88+
"""Get the HdlcRpcClient based on arguments."""
89+
serial_device = serial.Serial(device, baudrate, timeout=1)
90+
reader = rpc.SerialReader(serial_device, 8192)
91+
write = serial_device.write
92+
return rpc.HdlcRpcClient(
93+
reader,
94+
PROTO,
95+
rpc.default_channels(write),
96+
lambda data: rpc.write_to_file(data, output),
97+
)
98+
99+
100+
def run(args) -> int:
101+
"""Run the tests. Return the number of failed tests."""
102+
with get_hdlc_rpc_client(**vars(args)) as client:
103+
test_records = run_tests(client.rpcs())
104+
return len(test_records.failing_tests)
105+
106+
107+
def list_images(flash_directory: str) -> list[str]:
108+
filenames: list[str] = glob.glob(os.path.join(flash_directory, "*.s37"))
109+
return list(map(lambda x: os.path.join(flash_directory, x), filenames))
110+
111+
112+
def main() -> int:
113+
args = _parse_args()
114+
115+
failures = 0
116+
if args.flash_image:
117+
if os.path.isdir(args.flash_image):
118+
images = list_images(args.flash_image)
119+
if not images:
120+
raise Exception(f"No images found in `{args.flash_image}`")
121+
elif os.path.isdir(args.flash_image):
122+
images = [args.flash_image]
123+
else:
124+
raise Exception(f"File or directory not found `{args.flash_image}`")
125+
126+
for image in images:
127+
flash_device(args.device, image)
128+
time.sleep(1) # Give time for device to boot
129+
130+
failures += run(args)
131+
else: # No image provided. Just run what's on the device.
132+
failures += run(args)
133+
134+
return failures
135+
136+
137+
if __name__ == "__main__":
138+
sys.exit(main())

src/test_driver/efr32/py/nl_test_runner/__init__.py

Whitespace-only changes.

src/test_driver/efr32/py/nl_test_runner/nl_test_runner.py

-141
This file was deleted.

src/test_driver/efr32/py/pw_test_runner/pyproject.toml

-16
This file was deleted.

src/test_driver/efr32/py/pw_test_runner/setup.cfg

-20
This file was deleted.

0 commit comments

Comments
 (0)