CI: erase nvs partition before test:

Latest NVS partition bin can't be parsed by old IDF revision. Need to erase before test.
This commit is contained in:
He Yin Ling
2018-07-26 15:07:32 +08:00
parent 146a959706
commit bf72ed92a9
3 changed files with 80 additions and 21 deletions

View File

@@ -17,6 +17,10 @@ import os
import re
import subprocess
import functools
import random
import tempfile
from serial.tools import list_ports
import DUT
@@ -40,6 +44,8 @@ class IDFDUT(DUT.SerialDUT):
""" IDF DUT, extends serial with ESPTool methods """
CHIP_TYPE_PATTERN = re.compile(r"Detecting chip type[.:\s]+(.+)")
# if need to erase NVS partition in start app
ERASE_NVS = True
def __init__(self, name, port, log_file, app, **kwargs):
self.download_config, self.partition_table = app.process_app_info()
@@ -68,24 +74,39 @@ class IDFDUT(DUT.SerialDUT):
return cls.get_chip(app, port) is not None
@_tool_method
def start_app(self):
def start_app(self, erase_nvs=ERASE_NVS):
"""
download and start app.
:param: erase_nvs: whether erase NVS partition during flash
:return: None
"""
if erase_nvs:
address = self.partition_table["nvs"]["offset"]
size = self.partition_table["nvs"]["size"]
nvs_file = tempfile.NamedTemporaryFile()
nvs_file.write(chr(0xFF) * size)
nvs_file.flush()
download_config = self.download_config + [address, nvs_file.name]
else:
download_config = self.download_config
retry_baud_rates = ["921600", "115200"]
error = IDFToolError()
for baud_rate in retry_baud_rates:
try:
subprocess.check_output(["python", self.app.esptool,
"--port", self.port, "--baud", baud_rate]
+ self.download_config)
break
except subprocess.CalledProcessError as error:
continue
else:
raise error
try:
for baud_rate in retry_baud_rates:
try:
subprocess.check_output(["python", self.app.esptool,
"--port", self.port, "--baud", baud_rate]
+ download_config)
break
except subprocess.CalledProcessError as error:
continue
else:
raise error
finally:
if erase_nvs:
nvs_file.close()
@_tool_method
def reset(self):
@@ -96,6 +117,17 @@ class IDFDUT(DUT.SerialDUT):
"""
subprocess.check_output(["python", self.app.esptool, "--port", self.port, "run"])
@_tool_method
def erase_partition(self, partition):
"""
:param partition: partition name to erase
:return: None
"""
address = self.partition_table[partition]["offset"]
size = self.partition_table[partition]["size"]
with open(".erase_partition.tmp", "wb") as f:
f.write(chr(0xFF) * size)
@_tool_method
def dump_flush(self, output_file, **kwargs):
"""