xref: /aosp_15_r20/external/angle/build/android/pylib/base/environment.py (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker# Copyright 2014 The Chromium Authors
2*8975f5c5SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be
3*8975f5c5SAndroid Build Coastguard Worker# found in the LICENSE file.
4*8975f5c5SAndroid Build Coastguard Worker
5*8975f5c5SAndroid Build Coastguard Worker
6*8975f5c5SAndroid Build Coastguard Worker# TODO(crbug.com/40799394): After Telemetry is supported by python3 we can
7*8975f5c5SAndroid Build Coastguard Worker# remove object inheritance from this script.
8*8975f5c5SAndroid Build Coastguard Worker# pylint: disable=useless-object-inheritance
9*8975f5c5SAndroid Build Coastguard Workerclass Environment(object):
10*8975f5c5SAndroid Build Coastguard Worker  """An environment in which tests can be run.
11*8975f5c5SAndroid Build Coastguard Worker
12*8975f5c5SAndroid Build Coastguard Worker  This is expected to handle all logic that is applicable to an entire specific
13*8975f5c5SAndroid Build Coastguard Worker  environment but is independent of the test type.
14*8975f5c5SAndroid Build Coastguard Worker
15*8975f5c5SAndroid Build Coastguard Worker  Examples include:
16*8975f5c5SAndroid Build Coastguard Worker    - The local device environment, for running tests on devices attached to
17*8975f5c5SAndroid Build Coastguard Worker      the local machine.
18*8975f5c5SAndroid Build Coastguard Worker    - The local machine environment, for running tests directly on the local
19*8975f5c5SAndroid Build Coastguard Worker      machine.
20*8975f5c5SAndroid Build Coastguard Worker  """
21*8975f5c5SAndroid Build Coastguard Worker
22*8975f5c5SAndroid Build Coastguard Worker  def __init__(self, output_manager):
23*8975f5c5SAndroid Build Coastguard Worker    """Environment constructor.
24*8975f5c5SAndroid Build Coastguard Worker
25*8975f5c5SAndroid Build Coastguard Worker    Args:
26*8975f5c5SAndroid Build Coastguard Worker      output_manager: Instance of |output_manager.OutputManager| used to
27*8975f5c5SAndroid Build Coastguard Worker          save test output.
28*8975f5c5SAndroid Build Coastguard Worker    """
29*8975f5c5SAndroid Build Coastguard Worker    self._output_manager = output_manager
30*8975f5c5SAndroid Build Coastguard Worker
31*8975f5c5SAndroid Build Coastguard Worker    # Some subclasses have different teardown behavior on receiving SIGTERM.
32*8975f5c5SAndroid Build Coastguard Worker    self._received_sigterm = False
33*8975f5c5SAndroid Build Coastguard Worker
34*8975f5c5SAndroid Build Coastguard Worker  def SetUp(self):
35*8975f5c5SAndroid Build Coastguard Worker    raise NotImplementedError
36*8975f5c5SAndroid Build Coastguard Worker
37*8975f5c5SAndroid Build Coastguard Worker  def TearDown(self):
38*8975f5c5SAndroid Build Coastguard Worker    raise NotImplementedError
39*8975f5c5SAndroid Build Coastguard Worker
40*8975f5c5SAndroid Build Coastguard Worker  def __enter__(self):
41*8975f5c5SAndroid Build Coastguard Worker    self.SetUp()
42*8975f5c5SAndroid Build Coastguard Worker    return self
43*8975f5c5SAndroid Build Coastguard Worker
44*8975f5c5SAndroid Build Coastguard Worker  def __exit__(self, _exc_type, _exc_val, _exc_tb):
45*8975f5c5SAndroid Build Coastguard Worker    self.TearDown()
46*8975f5c5SAndroid Build Coastguard Worker
47*8975f5c5SAndroid Build Coastguard Worker  @property
48*8975f5c5SAndroid Build Coastguard Worker  def output_manager(self):
49*8975f5c5SAndroid Build Coastguard Worker    return self._output_manager
50*8975f5c5SAndroid Build Coastguard Worker
51*8975f5c5SAndroid Build Coastguard Worker  def ReceivedSigterm(self):
52*8975f5c5SAndroid Build Coastguard Worker    self._received_sigterm = True
53