From 7fbbde56c632212e2a304eaa24b7c2d0ad71f37c Mon Sep 17 00:00:00 2001 From: 2Shirt <1923621+2Shirt@users.noreply.github.com> Date: Wed, 27 Dec 2017 04:01:54 -0700 Subject: [PATCH] run_badblocks() working * Re-added and updated hw-diags-badblocks --- .bin/Scripts/functions/hw_diags.py | 71 +++++++++++++++++++++-- .bin/Scripts/hw-diags-badblocks | 18 ++++++ .bin/Scripts/hw-diags-prime95 | 1 + .bin/Scripts/linux-old/hw-diags-badblocks | 25 -------- 4 files changed, 86 insertions(+), 29 deletions(-) create mode 100755 .bin/Scripts/hw-diags-badblocks delete mode 100755 .bin/Scripts/linux-old/hw-diags-badblocks diff --git a/.bin/Scripts/functions/hw_diags.py b/.bin/Scripts/functions/hw_diags.py index dc236399..8d9ed020 100644 --- a/.bin/Scripts/functions/hw_diags.py +++ b/.bin/Scripts/functions/hw_diags.py @@ -36,6 +36,7 @@ TESTS = { }, 'badblocks': { 'Enabled': False, + 'Results': {}, 'Status': {}, }, } @@ -116,6 +117,58 @@ def menu_diags(): break def run_badblocks(): + aborted = False + clear_screen() + print_log('\nStart badblocks test(s)\n') + progress_file = '{}/badblocks_progress.out'.format(global_vars['LogDir']) + update_progress() + + # Set Window layout and start test + run_program('tmux split-window -dhl 15 watch -c -n1 -t cat {}'.format( + TESTS['Progress Out']).split()) + + # Show disk details + for name, dev in sorted(TESTS['badblocks']['Devices'].items()): + show_disk_details(dev) + print_standard(' ') + update_progress() + + # Run + print_standard('Running badblock test(s):') + for name, dev in sorted(TESTS['badblocks']['Devices'].items()): + cur_status = TESTS['badblocks']['Status'][name] + nvme_smart_status = TESTS['NVMe/SMART']['Status'].get(name, None) + if cur_status == 'Denied': + # Skip denied disks + continue + if nvme_smart_status == 'NS': + TESTS['badblocks']['Status'][name] = 'Skipped' + else: + # Not testing SMART, SMART CS, or SMART OVERRIDE + print_standard(' /dev/{:11} '.format(name+'...'), end='', flush=True) + run_program('tmux split-window -dl 10 {} {} {}'.format( + 'hw-diags-badblocks', + '/dev/{}'.format(name), + progress_file).split()) + wait_for_process('badblocks') + print_standard('Done', timestamp=False) + + # Check results + with open(progress_file, 'r') as f: + text = f.read() + TESTS['badblocks']['Results'][name] = text + r = re.search(r'Pass completed.*0/0/0 errors', text) + if r: + TESTS['badblocks']['Status'][name] = 'CS' + else: + TESTS['badblocks']['Status'][name] = 'NS' + + # Remove temp file + os.remove(progress_file) + update_progress() + + # Done + run_program('tmux kill-pane -a'.split(), check=False) pass def run_mprime(): @@ -255,7 +308,7 @@ def run_smart(): update_progress() print_standard('Running SMART short self-test(s):') print_standard( - ' /dev/{:8}({} minutes)...'.format(name, test_length), + ' /dev/{:8}({} minutes)... '.format(name, test_length), end='', flush=True) run_program( 'sudo smartctl -t short /dev/{}'.format(name).split(), @@ -518,9 +571,19 @@ def show_results(): print_success('\nDisks:') for name, dev in sorted(TESTS['NVMe/SMART']['Devices'].items()): show_disk_details(dev) - if TESTS['badblocks']['Enabled']: - #TODO - pass + bb_status = TESTS['badblocks']['Status'].get(name, None) + if (TESTS['badblocks']['Enabled'] + and bb_status not in ['Denied', 'OVERRIDE', 'Skipped']): + print_info('badblocks:') + for line in TESTS['badblocks']['Results'][name].splitlines(): + if re.search(r'Pass completed', line, re.IGNORECASE): + line = re.sub( + r'Pass completed,?\s+', r'', + line.strip(), re.IGNORECASE) + if TESTS['badblocks']['Status'][name] == 'CS': + print_standard(' {}'.format(line)) + else: + print_error(' {}'.format(line)) print_standard(' ') # Done diff --git a/.bin/Scripts/hw-diags-badblocks b/.bin/Scripts/hw-diags-badblocks new file mode 100755 index 00000000..2d915766 --- /dev/null +++ b/.bin/Scripts/hw-diags-badblocks @@ -0,0 +1,18 @@ +#!/bin/bash +# +## Wizard Kit: HW Diagnostics - badblocks + +function usage { + echo "Usage: $0 device log-file" + echo " e.g. $0 /dev/sda /tmp/tmp.XXXXXXX/badblocks.log" +} + +# Bail early +if [ ! -b "$1" ]; then + usage + exit 1 +fi + +# Run Badblocks +sudo badblocks -sv -e 1 "$1" 2>&1 | tee -a "$2" + diff --git a/.bin/Scripts/hw-diags-prime95 b/.bin/Scripts/hw-diags-prime95 index c19a913c..30c6994d 100755 --- a/.bin/Scripts/hw-diags-prime95 +++ b/.bin/Scripts/hw-diags-prime95 @@ -15,3 +15,4 @@ fi # Run Prime95 mprime -t | grep -iv --line-buffered 'stress.txt' | tee -a "$1/prime.log" + diff --git a/.bin/Scripts/linux-old/hw-diags-badblocks b/.bin/Scripts/linux-old/hw-diags-badblocks deleted file mode 100755 index cfff7c4d..00000000 --- a/.bin/Scripts/linux-old/hw-diags-badblocks +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -# -## Wizard Kit: HW Diagnostics - badblocks - -function usage { - echo "Usage: $0 log-dir device" - echo " e.g. $0 /tmp/tmp.7Mh5f1RhSL9001 /dev/sda" -} - -# Bail early -if [ ! -d "$1" ]; then - usage - exit 1 -fi -if [ ! -b "$2" ]; then - usage - exit 1 -fi - -# Run Badblocks -sudo badblocks -sv -e 1 "$2" -tmux capture-pane -tmux save-buffer "$1/bb_tmp.out" -grep -Ev '^$' "$1/bb_tmp.out" > "$1/${2##*/}_badblocks.log" -rm "$1/bb_tmp.out"