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 sys 19import unittest 20 21import namespace 22 23test_modules = [ 24 'anycast_test', 25 'bpf_test', 26 'csocket_test', 27 'cstruct_test', 28 'forwarding_test', 29 'leak_test', 30 'multinetwork_test', 31 'neighbour_test', 32 'nf_test', 33 'pf_key_test', 34 'ping6_test', 35 'policy_crash_test', 36 'qtaguid_test', 37 'removed_feature_test', 38 'resilient_rs_test', 39 'sock_diag_test', 40 'srcaddr_selection_test', 41 'tcp_fastopen_test', 42 'tcp_nuke_addr_test', 43 'tcp_repair_test', 44 'tcp_test', 45 'xfrm_algorithm_test', 46 'xfrm_test', 47 'xfrm_tunnel_test', 48] 49 50if __name__ == '__main__': 51 # Check whether ADB over TCP is occupying TCP port 5555. 52 if namespace.HasEstablishedTcpSessionOnPort(5555): 53 namespace.IfPossibleEnterNewNetworkNamespace() 54 # First, run InjectTests on all modules, to ensure that any parameterized 55 # tests in those modules are injected. 56 for name in test_modules: 57 importlib.import_module(name) 58 if hasattr(sys.modules[name], 'InjectTests'): 59 sys.modules[name].InjectTests() 60 61 loader = unittest.defaultTestLoader 62 if len(sys.argv) > 1: 63 test_suite = loader.loadTestsFromNames(sys.argv[1:]) 64 else: 65 test_suite = loader.loadTestsFromNames(test_modules) 66 67 assert test_suite.countTestCases() > 0, ( 68 'Inconceivable: no tests found! Command line: %s' % ' '.join(sys.argv)) 69 70 runner = unittest.TextTestRunner(verbosity=2) 71 result = runner.run(test_suite) 72 sys.exit(not result.wasSuccessful()) 73