Files
OpenCellular/test/tpm_test/utils.py
Vadim Bendebury e1be8e179c cr50: test: move crypto test into its own module
This is a no-op change moving some common code out of tpmtest.py,
preparing it to support different testing modes.

BRANCH=none
BUG=chrome-os-partner:43025
TEST=the AES test still succeeds:
  $ test/tpm_test/tpmtest.py
  Starting MPSSE at 800 kHz
  Connected to device vid:did:rid of 1ae0:0028:00
  SUCCESS: AES:ECB common
  SUCCESS: AES:ECB128 1
  SUCCESS: AES:ECB192 1
  SUCCESS: AES:ECB256 1
  SUCCESS: AES:ECB256 2
  SUCCESS: AES:CTR128I 1
  SUCCESS: AES:CTR256I 1

Change-Id: Ia6e0e3e89f99875297da0a4f6137de5901c8ca08
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/314691
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-12-03 02:21:19 -08:00

39 lines
1.0 KiB
Python

#!/usr/bin/python
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Support functions for extended command based testing."""
import sys
if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty():
cursor_back_cmd = '\x1b[1D' # Move one space to the left.
else:
cursor_back_cmd = ''
def cursor_back():
"""Return a string which would move cursor one space left, if available.
This is used to remove the remaining 'spinner' character after the test
completes and its result is printed on the same line where the 'spinner' was
spinning.
"""
return cursor_back_cmd
def hex_dump(binstr):
"""Convert binary string into its multiline hex representation."""
dump_lines = ['',]
i = 0
while i < len(binstr):
strsize = min(16, len(binstr) - i)
hexstr = ' '.join('%2.2x' % ord(x) for x in binstr[i:i+strsize])
dump_lines.append(hexstr)
i += strsize
dump_lines.append('')
return '\n'.join(dump_lines)