mirror of
https://github.com/espressif/esp-idf.git
synced 2026-04-27 19:13:21 +00:00
Merge branch 'feat/update_wifi_iperf_example' into 'master'
Feat: update iperf examples See merge request espressif/esp-idf!44705
This commit is contained in:
@@ -3,7 +3,30 @@
|
||||
components/esp_wifi/test_apps/:
|
||||
disable:
|
||||
- if: SOC_WIFI_SUPPORTED != 1
|
||||
depends_components:
|
||||
- esp_hw_support
|
||||
- esp_rom
|
||||
- esp_system
|
||||
- esp_timer
|
||||
- freertos
|
||||
- esp_event
|
||||
- esp_wifi
|
||||
- esp_phy
|
||||
- esp_netif
|
||||
- esp_coex
|
||||
- wpa_supplicant
|
||||
- mbedtls
|
||||
- esp_pm
|
||||
|
||||
components/esp_wifi/test_apps/wifi_nvs_config:
|
||||
disable:
|
||||
- if: SOC_WIFI_SUPPORTED != 1
|
||||
depends_components:
|
||||
- esp_hw_support
|
||||
- esp_rom
|
||||
- esp_system
|
||||
- esp_timer
|
||||
- freertos
|
||||
- esp_event
|
||||
- nvs_flash
|
||||
- esp_wifi
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Iperf example - wifi commands
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@@ -18,21 +18,6 @@
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_netif.h"
|
||||
#include "iperf.h"
|
||||
|
||||
typedef struct {
|
||||
struct arg_str *ip;
|
||||
struct arg_lit *server;
|
||||
struct arg_lit *udp;
|
||||
struct arg_lit *version;
|
||||
struct arg_int *port;
|
||||
struct arg_int *length;
|
||||
struct arg_int *interval;
|
||||
struct arg_int *time;
|
||||
struct arg_lit *abort;
|
||||
struct arg_end *end;
|
||||
} wifi_iperf_t;
|
||||
static wifi_iperf_t iperf_args;
|
||||
|
||||
typedef struct {
|
||||
struct arg_str *ssid;
|
||||
@@ -293,124 +278,6 @@ static int wifi_cmd_query(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t wifi_get_local_ip(void)
|
||||
{
|
||||
int bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0);
|
||||
esp_netif_t *ifx = ap_netif;
|
||||
esp_netif_ip_info_t ip_info;
|
||||
wifi_mode_t mode;
|
||||
|
||||
esp_wifi_get_mode(&mode);
|
||||
if (WIFI_MODE_STA == mode) {
|
||||
bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0);
|
||||
if (bits & CONNECTED_BIT) {
|
||||
ifx = sta_netif;
|
||||
} else {
|
||||
ESP_LOGE(TAG, "sta has no IP");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
esp_netif_get_ip_info(ifx, &ip_info);
|
||||
return ip_info.ip.addr;
|
||||
}
|
||||
|
||||
static int wifi_cmd_iperf(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse(argc, argv, (void **) &iperf_args);
|
||||
iperf_cfg_t cfg;
|
||||
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, iperf_args.end, argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
|
||||
// wifi iperf only support IPV4 address
|
||||
cfg.type = IPERF_IP_TYPE_IPV4;
|
||||
|
||||
if ( iperf_args.abort->count != 0) {
|
||||
iperf_stop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( ((iperf_args.ip->count == 0) && (iperf_args.server->count == 0)) ||
|
||||
((iperf_args.ip->count != 0) && (iperf_args.server->count != 0)) ) {
|
||||
ESP_LOGE(TAG, "should specific client/server mode");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (iperf_args.ip->count == 0) {
|
||||
cfg.flag |= IPERF_FLAG_SERVER;
|
||||
} else {
|
||||
cfg.destination_ip4 = esp_ip4addr_aton(iperf_args.ip->sval[0]);
|
||||
cfg.flag |= IPERF_FLAG_CLIENT;
|
||||
}
|
||||
|
||||
cfg.source_ip4 = wifi_get_local_ip();
|
||||
if (cfg.source_ip4 == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (iperf_args.length->count == 0) {
|
||||
cfg.len_send_buf = 0;
|
||||
} else {
|
||||
cfg.len_send_buf = iperf_args.length->ival[0];
|
||||
}
|
||||
|
||||
if (iperf_args.udp->count == 0) {
|
||||
cfg.flag |= IPERF_FLAG_TCP;
|
||||
} else {
|
||||
cfg.flag |= IPERF_FLAG_UDP;
|
||||
}
|
||||
|
||||
if (iperf_args.port->count == 0) {
|
||||
cfg.sport = IPERF_DEFAULT_PORT;
|
||||
cfg.dport = IPERF_DEFAULT_PORT;
|
||||
} else {
|
||||
if (cfg.flag & IPERF_FLAG_SERVER) {
|
||||
cfg.sport = iperf_args.port->ival[0];
|
||||
cfg.dport = IPERF_DEFAULT_PORT;
|
||||
} else {
|
||||
cfg.sport = IPERF_DEFAULT_PORT;
|
||||
cfg.dport = iperf_args.port->ival[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (iperf_args.interval->count == 0) {
|
||||
cfg.interval = IPERF_DEFAULT_INTERVAL;
|
||||
} else {
|
||||
cfg.interval = iperf_args.interval->ival[0];
|
||||
if (cfg.interval <= 0) {
|
||||
cfg.interval = IPERF_DEFAULT_INTERVAL;
|
||||
}
|
||||
}
|
||||
|
||||
if (iperf_args.time->count == 0) {
|
||||
cfg.time = IPERF_DEFAULT_TIME;
|
||||
} else {
|
||||
cfg.time = iperf_args.time->ival[0];
|
||||
if (cfg.time <= cfg.interval) {
|
||||
cfg.time = cfg.interval;
|
||||
}
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "mode=%s-%s sip=%" PRIu32 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32 ":%d, \
|
||||
dip=%" PRIu32 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32 ":%d, interval=%" PRIu32 ", time=%" PRIu32,
|
||||
cfg.flag & IPERF_FLAG_TCP ? "tcp" : "udp",
|
||||
cfg.flag & IPERF_FLAG_SERVER ? "server" : "client",
|
||||
cfg.source_ip4 & 0xFF, (cfg.source_ip4 >> 8) & 0xFF, (cfg.source_ip4 >> 16) & 0xFF,
|
||||
(cfg.source_ip4 >> 24) & 0xFF, cfg.sport,
|
||||
cfg.destination_ip4 & 0xFF, (cfg.destination_ip4 >> 8) & 0xFF, (cfg.destination_ip4 >> 16) & 0xFF,
|
||||
(cfg.destination_ip4 >> 24) & 0xFF, cfg.dport,
|
||||
cfg.interval, cfg.time);
|
||||
|
||||
iperf_start(&cfg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int restart(int argc, char **argv)
|
||||
{
|
||||
ESP_LOGI(TAG, "Restarting");
|
||||
@@ -484,26 +351,6 @@ void register_wifi(void)
|
||||
};
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&restart_cmd) );
|
||||
|
||||
iperf_args.ip = arg_str0("c", "client", "<ip>", "run in client mode, connecting to <host>");
|
||||
iperf_args.server = arg_lit0("s", "server", "run in server mode");
|
||||
iperf_args.udp = arg_lit0("u", "udp", "use UDP rather than TCP");
|
||||
iperf_args.version = arg_lit0("V", "ipv6_domain", "use IPV6 address rather than IPV4");
|
||||
iperf_args.port = arg_int0("p", "port", "<port>", "server port to listen on/connect to");
|
||||
iperf_args.length = arg_int0("l", "len", "<length>", "set read/write buffer size");
|
||||
iperf_args.interval = arg_int0("i", "interval", "<interval>", "seconds between periodic bandwidth reports");
|
||||
iperf_args.time = arg_int0("t", "time", "<time>", "time in seconds to transmit for (default 10 secs)");
|
||||
iperf_args.abort = arg_lit0("a", "abort", "abort running iperf");
|
||||
iperf_args.end = arg_end(1);
|
||||
const esp_console_cmd_t iperf_cmd = {
|
||||
.command = "iperf",
|
||||
.help = "iperf command",
|
||||
.hint = NULL,
|
||||
.func = &wifi_cmd_iperf,
|
||||
.argtable = &iperf_args
|
||||
};
|
||||
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&iperf_cmd) );
|
||||
|
||||
const esp_console_cmd_t heap_cmd = {
|
||||
.command = "heap",
|
||||
.help = "get min free heap size during test",
|
||||
|
||||
@@ -3,5 +3,5 @@ dependencies:
|
||||
path: ${IDF_PATH}/examples/bluetooth/esp_ble_mesh/common_components/fast_prov
|
||||
example_init:
|
||||
path: ${IDF_PATH}/examples/bluetooth/esp_ble_mesh/common_components/example_init
|
||||
espressif/iperf:
|
||||
version: "~0.1.1"
|
||||
espressif/iperf-cmd:
|
||||
version: "^1.0.2"
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
#include "ble_mesh_fast_prov_server_model.h"
|
||||
#include "ble_mesh_example_init.h"
|
||||
|
||||
#include "iperf_cmd.h"
|
||||
|
||||
#define TAG "EXAMPLE"
|
||||
|
||||
extern struct _led_state led_state[3];
|
||||
@@ -772,6 +774,7 @@ static void wifi_console_init(void)
|
||||
|
||||
/* Register commands */
|
||||
register_wifi();
|
||||
iperf_cmd_register_iperf();
|
||||
|
||||
printf("\n ==================================================\n");
|
||||
printf(" | Steps to test WiFi throughput |\n");
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ This demo demonstrates the Wi-Fi and Bluetooth (BLE/BR/EDR) coexistence feature
|
||||
* The Bluetooth function is demonstrated by the fast provisioning function. Details can be seen in `fast_prov_server`.
|
||||
|
||||
|
||||
> Note: In this demo, you call wifi API and bluetooth API to achieve the functions you want. such as `wifi_get_local_ip` API and `esp_ble_mesh_provisioner_add_unprov_dev` API.
|
||||
> Note: In this demo, you call wifi API and bluetooth API to achieve the functions you want. such as `esp_wifi_sta_get_ap_info` API and `esp_ble_mesh_provisioner_add_unprov_dev` API.
|
||||
|
||||
# What You Need
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ void app_main(void)
|
||||
|
||||
/* Register commands */
|
||||
register_system_common();
|
||||
app_register_iperf_commands();
|
||||
iperf_cmd_register_iperf();
|
||||
register_ethernet_commands();
|
||||
|
||||
printf("\n =======================================================\n");
|
||||
|
||||
@@ -2,6 +2,6 @@ dependencies:
|
||||
cmd_system:
|
||||
path: ${IDF_PATH}/examples/system/console/advanced/components/cmd_system
|
||||
espressif/ethernet_init:
|
||||
version: "~1.2.0"
|
||||
version: "~1.3.0"
|
||||
espressif/iperf-cmd:
|
||||
version: "~0.1.1"
|
||||
version: "~1.0.2"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
espressif/iperf-cmd: "^1.0.0"
|
||||
espressif/iperf-cmd: "^1.0.2"
|
||||
cmd_system:
|
||||
path: ${IDF_PATH}/examples/system/console/advanced/components/cmd_system
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
idf_component_register(SRCS "station_example_main.c"
|
||||
PRIV_REQUIRES esp_wifi nvs_flash bt
|
||||
PRIV_REQUIRES esp_wifi nvs_flash
|
||||
INCLUDE_DIRS ".")
|
||||
|
||||
@@ -2,7 +2,7 @@ dependencies:
|
||||
cmd_system:
|
||||
path: ${IDF_PATH}/examples/system/console/advanced/components/cmd_system
|
||||
espressif/iperf-cmd:
|
||||
version: "~0.1.3"
|
||||
version: "~1.0.2"
|
||||
esp-qa/wifi-cmd:
|
||||
version: "~0.2.7"
|
||||
esp-qa/ping-cmd:
|
||||
|
||||
@@ -39,29 +39,29 @@ extern int wifi_cmd_clr_rx_statistics(int argc, char **argv);
|
||||
#include "esp_extconn.h"
|
||||
#endif
|
||||
|
||||
void iperf_hook_show_wifi_stats(iperf_traffic_type_t type, iperf_status_t status)
|
||||
void iperf_hook_show_wifi_stats(iperf_id_t instance_id, iperf_state_data_t *data, void *priv)
|
||||
{
|
||||
if (status == IPERF_STARTED) {
|
||||
if (data->state == IPERF_STARTED) {
|
||||
#if CONFIG_ESP_WIFI_ENABLE_WIFI_TX_STATS
|
||||
if (type != IPERF_UDP_SERVER) {
|
||||
if (data->traffic_type != IPERF_UDP_SERVER) {
|
||||
wifi_cmd_clr_tx_statistics(0, NULL);
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_ESP_WIFI_ENABLE_WIFI_RX_STATS
|
||||
if (type != IPERF_UDP_CLIENT) {
|
||||
if (data->traffic_type != IPERF_UDP_CLIENT) {
|
||||
wifi_cmd_clr_rx_statistics(0, NULL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (status == IPERF_STOPPED) {
|
||||
if (data->state == IPERF_STOPPED) {
|
||||
#if CONFIG_ESP_WIFI_ENABLE_WIFI_TX_STATS
|
||||
if (type != IPERF_UDP_SERVER) {
|
||||
if (data->traffic_type != IPERF_UDP_SERVER) {
|
||||
wifi_cmd_get_tx_statistics(0, NULL);
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_ESP_WIFI_ENABLE_WIFI_RX_STATS
|
||||
if (type != IPERF_UDP_CLIENT) {
|
||||
if (data->traffic_type != IPERF_UDP_CLIENT) {
|
||||
wifi_cmd_get_rx_statistics(0, NULL);
|
||||
}
|
||||
#endif
|
||||
@@ -132,8 +132,8 @@ void app_main(void)
|
||||
/* From wifi-cmd */
|
||||
wifi_cmd_register_all();
|
||||
/* From iperf-cmd */
|
||||
app_register_iperf_commands();
|
||||
app_register_iperf_hook_func(iperf_hook_show_wifi_stats);
|
||||
iperf_cmd_register_iperf();
|
||||
iperf_cmd_set_iperf_state_handler(iperf_hook_show_wifi_stats, NULL);
|
||||
/* From ping-cmd */
|
||||
ping_cmd_register_ping();
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
CONFIG_LWIP_EXTRA_IRAM_OPTIMIZATION=y
|
||||
|
||||
@@ -9,8 +9,6 @@ CONFIG_ESP_TASK_WDT_EN=n
|
||||
CONFIG_LWIP_IRAM_OPTIMIZATION=y
|
||||
CONFIG_LWIP_TCPIP_TASK_PRIO=23
|
||||
|
||||
CONFIG_IPERF_TRAFFIC_TASK_PRIORITY=23
|
||||
CONFIG_IPERF_REPORT_TASK_PRIORITY=24
|
||||
CONFIG_COMPILER_OPTIMIZATION_PERF=y
|
||||
|
||||
CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import logging
|
||||
import os
|
||||
@@ -13,7 +13,6 @@ from idf_iperf_test_util import LineChart
|
||||
|
||||
try:
|
||||
from typing import Any
|
||||
from typing import Tuple
|
||||
except ImportError:
|
||||
# Only used for type annotations
|
||||
pass
|
||||
@@ -31,7 +30,7 @@ INVALID_HEAP_SIZE = 0xFFFFFFFF
|
||||
PC_IPERF_TEMP_LOG_FILE = '.tmp_iperf.log'
|
||||
|
||||
|
||||
class TestResult(object):
|
||||
class TestResult:
|
||||
"""record, analysis test result and convert data to output format"""
|
||||
|
||||
PC_BANDWIDTH_LOG_PATTERN = re.compile(r'(\d+\.\d+)\s*-\s*(\d+.\d+)\s+sec\s+[\d.]+\s+MBytes\s+([\d.]+)\s+Mbits\/sec')
|
||||
@@ -119,24 +118,21 @@ class TestResult(object):
|
||||
if throughput == 0 and rssi > self.ZERO_POINT_THRESHOLD and fall_to_0_recorded < 1:
|
||||
# throughput fall to 0 error. we only record 1 records for one test
|
||||
self.error_list.append(
|
||||
'[Error][fall to 0][{}][att: {}][rssi: {}]: 0 throughput interval: {}-{}'.format(
|
||||
ap_ssid, att, rssi, result[0], result[1]
|
||||
)
|
||||
f'[Error][fall to 0][{ap_ssid}][att: {att}][rssi: {rssi}]: 0 '
|
||||
f'throughput interval: {result[0]}-{result[1]}'
|
||||
)
|
||||
fall_to_0_recorded += 1
|
||||
|
||||
if len(throughput_list) < self.THROUGHPUT_QUALIFY_COUNT:
|
||||
self.error_list.append(
|
||||
'[Error][Fatal][{}][att: {}][rssi: {}]: Only {} throughput values found, expected at least {}'.format(
|
||||
ap_ssid, att, rssi, len(throughput_list), self.THROUGHPUT_QUALIFY_COUNT
|
||||
)
|
||||
f'[Error][Fatal][{ap_ssid}][att: {att}][rssi: {rssi}]: '
|
||||
f'Only {len(throughput_list)} throughput values found, '
|
||||
f'expected at least {self.THROUGHPUT_QUALIFY_COUNT}'
|
||||
)
|
||||
max_throughput = 0.0
|
||||
|
||||
if max_throughput == 0 and rssi > self.ZERO_THROUGHPUT_THRESHOLD:
|
||||
self.error_list.append(
|
||||
'[Error][Fatal][{}][att: {}][rssi: {}]: No throughput data found'.format(ap_ssid, att, rssi)
|
||||
)
|
||||
self.error_list.append(f'[Error][Fatal][{ap_ssid}][att: {att}][rssi: {rssi}]: No throughput data found')
|
||||
|
||||
self._save_result(max_throughput, ap_ssid, att, rssi, heap_size)
|
||||
|
||||
@@ -167,9 +163,8 @@ class TestResult(object):
|
||||
_percentage = result_dict[index_value] / result_dict[index_list[i]]
|
||||
if _percentage < 1 - self.BAD_POINT_PERCENTAGE_THRESHOLD:
|
||||
self.error_list.append(
|
||||
'[Error][Bad point][{}][{}: {}]: drop {:.02f}%'.format(
|
||||
ap_ssid, index_type, index_value, (1 - _percentage) * 100
|
||||
)
|
||||
f'[Error][Bad point][{ap_ssid}][{index_type}: {index_value}]: '
|
||||
f'drop {(1 - _percentage) * 100:.02f}%'
|
||||
)
|
||||
|
||||
analysis_bad_point(self.throughput_by_rssi, 'rssi')
|
||||
@@ -193,14 +188,14 @@ class TestResult(object):
|
||||
else:
|
||||
raise AssertionError('draw type not supported')
|
||||
if isinstance(ap_ssid, list):
|
||||
file_name = 'ThroughputVs{}_{}_{}.html'.format(type_name, self.proto, self.direction)
|
||||
file_name = f'ThroughputVs{type_name}_{self.proto}_{self.direction}.html'
|
||||
else:
|
||||
file_name = 'ThroughputVs{}_{}_{}.html'.format(type_name, self.proto, self.direction)
|
||||
file_name = f'ThroughputVs{type_name}_{self.proto}_{self.direction}.html'
|
||||
|
||||
LineChart.draw_line_chart(
|
||||
os.path.join(path, file_name),
|
||||
'Throughput Vs {} ({} {})'.format(type_name, self.proto, self.direction),
|
||||
'{} (dbm)'.format(type_name),
|
||||
f'Throughput Vs {type_name} ({self.proto} {self.direction})',
|
||||
f'{type_name} (dbm)',
|
||||
'Throughput (Mbps)',
|
||||
data,
|
||||
range_list,
|
||||
@@ -241,15 +236,15 @@ class TestResult(object):
|
||||
)
|
||||
ret += 'Performance for each AP:\r\n'
|
||||
for ap_ssid in self.throughput_by_att:
|
||||
ret += '[{}]: {:.02f} Mbps\r\n'.format(ap_ssid, max(self.throughput_by_att[ap_ssid].values()))
|
||||
ret += f'[{ap_ssid}]: {max(self.throughput_by_att[ap_ssid].values()):.02f} Mbps\r\n'
|
||||
if self.heap_size != INVALID_HEAP_SIZE:
|
||||
ret += 'Minimum heap size: {}'.format(self.heap_size)
|
||||
ret += f'Minimum heap size: {self.heap_size}'
|
||||
else:
|
||||
ret = ''
|
||||
return ret
|
||||
|
||||
|
||||
class IperfTestUtility(object):
|
||||
class IperfTestUtility:
|
||||
"""iperf test implementation"""
|
||||
|
||||
def __init__(
|
||||
@@ -282,7 +277,7 @@ class IperfTestUtility(object):
|
||||
'udp_rx': TestResult('udp', 'rx', config_name),
|
||||
}
|
||||
|
||||
def setup(self) -> Tuple[str, int]:
|
||||
def setup(self) -> tuple[str, int]:
|
||||
"""
|
||||
setup iperf test:
|
||||
|
||||
@@ -299,23 +294,23 @@ class IperfTestUtility(object):
|
||||
self.dut.write('restart')
|
||||
self.dut.expect_exact("Type 'help' to get the list of commands.")
|
||||
self.dut.expect('iperf>')
|
||||
self.dut.write('sta_scan {}'.format(self.ap_ssid))
|
||||
self.dut.write(f'sta_scan {self.ap_ssid}')
|
||||
for _ in range(SCAN_RETRY_COUNT):
|
||||
try:
|
||||
rssi = int(self.dut.expect(r'\[{}]\[rssi=(-\d+)]'.format(self.ap_ssid), timeout=SCAN_TIMEOUT).group(1))
|
||||
rssi = int(self.dut.expect(rf'\[{self.ap_ssid}]\[rssi=(-\d+)]', timeout=SCAN_TIMEOUT).group(1))
|
||||
break
|
||||
except pexpect.TIMEOUT:
|
||||
continue
|
||||
else:
|
||||
raise AssertionError('Failed to scan AP')
|
||||
self.dut.write('sta_connect {} {}'.format(self.ap_ssid, self.ap_password))
|
||||
self.dut.write(f'sta_connect {self.ap_ssid} {self.ap_password}')
|
||||
dut_ip = self.dut.expect(r'sta ip: ([\d.]+), mask: ([\d.]+), gw: ([\d.]+)').group(1)
|
||||
return dut_ip, rssi
|
||||
|
||||
def _save_test_result(self, test_case: str, raw_data: str, att: int, rssi: int, heap_size: int) -> Any:
|
||||
return self.test_result[test_case].add_result(raw_data, self.ap_ssid, att, rssi, heap_size)
|
||||
|
||||
def _test_once(self, proto: str, direction: str, bw_limit: int) -> Tuple[str, int, int]:
|
||||
def _test_once(self, proto: str, direction: str, bw_limit: int) -> tuple[str, int, int]:
|
||||
"""do measure once for one type"""
|
||||
# connect and scan to get RSSI
|
||||
dut_ip, rssi = self.setup()
|
||||
@@ -333,9 +328,9 @@ class IperfTestUtility(object):
|
||||
stderr=f,
|
||||
)
|
||||
if bw_limit > 0:
|
||||
self.dut.write('iperf -c {} -i 1 -t {} -b {}'.format(self.pc_nic_ip, TEST_TIME, bw_limit))
|
||||
self.dut.write(f'iperf -c {self.pc_nic_ip} -i 1 -t {TEST_TIME} -b {bw_limit}m')
|
||||
else:
|
||||
self.dut.write('iperf -c {} -i 1 -t {}'.format(self.pc_nic_ip, TEST_TIME))
|
||||
self.dut.write(f'iperf -c {self.pc_nic_ip} -i 1 -t {TEST_TIME}')
|
||||
else:
|
||||
process = subprocess.Popen(
|
||||
['iperf', '-s', '-u', '-B', self.pc_nic_ip, '-t', str(TEST_TIME), '-i', '1', '-f', 'm'],
|
||||
@@ -343,9 +338,9 @@ class IperfTestUtility(object):
|
||||
stderr=f,
|
||||
)
|
||||
if bw_limit > 0:
|
||||
self.dut.write('iperf -c {} -u -i 1 -t {} -b {}'.format(self.pc_nic_ip, TEST_TIME, bw_limit))
|
||||
self.dut.write(f'iperf -c {self.pc_nic_ip} -u -i 1 -t {TEST_TIME} -b {bw_limit}m')
|
||||
else:
|
||||
self.dut.write('iperf -c {} -u -i 1 -t {}'.format(self.pc_nic_ip, TEST_TIME))
|
||||
self.dut.write(f'iperf -c {self.pc_nic_ip} -u -i 1 -t {TEST_TIME}')
|
||||
|
||||
for _ in range(TEST_TIMEOUT):
|
||||
if process.poll() is not None:
|
||||
@@ -354,12 +349,12 @@ class IperfTestUtility(object):
|
||||
else:
|
||||
process.terminate()
|
||||
|
||||
with open(PC_IPERF_TEMP_LOG_FILE, 'r') as f:
|
||||
with open(PC_IPERF_TEMP_LOG_FILE) as f:
|
||||
pc_raw_data = server_raw_data = f.read()
|
||||
else:
|
||||
with open(PC_IPERF_TEMP_LOG_FILE, 'w') as f:
|
||||
if proto == 'tcp':
|
||||
self.dut.write('iperf -s -i 1 -t {}'.format(TEST_TIME))
|
||||
self.dut.write(f'iperf -s -i 1 -t {TEST_TIME}')
|
||||
# wait until DUT TCP server created
|
||||
try:
|
||||
self.dut.expect('Socket created', timeout=5)
|
||||
@@ -384,13 +379,13 @@ class IperfTestUtility(object):
|
||||
process.terminate()
|
||||
else:
|
||||
if bw_limit > 0:
|
||||
self.dut.write('iperf -s -u -i 1 -t {}'.format(TEST_TIME))
|
||||
self.dut.write(f'iperf -s -u -i 1 -t {TEST_TIME}')
|
||||
# wait until DUT TCP server created
|
||||
try:
|
||||
self.dut.expect('Socket bound', timeout=5)
|
||||
self.dut.expect('Socket created', timeout=5)
|
||||
except pexpect.TIMEOUT:
|
||||
# compatible with old iperf example binary
|
||||
logging.info('create iperf udp server fail')
|
||||
logging.info('No "Socket created" confirmation received after starting UDP server')
|
||||
process = subprocess.Popen(
|
||||
['iperf', '-c', dut_ip, '-u', '-b', str(bw_limit) + 'm', '-t', str(TEST_TIME), '-f', 'm'],
|
||||
stdout=f,
|
||||
@@ -408,14 +403,14 @@ class IperfTestUtility(object):
|
||||
n = 10
|
||||
step = int((stop_bw - start_bw) / n)
|
||||
self.dut.write(
|
||||
'iperf -s -u -i 1 -t {}'.format(TEST_TIME + 4 * (n + 1))
|
||||
f'iperf -s -u -i 1 -t {TEST_TIME + 4 * (n + 1)}'
|
||||
) # 4 sec for each bw step instance start/stop
|
||||
# wait until DUT TCP server created
|
||||
try:
|
||||
self.dut.expect('Socket bound', timeout=5)
|
||||
self.dut.expect('Socket created', timeout=5)
|
||||
except pexpect.TIMEOUT:
|
||||
# compatible with old iperf example binary
|
||||
logging.info('create iperf udp server fail')
|
||||
logging.info('No "Socket created" confirmation received after starting UDP server')
|
||||
for bandwidth in range(start_bw, stop_bw, step):
|
||||
process = subprocess.Popen(
|
||||
[
|
||||
@@ -441,7 +436,7 @@ class IperfTestUtility(object):
|
||||
process.terminate()
|
||||
|
||||
server_raw_data = self.dut.expect(pexpect.TIMEOUT, timeout=5).decode('utf-8')
|
||||
with open(PC_IPERF_TEMP_LOG_FILE, 'r') as f:
|
||||
with open(PC_IPERF_TEMP_LOG_FILE) as f:
|
||||
pc_raw_data = f.read()
|
||||
|
||||
if os.path.exists(PC_IPERF_TEMP_LOG_FILE):
|
||||
@@ -452,7 +447,7 @@ class IperfTestUtility(object):
|
||||
f.write(
|
||||
'## [{}] `{}`\r\n##### {}'.format(
|
||||
self.config_name,
|
||||
'{}_{}'.format(proto, direction),
|
||||
f'{proto}_{direction}',
|
||||
time.strftime('%m-%d %H:%M:%S', time.localtime(time.time())),
|
||||
)
|
||||
)
|
||||
@@ -476,17 +471,11 @@ class IperfTestUtility(object):
|
||||
heap_size = INVALID_HEAP_SIZE
|
||||
try:
|
||||
server_raw_data, rssi, heap_size = self._test_once(proto, direction, bw_limit)
|
||||
throughput = self._save_test_result(
|
||||
'{}_{}'.format(proto, direction), server_raw_data, atten_val, rssi, heap_size
|
||||
)
|
||||
logging.info(
|
||||
'[{}][{}_{}][{}][{}]: {:.02f}'.format(
|
||||
self.config_name, proto, direction, rssi, self.ap_ssid, throughput
|
||||
)
|
||||
)
|
||||
throughput = self._save_test_result(f'{proto}_{direction}', server_raw_data, atten_val, rssi, heap_size)
|
||||
logging.info(f'[{self.config_name}][{proto}_{direction}][{rssi}][{self.ap_ssid}]: {throughput:.02f}')
|
||||
self.lowest_rssi_scanned = min(self.lowest_rssi_scanned, rssi)
|
||||
except (ValueError, IndexError):
|
||||
self._save_test_result('{}_{}'.format(proto, direction), '', atten_val, rssi, heap_size)
|
||||
self._save_test_result(f'{proto}_{direction}', '', atten_val, rssi, heap_size)
|
||||
logging.info('Fail to get throughput results.')
|
||||
except AssertionError:
|
||||
self.fail_to_scan += 1
|
||||
@@ -504,9 +493,7 @@ class IperfTestUtility(object):
|
||||
self.run_test('udp', 'tx', atten_val, bw_limit)
|
||||
self.run_test('udp', 'rx', atten_val, bw_limit)
|
||||
if self.fail_to_scan > 10:
|
||||
logging.info(
|
||||
'Fail to scan AP for more than 10 times. Lowest RSSI scanned is {}'.format(self.lowest_rssi_scanned)
|
||||
)
|
||||
logging.info(f'Fail to scan AP for more than 10 times. Lowest RSSI scanned is {self.lowest_rssi_scanned}')
|
||||
raise AssertionError
|
||||
|
||||
def wait_ap_power_on(self) -> bool:
|
||||
@@ -520,8 +507,8 @@ class IperfTestUtility(object):
|
||||
self.dut.expect('iperf>')
|
||||
for _ in range(WAIT_AP_POWER_ON_TIMEOUT // SCAN_TIMEOUT):
|
||||
try:
|
||||
self.dut.write('scan {}'.format(self.ap_ssid))
|
||||
self.dut.expect(r'\[{}]\[rssi=(-\d+)]'.format(self.ap_ssid), timeout=SCAN_TIMEOUT)
|
||||
self.dut.write(f'scan {self.ap_ssid}')
|
||||
self.dut.expect(rf'\[{self.ap_ssid}]\[rssi=(-\d+)]', timeout=SCAN_TIMEOUT)
|
||||
ret = True
|
||||
break
|
||||
except pexpect.TIMEOUT:
|
||||
|
||||
Reference in New Issue
Block a user