From fba922ebe2b76ddac3f33454d284da4c6381db86 Mon Sep 17 00:00:00 2001 From: Zhanglong Xia Date: Thu, 1 Aug 2024 23:27:35 +0800 Subject: [PATCH] [test] test the Thread network 1 hop throughput (#10552) This commit adds a test case to the `cp-tests` to test the Thread network 1 hop throughput. --- tools/cp-caps/README.md | 12 +++++- tools/cp-caps/rcp_caps_test.py | 72 ++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/tools/cp-caps/README.md b/tools/cp-caps/README.md index 1614f3e1f..48ec8883b 100644 --- a/tools/cp-caps/README.md +++ b/tools/cp-caps/README.md @@ -54,7 +54,7 @@ Show help info. ```bash $ python3 ./tools/cp-caps/rcp_caps_test.py -h -usage: rcp_caps_test.py [-h] [-c] [-d] [-p] [-v] +usage: rcp_caps_test.py [-h] [-c] [-d] [-p] [-t] [-v] This script is used for testing RCP capabilities. @@ -63,6 +63,7 @@ options: -c, --csl test whether the RCP supports CSL transmitter -d, --diag-commands test whether the RCP supports all diag commands -p, --data-poll test whether the RCP supports data poll + -t, --throughput test the Thread network 1-hop throughput -v, --verbose output verbose information Device Interfaces: @@ -144,3 +145,12 @@ $ DUT_ADB_USB=1269UCKFZTAM95OR REF_CLI_SERIAL=/dev/ttyACM0 python3 ./tools/cp-ca Data Poll Parent ----------------------------------------- OK Data Poll Child ------------------------------------------ OK ``` + +### Test Throughput + +The parameter `-t` or `--throughput` starts to test the Thread network 1-hop throughput of the DUT. + +```bash +$ DUT_ADB_USB=1269UCKFZTAM95OR REF_ADB_USB=44061HFAG01AQK python3 ./tools/cp-caps/rcp_caps_test.py -t +Throughput ----------------------------------------------- 75.6 Kbits/sec +``` diff --git a/tools/cp-caps/rcp_caps_test.py b/tools/cp-caps/rcp_caps_test.py index f40e7e2c7..432777859 100644 --- a/tools/cp-caps/rcp_caps_test.py +++ b/tools/cp-caps/rcp_caps_test.py @@ -32,6 +32,7 @@ import logging import os import sys import textwrap +import threading from typing import List @@ -80,17 +81,77 @@ class RcpCaps(object): self.__dut.diag_stop() def test_csl(self): + """Test whether the DUT supports CSL transmitter.""" self.__dataset = self.__get_default_dataset() self.__test_csl_transmitter() def test_data_poll(self): + """Test whether the DUT supports data poll parent and child.""" self.__dataset = self.__get_default_dataset() self.__test_data_poll_parent() self.__test_data_poll_child() + def test_throughput(self): + """Test Thread network 1 hop throughput.""" + if not self.__dut.support_iperf3(): + print("The DUT doesn't support the tool iperf3") + return + + if not self.__ref.support_iperf3(): + print("The reference device doesn't support the tool iperf3") + return + + bitrate = 90000 + length = 1232 + transmit_time = 30 + max_wait_time = 30 + timeout = transmit_time + max_wait_time + + self.__dut.factory_reset() + self.__ref.factory_reset() + + dataset = self.__get_default_dataset() + + self.__dut.join(dataset) + self.__dut.wait_for('state', 'leader') + + self.__ref.set_router_selection_jitter(1) + self.__ref.join(dataset) + self.__ref.wait_for('state', ['child', 'router']) + + ref_mleid = self.__ref.get_ipaddr_mleid() + + ref_iperf3_server = threading.Thread(target=self.__ref_iperf3_server_task, + args=(ref_mleid, timeout), + daemon=True) + ref_iperf3_server.start() + self.__dut.wait(1) + + results = self.__dut.iperf3_client(host=ref_mleid, bitrate=bitrate, transmit_time=transmit_time, length=length) + ref_iperf3_server.join() + + if not results: + print('Failed to run the iperf3') + return + + self.__output_format_string('Throughput', self.__bitrate_to_string(results['receiver']['bitrate'])) + # # Private methods # + def __ref_iperf3_server_task(self, bind_address: str, timeout: int): + self.__ref.iperf3_server(bind_address, timeout=timeout) + + def __bitrate_to_string(self, bitrate: float): + units = ['bits/sec', 'Kbits/sec', 'Mbits/sec', 'Gbits/sec', 'Tbits/sec'] + unit_index = 0 + + while bitrate >= 1000 and unit_index < len(units) - 1: + bitrate /= 1000 + unit_index += 1 + + return f'{bitrate:.2f} {units[unit_index]}' + def __get_default_dataset(self): return self.__dut.create_dataset(channel=20, network_key='00112233445566778899aabbccddcafe') @@ -490,6 +551,14 @@ def parse_arguments(): help='test whether the RCP supports data poll', ) + parser.add_argument( + '-t', + '--throughput', + action='store_true', + default=False, + help='test Thread network 1-hop throughput', + ) + parser.add_argument( '-v', '--verbose', @@ -519,6 +588,9 @@ def main(): if arguments.data_poll is True: rcp_caps.test_data_poll() + if arguments.throughput: + rcp_caps.test_throughput() + if __name__ == '__main__': main()