iperf_test.py 4.0 KB

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