xref: /aosp_15_r20/kernel/tests/net/test/all_tests.py (revision 2f2c4c7ab4226c71756b9c31670392fdd6887c4f)
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 ctypes
18import importlib
19import os
20import sys
21import unittest
22
23import gki
24import namespace
25import net_test
26
27# man 2 personality
28personality = ctypes.CDLL(None).personality
29personality.restype = ctypes.c_int
30personality.argtypes = [ctypes.c_ulong]
31
32# From Linux kernel's include/uapi/linux/personality.h
33PER_QUERY = 0xFFFFFFFF
34PER_LINUX = 0
35PER_LINUX32 = 8
36
37all_test_modules = [
38    'anycast_test',
39    'bpf_test',
40    'csocket_test',
41    'cstruct_test',
42    'kernel_feature_test',
43    'leak_test',
44    'multinetwork_test',
45    'neighbour_test',
46    'netlink_test',
47    'nf_test',
48    'parameterization_test',
49    'ping6_test',
50    'policy_crash_test',
51    'resilient_rs_test',
52    'sock_diag_test',
53    'srcaddr_selection_test',
54    'sysctls_test',
55    'tcp_fastopen_test',
56    'tcp_nuke_addr_test',
57    'tcp_repair_test',
58    'xfrm_algorithm_test',
59    'xfrm_test',
60    'xfrm_tunnel_test',
61]
62
63
64def RunTests(modules_to_test):
65  uname = os.uname()
66  linux = uname.sysname
67  kver = uname.release
68  arch = uname.machine
69  p = personality(PER_LINUX)
70  true_arch = os.uname().machine
71  personality(p)
72  print('Running on %s %s %s %s/%s-%sbit%s%s'
73        % (linux, kver, net_test.LINUX_VERSION, true_arch, arch,
74           '64' if sys.maxsize > 0x7FFFFFFF else '32',
75           ' GKI' if gki.IS_GKI else '', ' GSI' if net_test.IS_GSI else ''),
76        file=sys.stderr)
77  namespace.EnterNewNetworkNamespace()
78
79  # First, run InjectTests on all modules, to ensure that any parameterized
80  # tests in those modules are injected.
81  for name in modules_to_test:
82    importlib.import_module(name)
83    if hasattr(sys.modules[name], 'InjectTests'):
84      sys.modules[name].InjectTests()
85
86  test_suite = unittest.defaultTestLoader.loadTestsFromNames(modules_to_test)
87
88  assert test_suite.countTestCases() > 0, (
89      'Inconceivable: no tests found! Command line: %s' % ' '.join(sys.argv))
90
91  runner = unittest.TextTestRunner(verbosity=2)
92  result = runner.run(test_suite)
93  sys.exit(not result.wasSuccessful())
94
95
96if __name__ == '__main__':
97  # If one or more tests were passed in on the command line, only run those.
98  if len(sys.argv) > 1:
99    RunTests(sys.argv[1:])
100  else:
101    RunTests(all_test_modules)
102