From 4feb15182ef6787e1314915d2d26a9b352f7b4db Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sat, 10 Jun 2023 18:06:09 -0700 Subject: [PATCH] Rework SMART self-test sections (again) - Use results from self-test log rather than self-test details - Include more result details in more scenarios - Only add self-test results to the report to avoid duplicate/conflicting info - Add check if test started but didn't finish (again?) --- scripts/wk/hw/diags.py | 2 +- scripts/wk/hw/smart.py | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/scripts/wk/hw/diags.py b/scripts/wk/hw/diags.py index cd309fc7..292bff3e 100644 --- a/scripts/wk/hw/diags.py +++ b/scripts/wk/hw/diags.py @@ -540,7 +540,7 @@ def disk_self_test(state, test_objects, test_mode=False) -> None: # Show progress if threads[-1].is_alive(): - state.ui.add_worker_pane(lines=4, watch_cmd='tail', watch_file=test_log) + state.ui.add_worker_pane(lines=4, watch_file=test_log) # Wait for all tests to complete state.update_progress_file() diff --git a/scripts/wk/hw/smart.py b/scripts/wk/hw/smart.py index c9c3a94b..13331efb 100644 --- a/scripts/wk/hw/smart.py +++ b/scripts/wk/hw/smart.py @@ -42,25 +42,24 @@ def build_self_test_report(test_obj, aborted=False) -> None: last known progress instead of just "was aborted by host." """ report = [ansi.color_string('Self-Test', 'BLUE')] - test_details = get_smart_self_test_details(test_obj.dev) - test_result = test_details.get('status', {}).get('string', 'Unknown') + test_result = get_smart_self_test_last_result(test_obj.dev) # Build report if test_obj.disabled or test_obj.status == 'Denied': report.append(ansi.color_string(f' {test_obj.status}', 'RED')) elif test_obj.status == 'N/A' or not test_obj.dev.attributes: report.append(ansi.color_string(f' {test_obj.status}', 'YELLOW')) - elif test_obj.status == 'TestInProgress': - report.append(ansi.color_string(' Failed to stop previous test', 'RED')) - test_obj.set_status('Failed') else: # Other cases include self-test result string - report.append(f' {test_result.capitalize()}') - if aborted and not (test_obj.passed or test_obj.failed): - report.append(ansi.color_string(' Aborted', 'YELLOW')) - test_obj.set_status('Aborted') + if test_obj.status == 'TestInProgress': + report.append(ansi.color_string(' Failed to stop previous test', 'RED')) + test_obj.set_status('Failed') elif test_obj.status == 'TimedOut': report.append(ansi.color_string(' TimedOut', 'YELLOW')) + elif aborted and not (test_obj.passed or test_obj.failed): + report.append(ansi.color_string(' Aborted', 'YELLOW')) + test_obj.set_status('Aborted') + report.append(f' {test_result}') # Done test_obj.report.extend(report) @@ -219,7 +218,7 @@ def get_known_disk_attributes(model) -> dict[str | int, dict[str, Any]]: return known_attributes -def get_smart_self_test_details(dev) -> dict[Any, Any]: +def get_smart_self_test_details(dev) -> dict[str, Any]: """Shorthand to get deeply nested self-test details, returns dict.""" details = {} try: @@ -241,7 +240,9 @@ def get_smart_self_test_last_result(dev) -> str: 'ata_smart_self_test_log', {}).get( 'standard', {}).get( 'table', []) - if not data: + try: + data = data[0] + except IndexError: # No results found return result @@ -291,7 +292,6 @@ def monitor_smart_self_test(test_obj, header_str, log_path) -> bool: result = get_smart_self_test_last_result(test_obj.dev) if result == 'Unknown': result = 'SMART self-test failed to start' - test_obj.dev.add_note(result) test_obj.failed = True test_obj.set_status('TimedOut') break @@ -307,6 +307,11 @@ def monitor_smart_self_test(test_obj, header_str, log_path) -> bool: finished = True break + # Check if timed out + if started and not finished: + test_obj.failed = True + test_obj.set_status('TimedOut') + # Done return finished