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 c8c4bd099e
commit f98da26b38
2 changed files with 52 additions and 16 deletions

View file

@ -17,6 +17,8 @@ import os
import re import re
import subprocess import subprocess
import functools import functools
import random
import tempfile
import DUT import DUT
@ -40,6 +42,8 @@ class IDFDUT(DUT.SerialDUT):
""" IDF DUT, extends serial with ESPTool methods """ """ IDF DUT, extends serial with ESPTool methods """
CHIP_TYPE_PATTERN = re.compile(r"Detecting chip type[.:\s]+(.+)") 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): def __init__(self, name, port, log_file, app, **kwargs):
self.download_config, self.partition_table = app.process_app_info() self.download_config, self.partition_table = app.process_app_info()
@ -68,24 +72,39 @@ class IDFDUT(DUT.SerialDUT):
return cls.get_chip(app, port) is not None return cls.get_chip(app, port) is not None
@_tool_method @_tool_method
def start_app(self): def start_app(self, erase_nvs=ERASE_NVS):
""" """
download and start app. download and start app.
:param: erase_nvs: whether erase NVS partition during flash
:return: None :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"] retry_baud_rates = ["921600", "115200"]
error = IDFToolError() error = IDFToolError()
try:
for baud_rate in retry_baud_rates: for baud_rate in retry_baud_rates:
try: try:
subprocess.check_output(["python", self.app.esptool, subprocess.check_output(["python", self.app.esptool,
"--port", self.port, "--baud", baud_rate] "--port", self.port, "--baud", baud_rate]
+ self.download_config) + download_config)
break break
except subprocess.CalledProcessError as error: except subprocess.CalledProcessError as error:
continue continue
else: else:
raise error raise error
finally:
if erase_nvs:
nvs_file.close()
@_tool_method @_tool_method
def reset(self): def reset(self):
@ -96,6 +115,17 @@ class IDFDUT(DUT.SerialDUT):
""" """
subprocess.check_output(["python", self.app.esptool, "--port", self.port, "run"]) 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 @_tool_method
def dump_flush(self, output_file, **kwargs): def dump_flush(self, output_file, **kwargs):
""" """

View file

@ -20,9 +20,8 @@ from IDF.IDFApp import IDFApp, Example, UT
from IDF.IDFDUT import IDFDUT from IDF.IDFDUT import IDFDUT
def idf_example_test(app=Example, dut=IDFDUT, chip="ESP32", def idf_example_test(app=Example, dut=IDFDUT, chip="ESP32", module="examples", execution_time=1,
module="examples", execution_time=1, level="example", erase_nvs=True, **kwargs):
**kwargs):
""" """
decorator for testing idf examples (with default values for some keyword args). decorator for testing idf examples (with default values for some keyword args).
@ -31,12 +30,19 @@ def idf_example_test(app=Example, dut=IDFDUT, chip="ESP32",
:param chip: chip supported, string or tuple :param chip: chip supported, string or tuple
:param module: module, string :param module: module, string
:param execution_time: execution time in minutes, int :param execution_time: execution time in minutes, int
:param level: test level, could be used to filter test cases, string
:param erase_nvs: if need to erase_nvs in DUT.start_app()
:param kwargs: other keyword args :param kwargs: other keyword args
:return: test method :return: test method
""" """
# not use partial function as define as function support auto generating document try:
# try to config the default behavior of erase nvs
dut.ERASE_NVS = erase_nvs
except AttributeError:
pass
return TinyFW.test_method(app=app, dut=dut, chip=chip, module=module, return TinyFW.test_method(app=app, dut=dut, chip=chip, module=module,
execution_time=execution_time, **kwargs) execution_time=execution_time, level=level, **kwargs)
def log_performance(item, value): def log_performance(item, value):