Skip to content

Commit

Permalink
Merge pull request #476 from brianesquilona/dev_tests
Browse files Browse the repository at this point in the history
Check first if the board is already remounted by checking mode change and remount count
  • Loading branch information
brianesquilona authored Sep 4, 2018
2 parents 76d846e + 13c68b9 commit f7f0568
Showing 1 changed file with 63 additions and 50 deletions.
113 changes: 63 additions & 50 deletions test/daplink_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,21 +522,35 @@ def load_bootloader(self, filepath, parent_test):
if data_crc != details_crc:
test_info.failure("Bootloader CRC is wrong")

def wait_for_remount(self, parent_test, wait_time=1800):
def wait_for_remount(self, parent_test, wait_time=600):
mode = self._mode
count = self._remount_count
test_info = parent_test.create_subtest('wait_for_remount')

elapsed = 0
start = time.time()
remounted = False
while os.path.isdir(self.mount_point):
if self.update_board_info(False): #check info if it is already mounted
if mode is not None and self._mode is not None and mode is not self._mode:
remounted = True
test_info.info("already remounted with change mode")
break
elif count is not None and self._remount_count is not None and count != self._remount_count:
remounted = True
test_info.info("already remounted with change mount count")
break
if elapsed > wait_time:
raise Exception("Dismount timed out")
time.sleep(0.1)
elapsed += 0.1
stop = time.time()
test_info.info("unmount took %s s" % (stop - start))
elapsed += 0.2
else:
stop = time.time()
test_info.info("unmount took %s s" % (stop - start))
elapsed = 0
start = time.time()
while True:

while not remounted:
if self.update_board_info(False):
if os.path.isdir(self.mount_point):
# Information returned by mbed-ls could be old.
Expand Down Expand Up @@ -579,53 +593,52 @@ def update_board_info(self, exptn_on_fail=True):
Note - before this function is set self.unique_id
must be set.
"""
endpoints = _get_board_endpoints(self.unique_id)
if endpoints is None:
if exptn_on_fail:
raise Exception("Could not update board info: %s" %
self.unique_id)
return False
self.unique_id, self.serial_port, self.mount_point = endpoints
# Serial port can be missing
if self.unique_id is None:
if exptn_on_fail:
raise Exception("Mount point is null")
return False
if self.mount_point is None:
if exptn_on_fail:
raise Exception("Mount point is null")
return False
self.board_id = int(self.unique_id[0:4], 16)
self._hic_id = int(self.unique_id[-8:], 16)

# Note - Some legacy boards might not have details.txt
details_txt_path = self.get_file_path("details.txt")
self.details_txt = _parse_kvp_file(details_txt_path)
self._parse_assert_txt()

self._remount_count = None
if DaplinkBoard.KEY_REMOUNT_COUNT in self.details_txt:
self._remount_count = int(self.details_txt[DaplinkBoard.KEY_REMOUNT_COUNT])
self._mode = None
if DaplinkBoard.KEY_MODE in self.details_txt:
DETAILS_TO_MODE = {
"interface": DaplinkBoard.MODE_IF,
"bootloader": DaplinkBoard.MODE_BL,
}
mode_str = self.details_txt[DaplinkBoard.KEY_MODE]
self._mode = DETAILS_TO_MODE[mode_str]
else:
# TODO - remove file check when old bootloader have been
# updated
check_bl_path = self.get_file_path('HELP_FAQ.HTM')
check_if_path = self.get_file_path('MBED.HTM')
if os.path.isfile(check_bl_path):
self._mode = self.MODE_BL
elif os.path.isfile(check_if_path):
self._mode = self.MODE_IF
try:
endpoints = _get_board_endpoints(self.unique_id)
if endpoints is None:
if exptn_on_fail:
raise Exception("Could not update board info: %s" %
self.unique_id)
return False
self.unique_id, self.serial_port, self.mount_point = endpoints
# Serial port can be missing
if self.unique_id is None:
if exptn_on_fail:
raise Exception("Mount point is null")
return False
if self.mount_point is None:
if exptn_on_fail:
raise Exception("Mount point is null")
return False
self.board_id = int(self.unique_id[0:4], 16)
self._hic_id = int(self.unique_id[-8:], 16)

# Note - Some legacy boards might not have details.txt
details_txt_path = self.get_file_path("details.txt")
self.details_txt = _parse_kvp_file(details_txt_path)
self._parse_assert_txt()

self._remount_count = None
if DaplinkBoard.KEY_REMOUNT_COUNT in self.details_txt:
self._remount_count = int(self.details_txt[DaplinkBoard.KEY_REMOUNT_COUNT])
self._mode = None
if DaplinkBoard.KEY_MODE in self.details_txt:
DETAILS_TO_MODE = {
"interface": DaplinkBoard.MODE_IF,
"bootloader": DaplinkBoard.MODE_BL,
}
mode_str = self.details_txt[DaplinkBoard.KEY_MODE]
self._mode = DETAILS_TO_MODE[mode_str]
else:
#check for race condition here
return False
return True
except Exception as e:
if exptn_on_fail:
raise e
else:
raise Exception("Could not determine board mode!")
return True
return False

def test_details_txt(self, parent_test):
"""Check that details.txt has all requied fields"""
Expand Down

0 comments on commit f7f0568

Please sign in to comment.