NVSCompatibleWiFi.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import os
  2. import time
  3. from TCAction import TCActionBase
  4. from TCAction import PerformanceTCBase
  5. from NativeLog import NativeLog
  6. SOFTAP_SSID = "SoftAPSSID4NVSCompatibleTest"
  7. SOFTAP_PASSWORD = "SoftAPPassword4NVSCompatibleTest"
  8. NVS_FILE_NAME = "nvs_wifi.bin"
  9. class TestCase(PerformanceTCBase.PerformanceTCBase):
  10. def __init__(self, test_case, test_env, timeout=30, log_path=TCActionBase.LOG_PATH):
  11. PerformanceTCBase.PerformanceTCBase.__init__(self, test_case, test_env, timeout=timeout, log_path=log_path)
  12. self.nvs_path = ""
  13. # load param from excel
  14. cmd_set = test_case["cmd set"]
  15. for i in range(1, len(cmd_set)):
  16. if cmd_set[i][0] != "dummy":
  17. cmd_string = "self." + cmd_set[i][0]
  18. exec cmd_string
  19. def get_nvs_bins(self):
  20. if os.path.exists(self.nvs_path) is False:
  21. NativeLog.add_trace_critical("NVS path is not correct")
  22. files = []
  23. else:
  24. files = [os.path.join(self.nvs_path, x) for x in os.listdir(self.nvs_path)]
  25. return filter(lambda f: NVS_FILE_NAME in f, files)
  26. def check_nvs(self, nvs_bin):
  27. branch_name = os.path.basename(nvs_bin)
  28. branch_name.replace("___", "/")
  29. result = True
  30. ssc1_port = self.test_env.get_port_by_name("SSC1")
  31. ap_ssid = self.get_parameter("ap_ssid")
  32. self.flush_data("SSC1")
  33. # first download
  34. ssc1_port.flash_nvs(nvs_bin)
  35. self.check_response("SSC1", "ready!!!")
  36. # set to sta mode and join ap
  37. if self.check_response("SSC1", "+JAP:CONNECTED,%s" % ap_ssid, timeout=15) is False:
  38. NativeLog.add_trace_critical("Failed to join AP on: " + branch_name)
  39. result = False
  40. self.serial_write_line("SSC1", "op -Q")
  41. if self.check_response("SSC1", "+CURMODE:3") is False:
  42. NativeLog.add_trace_critical("Failed on verifying WIFI mode on: " + branch_name)
  43. result = False
  44. self.serial_write_line("SSC1", "ap -Q")
  45. if self.check_response("SSC1", "+APCONFIG:%s,%s" % (SOFTAP_SSID, SOFTAP_PASSWORD)) is False:
  46. NativeLog.add_trace_critical("Failed on verifying SoftAP config on: " + branch_name)
  47. result = False
  48. return result
  49. def dump_nvs(self):
  50. ssc1_port = self.test_env.get_port_by_name("SSC1")
  51. ap_ssid = self.get_parameter("ap_ssid")
  52. ap_password = self.get_parameter("ap_password")
  53. # first erase NVS
  54. ssc1_port.flash_nvs(None)
  55. self.check_response("SSC1", "ready!!!")
  56. self.serial_write_line("SSC1", "op -S -o 3")
  57. self.check_response("SSC1", "+MODE:OK")
  58. self.serial_write_line("SSC1", "sta -C -s %s -p %s" % (ap_ssid, ap_password))
  59. self.check_response("SSC1", "+JAP:CONNECTED,%s" % ap_ssid, timeout=20)
  60. self.serial_write_line("SSC1", "ap -S -s %s -p %s -t 3" % (SOFTAP_SSID, SOFTAP_PASSWORD))
  61. self.check_response("SSC1", "+SAP:OK")
  62. time.sleep(1)
  63. idf_path = os.getenv("IDF_PATH")
  64. ssc1_port.dump_nvs(os.path.join(idf_path, NVS_FILE_NAME))
  65. def cleanup(self):
  66. # make sure dump nvs will be executed
  67. self.dump_nvs()
  68. def process(self):
  69. result = True
  70. nvs_bins = self.get_nvs_bins()
  71. for nvs_bin in nvs_bins:
  72. result = result and self.check_nvs(nvs_bin)
  73. if result is True:
  74. self.set_result("Succeed")