def poll_touchscreen(events=1, timeout=10, stop_finger_up=False): """ Polling on the touchtest tool for a number of events or until the timeout expires :param events: number of events to poll until exit :param timeout: maximum poll time :return: a list of events in json format """ cmd = 'adb shell touchtest' proc = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE) timer = Timer(timeout, proc.kill) timer.start() events_structure = Touch_Events() index = 1 for line in iter(proc.stdout.readline, ''): if index >= events: if timer.is_alive(): timer.cancel() proc.kill() events_structure.extract_json(line) if stop_finger_up and events_structure.action[index-1] == "up": proc.kill() index += 1 if index == 1: print_to_console_and_logcat("No data results from touchtest poll") return None return events_structure
def check_brightness(arguments): global VERDICT, OUTPUT # add step to brightness_max in order to have a closed range values_range = xrange(brightness_min, brightness_max + step, step) if order == -1: values_range = reversed(values_range) values_range = list(values_range) set_brightness(values_range[0]) #set display color to be white for 10 seconds proc = display_on_screen(white_color, white_timeout) for value in values_range[1:]: sleep(0.3) set_brightness(value) print validation_message if user_validation(): OUTPUT = "Success" print_to_console_and_logcat(OUTPUT) VERDICT = SUCCESS else: OUTPUT = "Failure. Display brightness should " + BRIGHTNESS_CHANGE.lower( ) print_to_console_and_logcat(OUTPUT) VERDICT = FAILURE if proc: proc.kill()
def wait_for_event(event, expected_state, timeout=20): if event == "battery presence": get_method = get_battery_presence elif event == "power status": get_method = get_charging_status elif event == "charger online": get_method = get_online_status else: print "Unknown event: '{}'!!!".format(event) exit_test() start = time.time() while time.time() - start < timeout: found_state = get_method() if isinstance(expected_state, basestring): comparison = found_state == expected_state elif isinstance(expected_state, list): comparison = found_state in expected_state else: comparison = False if comparison: print_to_console_and_logcat("Found {}: '{}'".format( event, found_state)) return True print_to_console_and_logcat("Timeout waiting for '{}' to be '{}'".format( event, expected_state)) return False
def wait_for_power_and_battery(args): global VERDICT, OUTPUT if wait_for_event("power status", ["Charging", "Full"]) and wait_for_event("battery presence", '1'): menu(validation_menu, initial_menu_items) else: OUTPUT = "FAILURE: Did not find power status 'Charging' or 'Full' and battery connected" print_to_console_and_logcat(OUTPUT) VERDICT = FAILURE menu(validation_menu[1:], initial_menu_items)
def wait_for_battery_full(args): global VERDICT, OUTPUT if wait_for_event("power status", 'Full', wait_time_sec): OUTPUT = "SUCCESS" print_to_console_and_logcat(OUTPUT) VERDICT = SUCCESS else: OUTPUT = "FAILURE: Did not find battery full status after waiting {} hours".format(wait_time_hours) print_to_console_and_logcat(OUTPUT) VERDICT = FAILURE
def wait_for_battery_disconnect(args): global VERDICT, OUTPUT if wait_for_event("battery presence", '0'): OUTPUT = "SUCCESS" print_to_console_and_logcat(OUTPUT) VERDICT = SUCCESS else: OUTPUT = "FAILURE: Did not find battery disconnected" print_to_console_and_logcat(OUTPUT) VERDICT = FAILURE
def are_values_constant(values, rel_std_dev=0.05): rsd = numpy.std(values) / numpy.mean(values) if rsd <= rel_std_dev: return True else: print_to_console_and_logcat( "Values are not relative constant. Found relative standard deviation: {:.1f}%, " "but we expect it to be lower than {:.1f}%".format( rsd * 100, rel_std_dev * 100)) return False
def pre_check_verification(args): global VERDICT, OUTPUT if wait_for_event("power status", pre_check_status): menu(validation_menu, initial_menu_items) else: OUTPUT = "FAILURE: Did not find power status '{}'".format( pre_check_status) print_to_console_and_logcat(OUTPUT) VERDICT = FAILURE menu(validation_menu[1:], initial_menu_items)
def wait_for_status(args): global VERDICT, OUTPUT if wait_for_event("power status", check_status): message = "SUCCESS" print_to_console_and_logcat(message) VERDICT = SUCCESS else: message = "FAILURE: Did not find power status '{}', instead found status '{}'" message = message.format(check_status, get_charging_status()) print_to_console_and_logcat(message) VERDICT = FAILURE OUTPUT = message
def check_color(arguments): global VERDICT, OUTPUT color = randint(1, 4) passed, message = check_sleep(color) if passed: OUTPUT = message print_to_console_and_logcat(OUTPUT) VERDICT = SUCCESS else: OUTPUT = message + ". Device couldn't support suspend/resume power cycle" print_to_console_and_logcat(OUTPUT) VERDICT = FAILURE
def check_axis(arguments): global VERDICT global OUTPUT x_max, x_min, y_max, y_min = touch_util.retrieve_resolution_geteven() events_structure = touch_util.poll_touchscreen(events=1, timeout=20) if not events_structure: VERDICT = FAILURE OUTPUT = "Failure. No touch events are retrieved" return x_middle = (x_min + x_max) / 2 y_middle = (y_min + y_max) / 2 if abs(events_structure.x[0][0] - x_middle) < 50 and abs(events_structure.y[0][0] - y_middle) < 50: print_to_console_and_logcat("Success") VERDICT = SUCCESS OUTPUT = "Success" else: print_to_console_and_logcat( "Middle of the touchscreen is located at coordinate [{} {}].". format(x_middle, y_middle)) print_to_console_and_logcat( "Touch event was found at coordinate [{} {}]".format( events_structure.x[0][0], events_structure.y[0][0])) print_to_console_and_logcat( "Failure. Touch event should be near the middle of the touchscreen" ) VERDICT = FAILURE OUTPUT = "Failure. Coordinates don't match middle of the screen. Expected: " + str(x_middle) + " " + str(y_middle) +\ " Received: " + str(events_structure.x[0][0]) + " " +str(events_structure.y[0][0])
def check_brightness(arguments): global VERDICT, OUTPUT set_brightness(brightness_value) #set display color to be white for 10 seconds proc = display_on_screen(white_color, white_timeout) if user_validation(): OUTPUT = "Success" print_to_console_and_logcat(OUTPUT) VERDICT = SUCCESS else: print_to_console_and_logcat(OUTPUT) OUTPUT = "Failure. Display brightness was not appropriate when " + \ "configured to value: " + str(brightness_value) VERDICT = FAILURE if proc: proc.kill()
def is_coord_in_corner(x, y, corner, pixel_margin=50): x_max, x_min, y_max, y_min = retrieve_resolution_geteven() if corner == "upper-left": corner_coord = (x_min, y_min) elif corner == "upper-right": corner_coord = (x_max, y_min) elif corner == "bottom-left": corner_coord = (x_min, y_max) elif corner == "bottom-right": corner_coord = (x_max, y_max) else: return False x_corner, y_corner = corner_coord if not (abs(x-x_corner) < pixel_margin and abs(y-y_corner) < pixel_margin): print_to_console_and_logcat("Coordinate [{}, {}] is not near the {} corner ([{}, {}])" .format(x, y, corner, x_corner, y_corner)) return False return True
def wait_for_status(): global VERDICT, OUTPUT global current_iteration tmp_status = check_status if check_status == "Charging": tmp_status = [check_status, "Full"] if wait_for_event("power status", tmp_status): return True else: OUTPUT = "FAILURE: Did not find power status '{}'".format(check_status) print_to_console_and_logcat(OUTPUT) VERDICT = FAILURE print "Do you want to repeat the test ? (y/n)" while True: input_line = raw_input("") if input_line == "y": current_iteration = 0 return True elif input_line == "n": return False
def check_axis(arguments): global VERDICT global OUTPUT events_structure = touch_util.poll_touchscreen(events=1, timeout=20) if not events_structure: VERDICT = FAILURE OUTPUT = "Failure. No touch events are retrieved" return if touch_util.is_coord_in_corner(events_structure.x[0][0], events_structure.y[0][0], CORNER): print_to_console_and_logcat("Success") VERDICT = SUCCESS OUTPUT = "Success" else: fail_message = "Failure. Touch event should be near the {} corner of the touchscreen"\ .format(CORNER) print_to_console_and_logcat(fail_message) VERDICT = FAILURE OUTPUT = fail_message
def run(self): try: self.values = [] self.aux_proc = subprocess.Popen( ['adb', 'shell', 'sens2', 'poll', str(self.id)], stdout=subprocess.PIPE) self.proc = subprocess.Popen(['tee', sens2_out], stdin=self.aux_proc.stdout, stdout=subprocess.PIPE) for line in iter(self.proc.stdout.readline, ''): parsed_json = json.loads(line.rstrip()) if parsed_json['type'] == self.type: sys.stdout.write( str(parsed_json['data'][self.axes]) + " \r") self.values.append(float(parsed_json['data'][self.axes])) except Exception as e: print_to_console_and_logcat("Exception in PollThread's run") exit_test()
def check_results(arguments): global VERDICT global OUTPUT if not events_structure: VERDICT = FAILURE OUTPUT = "Failure. No touch events are retrieved" return if len(events_structure.action) != 1: fail_message = "Failure. There were multiple events detected on the touchscreen. " \ "Events obtained: {}".format([x.encode('UTF8') for x in events_structure.action]) print_to_console_and_logcat(fail_message) VERDICT = FAILURE OUTPUT = fail_message return if events_structure.action[0] != "down": fail_message = "Failure. Expected to find a finger press event (action down), " \ "instead found action '{}'".format(events_structure.action[0]) print_to_console_and_logcat(fail_message) VERDICT = FAILURE OUTPUT = fail_message return print_to_console_and_logcat("Success") VERDICT = SUCCESS OUTPUT = "Success"
def check_color(arguments): global VERDICT, OUTPUT colors = range(1, 5) shuffle(colors) passed = True for color in colors: print insert_color_msg sleep(1) proc = display_on_screen(color) passed, OUTPUT = validate_response(color) if not passed: print_to_console_and_logcat(OUTPUT) VERDICT = FAILURE if proc: proc.kill() break if proc: proc.kill() if passed: OUTPUT = "Success" print_to_console_and_logcat(OUTPUT) VERDICT = SUCCESS
def are_values_on_the_edge(x_coords, y_coords): if EDGE == 'left': const_axis, ordered_axis = (x_coords, y_coords) const_axis_name, ordered_axis_name = ("x axis", "y axis") edge_val = x_min min_ordered, max_ordered = (y_min, y_max) elif EDGE == "right": const_axis, ordered_axis = (x_coords, y_coords) const_axis_name, ordered_axis_name = ("x axis", "y axis") edge_val = x_max min_ordered, max_ordered = (y_min, y_max) elif EDGE == "top": const_axis, ordered_axis = (y_coords, x_coords) const_axis_name, ordered_axis_name = ("y axis", "x axis") edge_val = y_min min_ordered, max_ordered = (x_min, x_max) elif EDGE == "bottom": const_axis, ordered_axis = (y_coords, x_coords) const_axis_name, ordered_axis_name = ("y axis", "x axis") edge_val = y_max min_ordered, max_ordered = (x_min, x_max) pixel_margin = 50 for const_coord in const_axis: if abs(const_coord - edge_val) > pixel_margin: print_to_console_and_logcat( "Found value {} for {} that is too far from the touchscreen edge ({})" .format(const_coord, const_axis_name, edge_val)) return False if abs(ordered_axis[0] - min_ordered) > pixel_margin: print_to_console_and_logcat( "Swipe did not start near the expected corner. Found {} coordinate '{}' " "which is too far from the corner value ({})".format( ordered_axis_name, ordered_axis[0], min_ordered)) return False if abs(ordered_axis[-1] - max_ordered) > pixel_margin: print_to_console_and_logcat( "Swipe did not end near the expected corner. Found {} coordinate '{}' " "which is too far from the corner value ({})".format( ordered_axis_name, ordered_axis[-1], max_ordered)) return False if not are_values_ordered(ordered_axis): return False return True
def check_edge(arguments): global VERDICT global OUTPUT events_structure = touch_util.poll_touchscreen(events=1000, timeout=10, stop_finger_up=True) if not events_structure: VERDICT = FAILURE OUTPUT = "Failure. No touch events are retrieved" return x_coords = [] y_coords = [] for x_event in events_structure.x: x_coords.append(x_event[0]) for y_event in events_structure.y: y_coords.append(y_event[0]) if are_values_correct(x_coords, y_coords): if EDGE == "non_touch": print_to_console_and_logcat("Success") VERDICT = SUCCESS OUTPUT = "Success" elif are_values_on_the_edge(x_coords, y_coords): print_to_console_and_logcat("Success") VERDICT = SUCCESS OUTPUT = "Success" else: fail_message = "Failure. Events coordinates were not appropriate for the " + EDGE + " edge." print_to_console_and_logcat(fail_message) VERDICT = FAILURE OUTPUT = fail_message else: VERDICT = FAILURE OUTPUT = "Failure. X and y values are not correct " + str( x_coords) + str(y_coords)
def check_axis(arguments): global VERDICT global OUTPUT events_structure = touch_util.poll_touchscreen(events=1000, timeout=10, stop_finger_up=True) if not events_structure: VERDICT = FAILURE OUTPUT = "Failure. No touch events are retrieved" return x_coords = [] y_coords = [] for x_event in events_structure.x: x_coords.append(x_event[0]) for y_event in events_structure.y: y_coords.append(y_event[0]) if DIAGONAL == "primary": if not (touch_util.is_coord_in_corner(x_coords[0], y_coords[0], "upper-left") and touch_util.is_coord_in_corner(x_coords[-1], y_coords[-1], "bottom-right")): print_to_console_and_logcat( "Failure. Swipe should start from the top left corner " "and end in the bottom right corner") VERDICT = FAILURE OUTPUT = "Failure. Swipe start coordinate " + str(x_coords[0]) +" "+ str(y_coords[0]) + " and end cooridnates " + \ str(x_coords[-1]) +" "+ str(y_coords[-1]) + " don't match the intended swipe gesture" return for coords, coords_name, axis in zip([x_coords, y_coords], ["x_coords", "y_coords"], ["X", "Y"]): if not are_values_ordered(coords): print_to_console_and_logcat( "Failure. Events coordinates should increase on {} axis.". format(axis)) VERDICT = FAILURE OUTPUT = "Failure. Events coordinates should increase on {} axis.".format( axis) return print_to_console_and_logcat("Success") VERDICT = SUCCESS OUTPUT = "Success" if DIAGONAL == "secondary": if not (touch_util.is_coord_in_corner(x_coords[0], y_coords[0], "upper-right") and touch_util.is_coord_in_corner(x_coords[-1], y_coords[-1], "bottom-left")): print_to_console_and_logcat( "Failure. Swipe should start from the top right corner " "and end in the bottom left corner") VERDICT = FAILURE OUTPUT = "Failure. Swipe start coordinate " + str(x_coords[0]) +" "+ str(y_coords[0]) + " and end cooridnates " + \ str(x_coords[-1]) +" "+ str(y_coords[-1]) + " don't match the intended swipe gesture" return if not are_values_ordered(x_coords, -1): print_to_console_and_logcat( "Failure. Events coordinates should decrease on X axis.") VERDICT = FAILURE OUTPUT = "Failure. Events along x axis are not in decrease order" return if not are_values_ordered(y_coords): print_to_console_and_logcat( "Failure. Events coordinates should increase on Y axis.") VERDICT = FAILURE OUTPUT = "Failure. Events along y axis are not in decrease order" return print_to_console_and_logcat("Success") VERDICT = SUCCESS OUTPUT = "Success"
from util import validate_result from util import menu from util import print_to_console_and_logcat from util import exit_test VERDICT = FAILURE OUTPUT = "" BRIGHTNESS_CHANGE = TC_PARAMETERS('BRIGHTNESS') check_brightness_message = "Please check the brightness of the display." if (BRIGHTNESS_CHANGE == "INCREASE"): order = 1 elif (BRIGHTNESS_CHANGE == "DECREASE"): order = -1 else: OUTPUT = "Wrong parameter. BRIGHTNESS value should be MAX or MIN" print_to_console_and_logcat(OUTPUT) exit_test() brightness_max = 255 brightness_min = 0 step = 15 white_color = 4 white_timeout = 10 validation_message = "Did you observe a gradually " + BRIGHTNESS_CHANGE.lower() + \ " of the display brightness? (y/n)" def check_brightness(arguments): global VERDICT, OUTPUT # add step to brightness_max in order to have a closed range values_range = xrange(brightness_min, brightness_max + step, step)
def check_multiple_swipe(arguments): global VERDICT global OUTPUT events_structure = touch_util.poll_touchscreen(events=1000, timeout=10, stop_finger_up=True) if not events_structure: VERDICT = FAILURE OUTPUT = "Failure. No touch events are retrieved" return x_coords = [] y_coords = [] for index, fingers_nr in enumerate(events_structure.fingers_number): # when at least one finger is lifted we won't take into consideration other events if events_structure.action[index] == "pointer up": break for finger in range(0, fingers_nr): if len(x_coords) <= finger: x_coords.append([]) x_coords[finger].append(events_structure.x[index][finger]) if len(y_coords) <= finger: y_coords.append([]) y_coords[finger].append(events_structure.y[index][finger]) # x_coords and y_coords are the same length fingers_nr = len(x_coords) if fingers_nr < 5: print_to_console_and_logcat( "Failure. Touch should be pressed with at least 5 fingers") print_to_console_and_logcat("Failure. There were recorded only " + str(fingers_nr) + " fingers") VERDICT = FAILURE OUTPUT = "Failure. Only " + str(fingers_nr) + " fingers detected" else: passed = True for finger in range(0, fingers_nr): if swipe_direction == "down": constant = "x coords" ordered = "y coords" order = 1 elif swipe_direction == "up": constant = "x coords" ordered = "y coords" order = -1 elif swipe_direction == "right": constant = "y coords" ordered = "x coords" order = 1 elif swipe_direction == "left": constant = "y coords" ordered = "x coords" order = -1 if constant == "x coords": constant_vals = x_coords[finger] else: constant_vals = y_coords[finger] if ordered == "x coords": ordered_vals = x_coords[finger] else: ordered_vals = y_coords[finger] if not are_values_ordered(ordered_vals, order, 0.99): passed = False fail_message = "Failure. For at least one finger, values for {} did not increase " \ "as they should.".format(ordered) print_to_console_and_logcat(fail_message) VERDICT = FAILURE OUTPUT = fail_message break elif not are_values_constant(constant_vals, 0.2): passed = False fail_message = "Failure. For at least one finger, values for {} are not relative constant " \ "as they should be.".format(finger+1, constant) print_to_console_and_logcat(fail_message) VERDICT = FAILURE OUTPUT = fail_message break if passed: print_to_console_and_logcat("Success") VERDICT = SUCCESS OUTPUT = "Success"
def are_values_correct(x_coords, y_coords): if min(x_coords) < x_min or max(x_coords) > x_max: print_to_console_and_logcat( "Failure. Some of the values excedeed the maximum or " "minimum values for ABS_X (min:{} max:{})".format(x_min, x_max)) print_to_console_and_logcat("Found x_coords min:{} max:{}".format( min(x_coords), max(x_coords))) return False if min(y_coords) < y_min or max(y_coords) > y_max: print_to_console_and_logcat( "Failure. Some of the values excedeed the maximum or " "minimum values for ABS_Y (min:{} max:{})".format(y_min, y_max)) print_to_console_and_logcat("Found y_coords min:{} max: {}".format( min(y_coords), max(y_coords))) return False for coords, coords_name in zip([x_coords, y_coords], ["x_coords", "y_coords"]): if min(coords) < 0: print_to_console_and_logcat( "Failure. All coordinates should be positive") print_to_console_and_logcat( "Failure. Found negative {}: {}".format(coords_name), min(coords)) return False return True
import os import numpy import touch_util from util import validate_result from util import menu from util import print_to_console_and_logcat from util import are_values_ordered from util import exit_test VERDICT = FAILURE swipe_direction = TC_PARAMETERS('swipe_direction') expected_directions = ["up", "down", "left", "right"] if swipe_direction not in expected_directions: print_to_console_and_logcat( "Incorrect value '{}' for parameter swipe_direction. \n".format( swipe_direction) + "It should be one of: " + expected_directions) exit_test() press_message = "Using five fingers, swipe {} on the touchscreen.".format( swipe_direction) def are_values_constant(values, rel_std_dev=0.05): rsd = numpy.std(values) / numpy.mean(values) if rsd <= rel_std_dev: return True else: print_to_console_and_logcat( "Values are not relative constant. Found relative standard deviation: {:.1f}%, " "but we expect it to be lower than {:.1f}%".format( rsd * 100, rel_std_dev * 100))
def check_size(arguments): global VERDICT global OUTPUT events_structure = touch_util.poll_touchscreen(events=1000, timeout=10, stop_finger_up=True) if not events_structure: VERDICT = FAILURE OUTPUT = "Failure. No touch events are retrieved" return size_values = [] for index, fingers_nr in enumerate(events_structure.fingers_number): for finger in range(0, fingers_nr): if len(size_values) <= finger: size_values.append([]) size_values[finger].append(events_structure.size[index][finger]) if MULTIPLE_FINGERS == "False": if are_values_ordered(size_values[0]): print_to_console_and_logcat("Success") VERDICT = SUCCESS OUTPUT = "Success" else: print_to_console_and_logcat( "Failure. Finger size should increase.") VERDICT = FAILURE OUTPUT = "Failure. Finger size didn't increase." else: fingers_nr = len(size_values) if fingers_nr < 5: print_to_console_and_logcat( "Failure. Touch should be pressed with at least 5 fingers") print_to_console_and_logcat("Failure. There were recorded only " + str(fingers_nr) + \ " fingers") VERDICT = FAILURE OUTPUT = "Failure. There were recorded only " + str(fingers_nr) + \ " fingers" else: passed = True for finger in range(0, fingers_nr): if not are_values_ordered(size_values[finger]): passed = False print_to_console_and_logcat( "Failure. Fingers size should increase") VERDICT = FAILURE OUTPUT = "Failure. Finger size didn't increase." break if passed: print_to_console_and_logcat("Success") VERDICT = SUCCESS OUTPUT = "Success"
from util import menu from util import print_to_console_and_logcat from util import are_values_ordered from util import exit_test VERDICT = FAILURE MULTIPLE_FINGERS = TC_PARAMETERS('MULTIPLE_FINGERS') press_message = "" if MULTIPLE_FINGERS == "True": press_message = "Press with the fingertip of five of your fingers on the touchscreen\n" + \ "Then, for several seconds, gradually increase the fingerprints size on the touchscreen." elif MULTIPLE_FINGERS == "False": press_message = "Press with the fingertip of one finger on the touchscreen\n" + \ "Then, for several seconds, gradually increase the fingerprint size on the touchscreen." else: print_to_console_and_logcat("Incorrect value for MULTIPLE_FINGERS parameter. " + \ "It should be True or False") exit_test() def check_size(arguments): global VERDICT global OUTPUT events_structure = touch_util.poll_touchscreen(events=1000, timeout=10, stop_finger_up=True) if not events_structure: VERDICT = FAILURE OUTPUT = "Failure. No touch events are retrieved" return
def check_pressure(arguments): global VERDICT global OUTPUT events_structure = touch_util.poll_touchscreen(events=1000, timeout=10, stop_finger_up=True) if not events_structure: VERDICT = FAILURE OUTPUT = "Failure. No touch events are retrieved" return pressure_values = [] for index, fingers_nr in enumerate(events_structure.fingers_number): for finger in range(0, fingers_nr): if len(pressure_values) <= finger: pressure_values.append([]) pressure_values[finger].append( events_structure.pressure[index][finger]) if MULTIPLE_FINGERS == "False": if not 0 in pressure_values[0]: print_to_console_and_logcat("Success") VERDICT = SUCCESS OUTPUT = "Success" else: fail_message = "Failure. Found a value of zero for pressure for the finger. " \ "Pressure values should be non-zero." print_to_console_and_logcat(fail_message) VERDICT = FAILURE OUTPUT = fail_message else: fingers_nr = len(pressure_values) if fingers_nr < 5: print_to_console_and_logcat( "Failure. Touch should be pressed with at least 5 fingers") print_to_console_and_logcat("Failure. It were recorded only " + str(fingers_nr) + \ " fingers") VERDICT = FAILURE OUTPUT = "Failure. Only " + str(fingers_nr) + " fingers detected" else: passed = True for finger in range(0, fingers_nr): if 0 in pressure_values[finger]: passed = False fail_message = "Failure. Found a value of zero for pressure for one of the fingers. " \ "Pressure values should be non-zero." print_to_console_and_logcat(fail_message) VERDICT = FAILURE OUTPUT = fail_message break if passed: print_to_console_and_logcat("Success") VERDICT = SUCCESS OUTPUT = "Success"
def check_sleep(arguments): global VERDICT global OUTPUT VERDICT = FAILURE start = time.time() timestamp_vector = [] first_touch = sys.float_info.max q.queue.clear() while True: # Exit if there are no touch events when timeout is reached if len(timestamp_vector) == 0 and time.time() - start > touch_timeout: print_to_console_and_logcat("Failure. Did not detect any touch events") OUTPUT = "Did not detect any touch events" return # Exit if we reach sleep timeout if time.time() - first_touch > max_sleep_duration: break # Exit if we reach a number of sufficient touch events elif len(timestamp_vector) > sufficient_events: break try: line = q.get_nowait() except Queue.Empty: continue match = json.loads(line) timestamp_vector.append(match["motion"]["timestamp"] / scale) if len(timestamp_vector) == 5: first_touch = time.time() print_to_console_and_logcat("Putting the device to sleep") for cmd in suspend_to_ram: p = subprocess.Popen(cmd, stdout=subprocess.PIPE) out, err = p.communicate() if out: print_to_console_and_logcat("Received error when trying to put device into sleep " + out) exit_test() dev_state = subprocess.check_output(["adb get-state"], shell=True) if dev_state.strip("\n") != "device": print_to_console_and_logcat("Failure. Device did not recover; found device state: {}".format(dev_state)) OUTPUT = "Failure. Adb state after sleep is: " + str(dev_state) exit_test() if len(timestamp_vector) < minimum_events: print_to_console_and_logcat("Failure. Not enough touch events were detected") OUTPUT = "Failure. Didn't receive enought touch events" return consecutive_elem_diff = [t - s for s, t in zip(timestamp_vector, timestamp_vector[1:])] time_diff_peak = max(consecutive_elem_diff) consecutive_elem_diff.remove(time_diff_peak) avg = numpy.mean(consecutive_elem_diff) std = numpy.std(consecutive_elem_diff) exp_max_std = 0.02 exp_max_avg = 0.015 avg_to_sleep_ratio = 200 if (std < exp_max_std) and (avg < exp_max_avg) and (avg_to_sleep_ratio * avg < time_diff_peak): print_to_console_and_logcat("Successfully received poll events after sleep") VERDICT = SUCCESS OUTPUT = "Success" else: print_to_console_and_logcat("Did not detect sleep conditions. Average time diff between events: " + str(avg) + " Peak time difference: " + str(time_diff_peak) + " Standard deviation:" + str(std)) OUTPUT = "Failure. Did not detect sleep conditions"
events = [] index = 0 for line in iter(proc.stdout.readline, ''): parsed_json = json.loads(line.rstrip()) events.append(parsed_json) index = index + 1 if index >= nr_events: if timer.is_alive(): timer.cancel() proc.kill() return events return events try: events = poll_for_events() if len(events) < expected_nr_events: print_test_result(False, "Timeout excedeed") else: period_values = [] # get periods array in seconds for event in events[1:]: period_values.append(event["event vsync"]["period"] / 1000) result = is_frequency_in_expected_range(expected_frequency, period_values) print_test_result(result["test_passed"], result["message"]) except Exception as e: print_to_console_and_logcat(str(e)) print_test_result(False, "Vsync poll could not be realised") exit_test()