1#!/usr/bin/python2.4
2#
3#
4# Copyright 2009, The Android Open Source Project
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18"""Abstract Android test suite."""
19
20
21class AbstractTestSuite(object):
22  """Represents a generic test suite definition.
23
24  TODO: rename this as AbstractTestDef.
25  """
26
27  def __init__(self):
28    self._name = None
29    self._build_path = None
30    self._build_dependencies = []
31    self._is_continuous = False
32    self._suite = None
33    self._description = ''
34    self._extra_build_args = ''
35    self._is_full_make = False
36    self._is_granted_permissions = True
37
38  def GetName(self):
39    return self._name
40
41  def SetName(self, name):
42    self._name = name
43    return self
44
45  def GetBuildPath(self):
46    """Returns the build path of this test, relative to source tree root."""
47    return self._build_path
48
49  def SetBuildPath(self, build_path):
50    self._build_path = build_path
51    return self
52
53  def GetBuildDependencies(self, options):
54    """Returns a list of dependent build paths."""
55    return self._build_dependencies
56
57  def SetBuildDependencies(self, build_dependencies):
58    self._build_dependencies = build_dependencies
59    return self
60
61  def IsContinuous(self):
62    """Returns true if test is part of the continuous test."""
63    return self._is_continuous
64
65  def SetContinuous(self, continuous):
66    self._is_continuous = continuous
67    return self._is_continuous
68
69  def IsGrantedPermissions(self):
70    """Return true if the test should be granted runtime permissions on install."""
71    return self._is_granted_permissions
72
73  def SetIsGrantedPermissions(self, is_granted_permissions):
74    self._is_granted_permissions = is_granted_permissions
75    return self._is_granted_permissions
76
77  def GetSuite(self):
78    """Returns the name of test' suite, or None."""
79    return self._suite
80
81  def SetSuite(self, suite):
82    self._suite = suite
83    return self
84
85  def GetDescription(self):
86    """Returns a description if available, an empty string otherwise."""
87    return self._description
88
89  def SetDescription(self, desc):
90    self._description = desc
91    return self
92
93  def GetExtraBuildArgs(self):
94    """Returns the extra build args if available, an empty string otherwise."""
95    return self._extra_build_args
96
97  def SetExtraBuildArgs(self, build_args):
98    self._extra_build_args = build_args
99    return self
100
101  def IsFullMake(self):
102    return self._is_full_make
103
104  def SetIsFullMake(self, full_make):
105    self._is_full_make = full_make
106    return self
107
108  def Run(self, options, adb):
109    """Runs the test.
110
111    Subclasses must implement this.
112    Args:
113      options: global command line options
114      adb: asdb_interface to device under test
115    """
116    raise NotImplementedError
117
118class AbstractTestFactory(object):
119  """generic test suite factory."""
120
121  def __init__(self, test_root_path, build_path):
122    """Creates a test suite factory.
123
124    Args:
125      test_root_path: the filesystem path to the tests build directory
126      upstream_build_path: filesystem path for the directory
127      to build when running tests, relative to the source tree root.
128    """
129    self._test_root_path = test_root_path
130    self._build_path = build_path
131
132  def GetBuildPath(self):
133    return self._build_path
134
135  def GetTestsRootPath(self):
136    return self._test_root_path
137
138  def CreateTests(self, sub_tests_path=None):
139    """Creates the tests at given test_path.
140
141    Subclasses must implement this.
142
143    Args:
144      sub_tests_path: the child path of test_root_path containing the tests to
145        run. If unspecified will be set to test_root_path.
146
147    Returns:
148      an array of AbstractTestSuite, or empty AbstractTestSuite if no tests
149      were defined
150    """
151    raise NotImplementedError
152