1*9c5db199SXin Li# Copyright 2018 The Chromium OS Authors. All rights reserved. 2*9c5db199SXin Li# Use of this source code is governed by a BSD-style license that can be 3*9c5db199SXin Li# found in the LICENSE file. 4*9c5db199SXin Li 5*9c5db199SXin Li"""An interface to access the local graphics facade.""" 6*9c5db199SXin Li 7*9c5db199SXin Lifrom autotest_lib.client.common_lib import error 8*9c5db199SXin Lifrom autotest_lib.client.cros.graphics import graphics_utils 9*9c5db199SXin Li 10*9c5db199SXin Li 11*9c5db199SXin Liclass GraphicsFacadeLocal(object): 12*9c5db199SXin Li """Facade to access graphics utilities for catching GPU hangs.""" 13*9c5db199SXin Li 14*9c5db199SXin Li 15*9c5db199SXin Li def __init__(self): 16*9c5db199SXin Li """Initializes the graphics facade. 17*9c5db199SXin Li 18*9c5db199SXin Li Graphics state checker is initialized with a dedicated function to 19*9c5db199SXin Li control timing for the initial set of errors extracted from logs. 20*9c5db199SXin Li 21*9c5db199SXin Li """ 22*9c5db199SXin Li self._graphics_state_checker = None 23*9c5db199SXin Li 24*9c5db199SXin Li 25*9c5db199SXin Li def graphics_state_checker_initialize(self): 26*9c5db199SXin Li """Create and initialize the graphics state checker object. 27*9c5db199SXin Li 28*9c5db199SXin Li This will establish existing errors and take a snapshot of graphics 29*9c5db199SXin Li kernel memory. 30*9c5db199SXin Li 31*9c5db199SXin Li """ 32*9c5db199SXin Li self._graphics_state_checker = graphics_utils.GraphicsStateChecker() 33*9c5db199SXin Li 34*9c5db199SXin Li 35*9c5db199SXin Li def graphics_state_checker_finalize(self): 36*9c5db199SXin Li """Throw an error on new GPU hang messages in system logs. 37*9c5db199SXin Li 38*9c5db199SXin Li @raises TestError: Finalize was called before initialize. 39*9c5db199SXin Li """ 40*9c5db199SXin Li if self._graphics_state_checker is None: 41*9c5db199SXin Li raise error.TestError('Graphics state checker initialize not called.') 42*9c5db199SXin Li self._graphics_state_checker.finalize() 43