iperf_test.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. """
  2. Test case for iperf example.
  3. This test case might have problem running on windows:
  4. 1. direct use of `make`
  5. 2. use `sudo killall iperf` to force kill iperf, didn't implement windows version
  6. """
  7. from __future__ import division, unicode_literals
  8. import os
  9. import re
  10. import subprocess
  11. import time
  12. import netifaces
  13. import ttfw_idf
  14. from common_test_methods import get_env_config_variable, get_host_ip_by_interface
  15. from idf_iperf_test_util import IperfUtility
  16. from tiny_test_fw import TinyFW
  17. try:
  18. from typing import Any, Tuple
  19. except ImportError:
  20. # Only used for type annotations
  21. pass
  22. NO_BANDWIDTH_LIMIT = -1 # iperf send bandwidth is not limited
  23. class IperfTestUtilityEth(IperfUtility.IperfTestUtility):
  24. """ iperf test implementation """
  25. def __init__(self, dut, config_name, pc_nic_ip, pc_iperf_log_file, test_result=None): # type: (str, str, str,str, Any) -> None
  26. IperfUtility.IperfTestUtility.__init__(self, dut, config_name, 'None', 'None', pc_nic_ip, pc_iperf_log_file, test_result)
  27. def setup(self): # type: () -> Tuple[str,int]
  28. """
  29. setup iperf test:
  30. 1. kill current iperf process
  31. 2. reboot DUT (currently iperf is not very robust, need to reboot DUT)
  32. """
  33. try:
  34. subprocess.check_output('sudo killall iperf 2>&1 > /dev/null', shell=True)
  35. except subprocess.CalledProcessError:
  36. pass
  37. self.dut.write('restart')
  38. self.dut.expect_any('iperf>', 'esp32>')
  39. self.dut.write('ethernet start')
  40. time.sleep(10)
  41. self.dut.write('ethernet info')
  42. dut_ip = self.dut.expect(re.compile(r'ETHIP: (\d+[.]\d+[.]\d+[.]\d+)\r'))[0]
  43. rssi = 0
  44. return dut_ip, rssi
  45. @ttfw_idf.idf_example_test(env_tag='ethernet_router')
  46. def test_ethernet_throughput_basic(env, _): # type: (Any, Any) -> None
  47. """
  48. steps: |
  49. 1. test TCP tx rx and UDP tx rx throughput
  50. 2. compare with the pre-defined pass standard
  51. """
  52. pc_nic = get_env_config_variable('wifi_router', 'pc_nic', default='eth1')
  53. pc_nic_ip = get_host_ip_by_interface(pc_nic, netifaces.AF_INET)
  54. pc_iperf_log_file = os.path.join(env.log_path, 'pc_iperf_log.md')
  55. # 1. get DUT
  56. dut = env.get_dut('iperf', 'examples/ethernet/iperf', dut_class=ttfw_idf.ESP32DUT)
  57. dut.start_app()
  58. dut.expect_any('iperf>', 'esp32>')
  59. # 2. preparing
  60. test_result = {
  61. 'tcp_tx': IperfUtility.TestResult('tcp', 'tx', 'ethernet'),
  62. 'tcp_rx': IperfUtility.TestResult('tcp', 'rx', 'ethernet'),
  63. 'udp_tx': IperfUtility.TestResult('udp', 'tx', 'ethernet'),
  64. 'udp_rx': IperfUtility.TestResult('udp', 'rx', 'ethernet'),
  65. }
  66. test_utility = IperfTestUtilityEth(dut, 'ethernet', pc_nic_ip, pc_iperf_log_file, test_result)
  67. # 3. run test for TCP Tx, Rx and UDP Tx, Rx
  68. test_utility.run_test('tcp', 'tx', 0, NO_BANDWIDTH_LIMIT)
  69. test_utility.run_test('tcp', 'rx', 0, NO_BANDWIDTH_LIMIT)
  70. test_utility.run_test('udp', 'tx', 0, 80)
  71. test_utility.run_test('udp', 'rx', 0, NO_BANDWIDTH_LIMIT)
  72. # 4. log performance and compare with pass standard
  73. performance_items = []
  74. for throughput_type in test_result:
  75. ttfw_idf.log_performance('{}_throughput'.format(throughput_type),
  76. '{:.02f} Mbps'.format(test_result[throughput_type].get_best_throughput()))
  77. performance_items.append(['{}_throughput'.format(throughput_type),
  78. '{:.02f} Mbps'.format(test_result[throughput_type].get_best_throughput())])
  79. # 5. save to report
  80. TinyFW.JunitReport.update_performance(performance_items)
  81. # do check after logging, otherwise test will exit immediately if check fail, some performance can't be logged.
  82. for throughput_type in test_result:
  83. ttfw_idf.check_performance('{}_throughput'.format(throughput_type + '_eth'),
  84. test_result[throughput_type].get_best_throughput(), dut.TARGET)
  85. env.close_dut('iperf')
  86. if __name__ == '__main__':
  87. test_ethernet_throughput_basic(env_config_file='EnvConfig.yml')