2016-09-17 23:06:38 +08:00
|
|
|
#!/usr/bin/env python3
|
2023-12-14 03:38:41 +08:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2021-05-09 03:21:04 +08:00
|
|
|
# Copyright 2016-2021 The Meson development team
|
2016-09-17 23:06:38 +08:00
|
|
|
|
2021-06-22 22:20:14 +08:00
|
|
|
# Work around some pathlib bugs...
|
|
|
|
from mesonbuild import _pathlib
|
|
|
|
import sys
|
|
|
|
sys.modules['pathlib'] = _pathlib
|
|
|
|
|
2020-09-12 05:27:18 +08:00
|
|
|
import time
|
2016-09-17 23:06:38 +08:00
|
|
|
import subprocess
|
2017-05-17 15:42:16 +08:00
|
|
|
import os
|
|
|
|
import unittest
|
2017-06-09 15:30:20 +08:00
|
|
|
|
|
|
|
import mesonbuild.mlog
|
2019-07-27 21:25:38 +08:00
|
|
|
import mesonbuild.depfile
|
2020-01-29 01:20:26 +08:00
|
|
|
import mesonbuild.dependencies.base
|
2021-06-01 01:46:09 +08:00
|
|
|
import mesonbuild.dependencies.factory
|
2017-01-21 13:45:14 +08:00
|
|
|
import mesonbuild.compilers
|
2020-01-14 03:15:36 +08:00
|
|
|
import mesonbuild.envconfig
|
2016-10-29 01:02:46 +08:00
|
|
|
import mesonbuild.environment
|
2017-08-15 02:01:34 +08:00
|
|
|
import mesonbuild.coredata
|
2018-02-20 01:36:37 +08:00
|
|
|
import mesonbuild.modules.gnome
|
2021-09-30 23:54:43 +08:00
|
|
|
from mesonbuild.mesonlib import python_command, setup_vsenv
|
2018-04-15 02:57:12 +08:00
|
|
|
import mesonbuild.modules.pkgconfig
|
2016-09-18 02:48:41 +08:00
|
|
|
|
2021-07-25 06:31:45 +08:00
|
|
|
from unittests.allplatformstests import AllPlatformTests
|
2022-02-25 06:18:14 +08:00
|
|
|
from unittests.cargotests import CargoVersionTest, CargoCfgTest
|
2021-07-25 06:31:45 +08:00
|
|
|
from unittests.darwintests import DarwinTests
|
|
|
|
from unittests.failuretests import FailureTests
|
|
|
|
from unittests.linuxcrosstests import LinuxCrossArmTests, LinuxCrossMingwTests
|
|
|
|
from unittests.machinefiletests import NativeFileTests, CrossFileTests
|
|
|
|
from unittests.rewritetests import RewriterTests
|
|
|
|
from unittests.taptests import TAPParserTests
|
|
|
|
from unittests.datatests import DataTests
|
|
|
|
from unittests.internaltests import InternalTests
|
|
|
|
from unittests.linuxliketests import LinuxlikeTests
|
|
|
|
from unittests.pythontests import PythonTests
|
|
|
|
from unittests.subprojectscommandtests import SubprojectsCommandTests
|
|
|
|
from unittests.windowstests import WindowsTests
|
2021-09-21 02:57:20 +08:00
|
|
|
from unittests.platformagnostictests import PlatformAgnosticTests
|
2019-07-08 21:19:08 +08:00
|
|
|
|
2017-04-23 06:11:25 +08:00
|
|
|
def unset_envs():
|
2018-04-25 08:17:55 +08:00
|
|
|
# For unit tests we must fully control all command lines
|
2017-04-23 06:11:25 +08:00
|
|
|
# so that there are no unexpected changes coming from the
|
|
|
|
# environment, for example when doing a package build.
|
2020-12-09 02:33:11 +08:00
|
|
|
varnames = ['CPPFLAGS', 'LDFLAGS'] + list(mesonbuild.compilers.compilers.CFLAGS_MAPPING.values())
|
2017-04-23 06:11:25 +08:00
|
|
|
for v in varnames:
|
|
|
|
if v in os.environ:
|
|
|
|
del os.environ[v]
|
|
|
|
|
2019-07-26 05:43:46 +08:00
|
|
|
def convert_args(argv):
|
|
|
|
# If we got passed a list of tests, pass it on
|
|
|
|
pytest_args = ['-v'] if '-v' in argv else []
|
|
|
|
test_list = []
|
|
|
|
for arg in argv:
|
|
|
|
if arg.startswith('-'):
|
2020-06-11 13:05:28 +08:00
|
|
|
if arg in ('-f', '--failfast'):
|
|
|
|
arg = '--exitfirst'
|
|
|
|
pytest_args.append(arg)
|
2019-07-26 05:43:46 +08:00
|
|
|
continue
|
|
|
|
# ClassName.test_name => 'ClassName and test_name'
|
|
|
|
if '.' in arg:
|
|
|
|
arg = ' and '.join(arg.split('.'))
|
|
|
|
test_list.append(arg)
|
|
|
|
if test_list:
|
|
|
|
pytest_args += ['-k', ' or '.join(test_list)]
|
|
|
|
return pytest_args
|
|
|
|
|
2020-09-10 15:40:40 +08:00
|
|
|
def running_single_tests(argv, cases):
|
|
|
|
'''
|
|
|
|
Check whether we only got arguments for running individual tests, not
|
|
|
|
entire testcases, and not all testcases (no test args).
|
|
|
|
'''
|
|
|
|
got_test_arg = False
|
|
|
|
for arg in argv:
|
|
|
|
if arg.startswith('-'):
|
|
|
|
continue
|
|
|
|
for case in cases:
|
|
|
|
if not arg.startswith(case):
|
|
|
|
continue
|
|
|
|
if '.' not in arg:
|
|
|
|
# Got a testcase, done
|
|
|
|
return False
|
|
|
|
got_test_arg = True
|
|
|
|
return got_test_arg
|
|
|
|
|
2021-05-08 06:56:58 +08:00
|
|
|
def setup_backend():
|
|
|
|
filtered = []
|
|
|
|
be = 'ninja'
|
|
|
|
for a in sys.argv:
|
|
|
|
if a.startswith('--backend'):
|
|
|
|
be = a.split('=')[1]
|
|
|
|
else:
|
|
|
|
filtered.append(a)
|
|
|
|
# Since we invoke the tests via unittest or xtest test runner
|
|
|
|
# we need to pass the backend to use to the spawned process via
|
|
|
|
# this side channel. Yes it sucks, but at least is is fully
|
|
|
|
# internal to this file.
|
|
|
|
os.environ['MESON_UNIT_TEST_BACKEND'] = be
|
|
|
|
sys.argv = filtered
|
|
|
|
|
2018-10-11 03:17:24 +08:00
|
|
|
def main():
|
2017-04-23 06:11:25 +08:00
|
|
|
unset_envs()
|
2021-05-08 06:56:58 +08:00
|
|
|
setup_backend()
|
2018-09-21 00:13:25 +08:00
|
|
|
cases = ['InternalTests', 'DataTests', 'AllPlatformTests', 'FailureTests',
|
2019-02-24 04:11:18 +08:00
|
|
|
'PythonTests', 'NativeFileTests', 'RewriterTests', 'CrossFileTests',
|
2021-09-21 02:57:20 +08:00
|
|
|
'TAPParserTests', 'SubprojectsCommandTests', 'PlatformAgnosticTests',
|
2019-02-27 14:25:33 +08:00
|
|
|
|
2019-02-24 04:11:18 +08:00
|
|
|
'LinuxlikeTests', 'LinuxCrossArmTests', 'LinuxCrossMingwTests',
|
|
|
|
'WindowsTests', 'DarwinTests']
|
2017-08-12 02:23:01 +08:00
|
|
|
|
2020-10-14 01:44:41 +08:00
|
|
|
try:
|
|
|
|
import pytest # noqa: F401
|
|
|
|
pytest_args = []
|
2022-02-01 08:10:37 +08:00
|
|
|
try:
|
|
|
|
# Need pytest-xdist for `-n` arg
|
|
|
|
import xdist # noqa: F401
|
|
|
|
# Don't use pytest-xdist when running single unit tests since it wastes
|
|
|
|
# time spawning a lot of processes to distribute tests to in that case.
|
|
|
|
if not running_single_tests(sys.argv, cases):
|
|
|
|
pytest_args += ['-n', 'auto']
|
|
|
|
except ImportError:
|
|
|
|
print('pytest-xdist not found, tests will not be distributed across CPU cores')
|
2021-06-09 17:02:38 +08:00
|
|
|
# Let there be colors!
|
|
|
|
if 'CI' in os.environ:
|
|
|
|
pytest_args += ['--color=yes']
|
2023-08-15 01:45:35 +08:00
|
|
|
pytest_args += ['unittests']
|
2020-10-14 01:44:41 +08:00
|
|
|
pytest_args += convert_args(sys.argv[1:])
|
2021-06-07 19:00:59 +08:00
|
|
|
# Always disable pytest-cov because we use a custom setup
|
|
|
|
try:
|
|
|
|
import pytest_cov # noqa: F401
|
|
|
|
print('Disabling pytest-cov')
|
|
|
|
pytest_args += ['-p' 'no:cov']
|
|
|
|
except ImportError:
|
|
|
|
pass
|
2020-10-14 01:44:41 +08:00
|
|
|
return subprocess.run(python_command + ['-m', 'pytest'] + pytest_args).returncode
|
|
|
|
except ImportError:
|
2022-02-01 08:10:37 +08:00
|
|
|
print('pytest not found, using unittest instead')
|
2020-09-10 15:40:40 +08:00
|
|
|
# Fallback to plain unittest.
|
2018-10-11 03:17:24 +08:00
|
|
|
return unittest.main(defaultTest=cases, buffer=True)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-05-09 03:21:04 +08:00
|
|
|
setup_vsenv()
|
2020-05-15 01:55:46 +08:00
|
|
|
print('Meson build system', mesonbuild.coredata.version, 'Unit Tests')
|
2020-09-12 05:27:18 +08:00
|
|
|
start = time.monotonic()
|
|
|
|
try:
|
|
|
|
raise SystemExit(main())
|
|
|
|
finally:
|
|
|
|
print('Total time: {:.3f} seconds'.format(time.monotonic() - start))
|