Skip to content

Commit

Permalink
testing/esp: add optional skip reason to decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
sobuch authored and erhankur committed Dec 11, 2024
1 parent 9d85041 commit 35d57a5
Showing 1 changed file with 38 additions and 22 deletions.
60 changes: 38 additions & 22 deletions testing/esp/debug_backend_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,41 @@ def create_gdb_and_reconnect(self):
testee_info = TesteeInfo()


def idf_ver_min(ver_str):
return unittest.skipIf(testee_info.idf_ver < IdfVersion.fromstr(ver_str), "requires min IDF_VER='%s', current IDF_VER='%s'" % (ver_str, testee_info.idf_ver))

def run_with_version(ver_str):
return unittest.skipIf(testee_info.idf_ver != IdfVersion.fromstr(ver_str), "Not Applicable to this version")

def skip_for_hw_id(hw_ids_to_skip):
def idf_ver_min(ver_str, reason=None):
if reason is None:
reason = "requires min IDF_VER='%s', current IDF_VER='%s'" % (ver_str, testee_info.idf_ver)
return unittest.skipIf(testee_info.idf_ver < IdfVersion.fromstr(ver_str), reason)

def run_with_version(ver_str, reason=None):
if reason is None:
reason = "Not Applicable to this version"
return unittest.skipIf(testee_info.idf_ver != IdfVersion.fromstr(ver_str), reason)

def skip_for_hw_id(hw_ids_to_skip, reason=None):
if reason is None:
reason = "skipped due to HW ID '%s' matches to '%s'" % (testee_info.hw_id, hw_id_to_skip)
skip = False
hw_id_to_skip = ''
for id in hw_ids_to_skip:
if re.match(id, testee_info.hw_id):
skip = True
hw_id_to_skip = id
break
return unittest.skipIf(skip, "skipped due to HW ID '%s' matches to '%s'" % (testee_info.hw_id, hw_id_to_skip))
return unittest.skipIf(skip, reason)

def skip_for_chip(chips_to_skip):
def skip_for_chip(chips_to_skip, reason=None):
if reason is None:
reason = "skipped for chip '%s'" % (testee_info.chip)
skip = False
for id in chips_to_skip:
if id == testee_info.chip:
skip = True
break
return unittest.skipIf(skip, "skipped for chip '%s'" % (testee_info.chip))
return unittest.skipIf(skip, reason)

def skip_for_chip_and_ver(ver_str, chips_to_skip):
def skip_for_chip_and_ver(ver_str, chips_to_skip, reason=None):
if reason is None:
reason = "for the '%s' for the IDF_VER='%s'" % (id, testee_info.idf_ver)
skip = False
for id in chips_to_skip:
if id == testee_info.chip:
Expand All @@ -180,46 +190,52 @@ def skip_for_chip_and_ver(ver_str, chips_to_skip):
# check major and minor numbers only.
if v1 == v2 or (v1[0] == v2[0] and v1[1] == v2[1]):
skip = True
return unittest.skipIf(skip, "for the '%s' for the IDF_VER='%s'" % (id, testee_info.idf_ver))
return unittest.skipIf(skip, reason)

def skip_for_arch(archs_to_skip):
def skip_for_arch(archs_to_skip, reason=None):
if reason is None:
reason = "skipped due to arch '%s' matches to '%s'" % (testee_info.arch, arch_to_skip)
skip = False
arch_to_skip = ''
for id in archs_to_skip:
if re.match(id, testee_info.arch):
skip = True
arch_to_skip = id
break
return unittest.skipIf(skip, "skipped due to arch '%s' matches to '%s'" % (testee_info.arch, arch_to_skip))
return unittest.skipIf(skip, reason)

def only_for_arch(archs_to_run):
def only_for_arch(archs_to_run, reason=None):
if reason is None:
reason = "skipped due to arch '%s' does not match to '%s'" % (testee_info.arch, archs_to_run)
skip = True
for id in archs_to_run:
if re.match(id, testee_info.arch):
skip = False
break
return unittest.skipIf(skip, "skipped due to arch '%s' does not match to '%s'" % (testee_info.arch, archs_to_run))
return unittest.skipIf(skip, reason)

def only_for_chip(chips_to_run):
def only_for_chip(chips_to_run, reason=None):
if reason is None:
reason = "skipped for chip '%s'" % (testee_info.chip)
skip = True
for id in chips_to_run:
if id == testee_info.chip:
skip = False
break
return unittest.skipIf(skip, "skipped for chip '%s'" % (testee_info.chip))
return unittest.skipIf(skip, reason)

def idf_ver_min_for_arch(ver_str, archs_to_run):
def idf_ver_min_for_arch(ver_str, archs_to_run, reason=None):
skip = True
for id in archs_to_run:
if re.match(id, testee_info.arch):
return idf_ver_min(ver_str)
return idf_ver_min(ver_str, reason)
# do not skip if arch is not found
return unittest.skipIf(False, "")

def idf_ver_min_for_chip(ver_str, chips_to_skip):
def idf_ver_min_for_chip(ver_str, chips_to_skip, reason=None):
for chip in chips_to_skip:
if chip == testee_info.chip:
return idf_ver_min(ver_str)
return idf_ver_min(ver_str, reason)
# do not skip if chip is not found
return unittest.skipIf(False, "")

Expand Down

0 comments on commit 35d57a5

Please sign in to comment.