1#!/usr/bin/python3 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 gki 23import namespace 24import net_test 25 26all_test_modules = [ 27 'anycast_test', 28 'bpf_test', 29 'csocket_test', 30 'cstruct_test', 31 'kernel_feature_test', 32 'leak_test', 33 'multinetwork_test', 34 'neighbour_test', 35 'netlink_test', 36 'nf_test', 37 'parameterization_test', 38 'ping6_test', 39 'policy_crash_test', 40 'resilient_rs_test', 41 'sock_diag_test', 42 'srcaddr_selection_test', 43 'sysctls_test', 44 'tcp_fastopen_test', 45 'tcp_nuke_addr_test', 46 'tcp_repair_test', 47 'xfrm_algorithm_test', 48 'xfrm_test', 49 'xfrm_tunnel_test', 50] 51 52 53def RunTests(modules_to_test): 54 print('Running on %s %s %s %s-%sbit%s%s' 55 % (os.uname()[0], os.uname()[2], net_test.LINUX_VERSION, os.uname()[4], 56 '64' if sys.maxsize > 0x7FFFFFFF else '32', 57 ' GKI' if gki.IS_GKI else '', ' GSI' if net_test.IS_GSI else ''), 58 file=sys.stderr) 59 namespace.EnterNewNetworkNamespace() 60 61 # First, run InjectTests on all modules, to ensure that any parameterized 62 # tests in those modules are injected. 63 for name in modules_to_test: 64 importlib.import_module(name) 65 if hasattr(sys.modules[name], 'InjectTests'): 66 sys.modules[name].InjectTests() 67 68 test_suite = unittest.defaultTestLoader.loadTestsFromNames(modules_to_test) 69 70 assert test_suite.countTestCases() > 0, ( 71 'Inconceivable: no tests found! Command line: %s' % ' '.join(sys.argv)) 72 73 runner = unittest.TextTestRunner(verbosity=2) 74 result = runner.run(test_suite) 75 sys.exit(not result.wasSuccessful()) 76 77 78if __name__ == '__main__': 79 # If one or more tests were passed in on the command line, only run those. 80 if len(sys.argv) > 1: 81 RunTests(sys.argv[1:]) 82 else: 83 RunTests(all_test_modules) 84