xref: /aosp_15_r20/tools/treble/build/test.py (revision 105f628577ac4ba0e277a494fbb614ed8c12a994)
1*105f6285SAndroid Build Coastguard Worker# Copyright 2019 Google LLC
2*105f6285SAndroid Build Coastguard Worker#
3*105f6285SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
4*105f6285SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
5*105f6285SAndroid Build Coastguard Worker# You may obtain a copy of the License at
6*105f6285SAndroid Build Coastguard Worker#
7*105f6285SAndroid Build Coastguard Worker#     https://www.apache.org/licenses/LICENSE-2.0
8*105f6285SAndroid Build Coastguard Worker#
9*105f6285SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
10*105f6285SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
11*105f6285SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*105f6285SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
13*105f6285SAndroid Build Coastguard Worker# limitations under the License.
14*105f6285SAndroid Build Coastguard Worker
15*105f6285SAndroid Build Coastguard Worker"""Runs all tests in this project.
16*105f6285SAndroid Build Coastguard Worker"""
17*105f6285SAndroid Build Coastguard Worker
18*105f6285SAndroid Build Coastguard Workerimport unittest
19*105f6285SAndroid Build Coastguard Workerimport os
20*105f6285SAndroid Build Coastguard Workerimport pkgutil
21*105f6285SAndroid Build Coastguard Workerimport sys
22*105f6285SAndroid Build Coastguard Worker
23*105f6285SAndroid Build Coastguard Workerdef run():
24*105f6285SAndroid Build Coastguard Worker  test_modules = [
25*105f6285SAndroid Build Coastguard Worker    mod.name
26*105f6285SAndroid Build Coastguard Worker    for mod in pkgutil.walk_packages()
27*105f6285SAndroid Build Coastguard Worker    if mod.name.endswith('_test')
28*105f6285SAndroid Build Coastguard Worker  ]
29*105f6285SAndroid Build Coastguard Worker
30*105f6285SAndroid Build Coastguard Worker  suite = unittest.defaultTestLoader.loadTestsFromNames(test_modules)
31*105f6285SAndroid Build Coastguard Worker
32*105f6285SAndroid Build Coastguard Worker  runner = unittest.TextTestRunner(verbosity=2)
33*105f6285SAndroid Build Coastguard Worker  result = runner.run(suite)
34*105f6285SAndroid Build Coastguard Worker  sys.exit(not result.wasSuccessful())
35*105f6285SAndroid Build Coastguard Worker
36*105f6285SAndroid Build Coastguard Worker
37*105f6285SAndroid Build Coastguard Workerif __name__ == '__main__':
38*105f6285SAndroid Build Coastguard Worker  run()
39