iperf_test.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 ttfw_idf
  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 bandwith 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_any('iperf>', 'esp32>')
  37. self.dut.write('ethernet start')
  38. time.sleep(10)
  39. self.dut.write('ethernet info')
  40. dut_ip = self.dut.expect(re.compile(r'ETHIP: (\d+[.]\d+[.]\d+[.]\d+)'))[0]
  41. rssi = 0
  42. return dut_ip, rssi
  43. @ttfw_idf.idf_example_test(env_tag='Example_Ethernet')
  44. def test_ethernet_throughput_basic(env, _): # type: (Any, Any) -> None
  45. """
  46. steps: |
  47. 1. test TCP tx rx and UDP tx rx throughput
  48. 2. compare with the pre-defined pass standard
  49. """
  50. pc_nic_ip = env.get_pc_nic_info('pc_nic', 'ipv4')['addr']
  51. pc_iperf_log_file = os.path.join(env.log_path, 'pc_iperf_log.md')
  52. # 1. get DUT
  53. dut = env.get_dut('iperf', 'examples/ethernet/iperf', dut_class=ttfw_idf.ESP32DUT)
  54. dut.start_app()
  55. dut.expect_any('iperf>', 'esp32>')
  56. # 2. preparing
  57. test_result = {
  58. 'tcp_tx': IperfUtility.TestResult('tcp', 'tx', 'ethernet'),
  59. 'tcp_rx': IperfUtility.TestResult('tcp', 'rx', 'ethernet'),
  60. 'udp_tx': IperfUtility.TestResult('udp', 'tx', 'ethernet'),
  61. 'udp_rx': IperfUtility.TestResult('udp', 'rx', 'ethernet'),
  62. }
  63. test_utility = IperfTestUtilityEth(dut, 'ethernet', pc_nic_ip, pc_iperf_log_file, test_result)
  64. # 3. run test for TCP Tx, Rx and UDP Tx, Rx
  65. test_utility.run_test('tcp', 'tx', 0, NO_BANDWIDTH_LIMIT)
  66. test_utility.run_test('tcp', 'rx', 0, NO_BANDWIDTH_LIMIT)
  67. test_utility.run_test('udp', 'tx', 0, 80)
  68. test_utility.run_test('udp', 'rx', 0, NO_BANDWIDTH_LIMIT)
  69. # 4. log performance and compare with pass standard
  70. performance_items = []
  71. for throughput_type in test_result:
  72. ttfw_idf.log_performance('{}_throughput'.format(throughput_type),
  73. '{:.02f} Mbps'.format(test_result[throughput_type].get_best_throughput()))
  74. performance_items.append(['{}_throughput'.format(throughput_type),
  75. '{:.02f} Mbps'.format(test_result[throughput_type].get_best_throughput())])
  76. # 5. save to report
  77. TinyFW.JunitReport.update_performance(performance_items)
  78. # do check after logging, otherwise test will exit immediately if check fail, some performance can't be logged.
  79. for throughput_type in test_result:
  80. ttfw_idf.check_performance('{}_throughput'.format(throughput_type + '_eth'),
  81. test_result[throughput_type].get_best_throughput(), dut.TARGET)
  82. env.close_dut('iperf')
  83. if __name__ == '__main__':
  84. test_ethernet_throughput_basic(env_config_file='EnvConfig.yml')