iperf_test.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. class IperfTestUtilityEth(IperfUtility.IperfTestUtility):
  21. """ iperf test implementation """
  22. def __init__(self, dut, config_name, pc_nic_ip, pc_iperf_log_file, test_result=None): # type: (str, str, str,str, Any) -> None
  23. IperfUtility.IperfTestUtility.__init__(self, dut, config_name, 'None', 'None', pc_nic_ip, pc_iperf_log_file, test_result)
  24. def setup(self): # type: () -> Tuple[str,int]
  25. """
  26. setup iperf test:
  27. 1. kill current iperf process
  28. 2. reboot DUT (currently iperf is not very robust, need to reboot DUT)
  29. """
  30. try:
  31. subprocess.check_output('sudo killall iperf 2>&1 > /dev/null', shell=True)
  32. except subprocess.CalledProcessError:
  33. pass
  34. self.dut.write('restart')
  35. self.dut.expect_any('iperf>', 'esp32>')
  36. self.dut.write('ethernet start')
  37. time.sleep(10)
  38. self.dut.write('ethernet info')
  39. dut_ip = self.dut.expect(re.compile(r'ETHIP: ([\d.]+)'))[0]
  40. rssi = 0
  41. return dut_ip, rssi
  42. @ttfw_idf.idf_example_test(env_tag='Example_Ethernet')
  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_nic_ip = env.get_pc_nic_info('pc_nic', 'ipv4')['addr']
  50. pc_iperf_log_file = os.path.join(env.log_path, 'pc_iperf_log.md')
  51. # 1. get DUT
  52. dut = env.get_dut('iperf', 'examples/ethernet/iperf', dut_class=ttfw_idf.ESP32DUT)
  53. dut.start_app()
  54. dut.expect_any('iperf>', 'esp32>')
  55. # 2. preparing
  56. test_result = {
  57. 'tcp_tx': IperfUtility.TestResult('tcp', 'tx', 'ethernet'),
  58. 'tcp_rx': IperfUtility.TestResult('tcp', 'rx', 'ethernet'),
  59. 'udp_tx': IperfUtility.TestResult('udp', 'tx', 'ethernet'),
  60. 'udp_rx': IperfUtility.TestResult('udp', 'rx', 'ethernet'),
  61. }
  62. test_utility = IperfTestUtilityEth(dut, 'ethernet', pc_nic_ip, pc_iperf_log_file, test_result)
  63. # 3. run test for TCP Tx, Rx and UDP Tx, Rx
  64. test_utility.run_all_cases(0)
  65. # 4. log performance and compare with pass standard
  66. performance_items = []
  67. for throughput_type in test_result:
  68. ttfw_idf.log_performance('{}_throughput'.format(throughput_type),
  69. '{:.02f} Mbps'.format(test_result[throughput_type].get_best_throughput()))
  70. performance_items.append(['{}_throughput'.format(throughput_type),
  71. '{:.02f} Mbps'.format(test_result[throughput_type].get_best_throughput())])
  72. # 5. save to report
  73. TinyFW.JunitReport.update_performance(performance_items)
  74. # do check after logging, otherwise test will exit immediately if check fail, some performance can't be logged.
  75. for throughput_type in test_result:
  76. ttfw_idf.check_performance('{}_throughput'.format(throughput_type + '_eth'),
  77. test_result[throughput_type].get_best_throughput(), dut.TARGET)
  78. env.close_dut('iperf')
  79. if __name__ == '__main__':
  80. test_ethernet_throughput_basic(env_config_file='EnvConfig.yml')