1#!/usr/bin/python 2# 3# Copyright 2018 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import importlib 18import os 19import sys 20import unittest 21 22import namespace 23 24test_modules = [ 25 'anycast_test', 26 'bpf_test', 27 'csocket_test', 28 'cstruct_test', 29 'forwarding_test', 30 'leak_test', 31 'multinetwork_test', 32 'neighbour_test', 33 'nf_test', 34 'pf_key_test', 35 'ping6_test', 36 'policy_crash_test', 37 'qtaguid_test', 38 'removed_feature_test', 39 'resilient_rs_test', 40 'sock_diag_test', 41 'srcaddr_selection_test', 42 'tcp_fastopen_test', 43 'tcp_nuke_addr_test', 44 'tcp_repair_test', 45 'tcp_test', 46 'xfrm_algorithm_test', 47 'xfrm_test', 48 'xfrm_tunnel_test', 49] 50 51if __name__ == '__main__': 52 # Check whether ADB over TCP is occupying TCP port 5555, 53 # or if we're on a real Android device 54 if os.path.isdir('/system') or namespace.HasEstablishedTcpSessionOnPort(5555): 55 namespace.IfPossibleEnterNewNetworkNamespace() 56 # First, run InjectTests on all modules, to ensure that any parameterized 57 # tests in those modules are injected. 58 for name in test_modules: 59 importlib.import_module(name) 60 if hasattr(sys.modules[name], 'InjectTests'): 61 sys.modules[name].InjectTests() 62 63 loader = unittest.defaultTestLoader 64 if len(sys.argv) > 1: 65 test_suite = loader.loadTestsFromNames(sys.argv[1:]) 66 else: 67 test_suite = loader.loadTestsFromNames(test_modules) 68 69 assert test_suite.countTestCases() > 0, ( 70 'Inconceivable: no tests found! Command line: %s' % ' '.join(sys.argv)) 71 72 runner = unittest.TextTestRunner(verbosity=2) 73 result = runner.run(test_suite) 74 sys.exit(not result.wasSuccessful()) 75