Expanded logging in wk.hw.diags

This commit is contained in:
2Shirt 2019-11-10 20:22:48 -07:00
parent 906826d752
commit 21dfeac20b
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 18 additions and 9 deletions

View file

@ -12,16 +12,15 @@ import time
from collections import OrderedDict from collections import OrderedDict
from docopt import docopt from docopt import docopt
from wk import exe, net, std, tmux from wk import cfg, exe, log, net, std, tmux
from wk.cfg.hw import TMUX_LAYOUT, TMUX_SIDE_WIDTH
from wk.cfg.main import KIT_NAME_FULL
# atexit functions # atexit functions
atexit.register(tmux.kill_all_panes) atexit.register(tmux.kill_all_panes)
#TODO: Add state/dev data dump debug function
# STATIC VARIABLES # STATIC VARIABLES
DOCSTRING = f'''{KIT_NAME_FULL}: Hardware Diagnostics DOCSTRING = f'''{cfg.main.KIT_NAME_FULL}: Hardware Diagnostics
Usage: Usage:
hw-diags hw-diags
@ -112,13 +111,13 @@ class State():
def fix_tmux_layout(self, forced=True, signum=None, frame=None): def fix_tmux_layout(self, forced=True, signum=None, frame=None):
# pylint: disable=unused-argument # pylint: disable=unused-argument
"""Fix tmux layout based on TMUX_LAYOUT. """Fix tmux layout based on cfg.hw.TMUX_LAYOUT.
NOTE: To support being called by both a signal and a thread NOTE: To support being called by both a signal and a thread
signum and frame must be valid aguments. signum and frame must be valid aguments.
""" """
try: try:
tmux.fix_layout(self.panes, TMUX_LAYOUT, forced=forced) tmux.fix_layout(self.panes, cfg.hw.TMUX_LAYOUT, forced=forced)
except RuntimeError: except RuntimeError:
# Assuming self.panes changed while running # Assuming self.panes changed while running
pass pass
@ -146,7 +145,7 @@ class State():
# Started # Started
self.panes['Started'] = tmux.split_window( self.panes['Started'] = tmux.split_window(
lines=TMUX_SIDE_WIDTH, lines=cfg.hw.TMUX_SIDE_WIDTH,
target_id=self.panes['Top'], target_id=self.panes['Top'],
text=std.color_string( text=std.color_string(
['Started', time.strftime("%Y-%m-%d %H:%M %Z")], ['Started', time.strftime("%Y-%m-%d %H:%M %Z")],
@ -157,7 +156,7 @@ class State():
# Progress # Progress
self.panes['Progress'] = tmux.split_window( self.panes['Progress'] = tmux.split_window(
lines=TMUX_SIDE_WIDTH, lines=cfg.hw.TMUX_SIDE_WIDTH,
text=' ', text=' ',
) )
@ -176,6 +175,7 @@ def audio_test():
def audio_test_linux(): def audio_test_linux():
"""Run an audio test using amixer and speaker-test.""" """Run an audio test using amixer and speaker-test."""
LOG.info('Audio Test')
std.clear_screen() std.clear_screen()
# Set volume # Set volume
@ -226,36 +226,42 @@ def build_menu(quick_mode=False):
def cpu_mprime_test(): def cpu_mprime_test():
"""CPU & cooling check using Prime95.""" """CPU & cooling check using Prime95."""
LOG.info('CPU Test (Prime95)')
#TODO: p95 #TODO: p95
std.print_warning('TODO: p95') std.print_warning('TODO: p95')
def disk_attribute_check(): def disk_attribute_check():
"""Disk attribute check.""" """Disk attribute check."""
LOG.info('Disk Attribute Check')
#TODO: at #TODO: at
std.print_warning('TODO: at') std.print_warning('TODO: at')
def disk_io_benchmark(): def disk_io_benchmark():
"""Disk I/O benchmark using dd.""" """Disk I/O benchmark using dd."""
LOG.info('Disk I/O Benchmark (dd)')
#TODO: io #TODO: io
std.print_warning('TODO: io') std.print_warning('TODO: io')
def disk_self_test(): def disk_self_test():
"""Disk self-test if available.""" """Disk self-test if available."""
LOG.info('Disk Self-Test')
#TODO: st #TODO: st
std.print_warning('TODO: st') std.print_warning('TODO: st')
def disk_surface_scan(): def disk_surface_scan():
"""Disk surface scan using badblocks.""" """Disk surface scan using badblocks."""
LOG.info('Disk Surface Scan (badblocks)')
#TODO: bb #TODO: bb
std.print_warning('TODO: bb') std.print_warning('TODO: bb')
def keyboard_test(): def keyboard_test():
"""Test keyboard using xev.""" """Test keyboard using xev."""
LOG.info('Keyboard Test (xev)')
cmd = ['xev', '-event', 'keyboard'] cmd = ['xev', '-event', 'keyboard']
std.clear_screen() std.clear_screen()
exe.run_program(cmd, check=False, pipe=False) exe.run_program(cmd, check=False, pipe=False)
@ -264,6 +270,7 @@ def keyboard_test():
def main(): def main():
"""Main function for hardware diagnostics.""" """Main function for hardware diagnostics."""
args = docopt(DOCSTRING) args = docopt(DOCSTRING)
log.update_log_path(dest_name='Hardware-Diagnostics', timestamp=True)
# Safety check # Safety check
if 'TMUX' not in os.environ: if 'TMUX' not in os.environ:
@ -320,6 +327,7 @@ def main():
def network_test(): def network_test():
"""Run network tests.""" """Run network tests."""
LOG.info('Network Test')
std.clear_screen() std.clear_screen()
try_and_print = std.TryAndPrint() try_and_print = std.TryAndPrint()
result = try_and_print.run( result = try_and_print.run(
@ -349,6 +357,7 @@ def network_test():
def screensaver(name): def screensaver(name):
"""Show screensaver""" """Show screensaver"""
LOG.info('Screensaver (%s)', name)
if name == 'matrix': if name == 'matrix':
cmd = ['cmatrix', '-abs'] cmd = ['cmatrix', '-abs']
elif name == 'pipes': elif name == 'pipes':

View file

@ -191,7 +191,7 @@ def resize_pane(pane_id=None, width=None, height=None, **kwargs):
# Safety checks # Safety checks
if not poll_pane(pane_id): if not poll_pane(pane_id):
LOG.error('tmux pane %s not found', pane_id) LOG.debug('tmux pane %s not found', pane_id)
raise RuntimeError(f'tmux pane {pane_id} not found') raise RuntimeError(f'tmux pane {pane_id} not found')
if not (width or height): if not (width or height):
LOG.error('Neither width nor height specified') LOG.error('Neither width nor height specified')