• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Provides utilities to support bluetooth adapter tests"""
2
3from __future__ import absolute_import
4
5import common
6from autotest_lib.client.bin.input.linux_input import EV_KEY
7from autotest_lib.server.cros.bluetooth.debug_linux_keymap import (
8        linux_input_keymap)
9from ast import literal_eval as make_tuple
10import logging
11
12
13def reconstruct_string(events):
14    """ Tries to reconstruct a string from linux input in a simple way
15
16    @param events: list of event objects received over the BT channel
17
18    @returns: reconstructed string
19    """
20    recon = []
21
22    for ev in events:
23        # If it's a key pressed event
24        if ev.type == EV_KEY and ev.value == 1:
25            recon.append(linux_input_keymap.get(ev.code, "_"))
26
27    return "".join(recon)
28
29
30def parse_trace_file(filename):
31    """ Reads contents of trace file
32
33    @param filename: location of trace file on disk
34
35    @returns: structure containing contents of filename
36    """
37
38    contents = []
39
40    try:
41        with open(filename, 'r') as mf:
42            for line in mf:
43                # Reconstruct tuple and add to trace
44                contents.append(make_tuple(line))
45    except EnvironmentError:
46        logging.error('Unable to open file %s', filename)
47        return None
48
49    return contents
50