Skip to content

Commit c7685e8

Browse files
authored
Merge pull request #1228 from mesonbuild/runcross
Fix cross test and run them if a cross compiler is available.
2 parents 4317edc + 701e393 commit c7685e8

File tree

9 files changed

+62
-83
lines changed

9 files changed

+62
-83
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ __pycache__
1010

1111
/meson-test-run.txt
1212
/meson-test-run.xml
13+
/meson-cross-test-run.txt
14+
/meson-cross-test-run.xml
1315

1416
.DS_Store
1517
*~

cross/ubuntu-armhf.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[binaries]
22
# we could set exe_wrapper = qemu-arm-static but to test the case
33
# when cross compiled binaries can't be run we don't do that
4-
c = '/usr/bin/arm-linux-gnueabihf-gcc'
5-
cpp = '/usr/bin/arm-linux-gnueabihf-g++'
4+
c = '/usr/bin/arm-linux-gnueabihf-gcc-6'
5+
cpp = '/usr/bin/arm-linux-gnueabihf-g++-6'
66
ar = '/usr/arm-linux-gnueabihf/bin/ar'
77
strip = '/usr/arm-linux-gnueabihf/bin/strip'
88
pkgconfig = '/usr/bin/arm-linux-gnueabihf-pkg-config'

mesontest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ def write_json_log(jsonlogfile, test_name, result):
132132
'duration' : result.duration,
133133
'returncode' : result.returncode,
134134
'command' : result.cmd,
135-
'env' : result.env}
135+
}
136+
if isinstance(result.env, dict):
137+
jresult['env'] = result.env
138+
else:
139+
jresult['env'] = result.env.get_env(os.environ)
136140
if result.stde:
137141
jresult['stderr'] = result.stde
138142
jsonlogfile.write(json.dumps(jresult) + '\n')
@@ -198,7 +202,7 @@ def run_single_test(self, wrap, test):
198202
duration = 0.0
199203
stdo = 'Not run because can not execute cross compiled binaries.'
200204
stde = None
201-
returncode = -1
205+
returncode = GNU_SKIP_RETURNCODE
202206
else:
203207
cmd = wrap + cmd + test.cmd_args
204208
starttime = time.time()

run_cross_test.py

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,68 +22,27 @@
2222
2323
Eventually migrate to something fancier.'''
2424

25-
import os, subprocess, shutil, sys
26-
import mesonbuild.environment as environment
25+
import sys, os
2726

28-
from run_tests import gather_tests
27+
from run_project_tests import gather_tests, run_tests, StopException, setup_commands
28+
from run_project_tests import failing_logs
2929

30-
test_build_dir = 'work area'
31-
install_dir = os.path.join(os.path.split(os.path.abspath(__file__))[0], 'install dir')
32-
meson_command = './meson.py'
33-
34-
extra_flags = ['--cross-file', sys.argv[1]]
35-
ninja_command = environment.detect_ninja()
36-
if ninja_command is None:
37-
raise RuntimeError('Could not find Ninja v1.6 or newer')
38-
compile_commands = [ninja_command]
39-
test_commands = [ninja_command, 'test']
40-
install_commands = [ninja_command, 'install']
41-
42-
def run_test(testdir, should_succeed=True):
43-
shutil.rmtree(test_build_dir)
44-
shutil.rmtree(install_dir)
45-
os.mkdir(test_build_dir)
46-
os.mkdir(install_dir)
47-
print('Running test: ' + testdir)
48-
gen_command = [sys.executable, meson_command, '--prefix', '/usr', '--libdir', 'lib', testdir, test_build_dir] + extra_flags
49-
p = subprocess.Popen(gen_command)
50-
p.wait()
51-
if not should_succeed:
52-
if p.returncode != 0:
53-
return
54-
raise RuntimeError('Test that should fail succeeded.')
55-
if p.returncode != 0:
56-
raise RuntimeError('Generating the build system failed.')
57-
pc = subprocess.Popen(compile_commands, cwd=test_build_dir)
58-
pc.wait()
59-
if pc.returncode != 0:
60-
raise RuntimeError('Compiling source code failed.')
61-
pt = subprocess.Popen(test_commands, cwd=test_build_dir)
62-
pt.wait()
63-
if pt.returncode != 0:
64-
raise RuntimeError('Running unit tests failed.')
65-
install_env = os.environ.copy()
66-
install_env['DESTDIR'] = install_dir
67-
pi = subprocess.Popen(install_commands, cwd=test_build_dir, env=install_env)
68-
pi.wait()
69-
if pi.returncode != 0:
70-
raise RuntimeError('Running install failed.')
71-
72-
def run_tests():
73-
commontests = gather_tests('test cases/common')
74-
try:
75-
os.mkdir(test_build_dir)
76-
except OSError:
77-
pass
30+
def runtests(cross_file):
31+
commontests = [('common', gather_tests('test cases/common'), False)]
7832
try:
79-
os.mkdir(install_dir)
80-
except OSError:
33+
(passing_tests, failing_tests, skipped_tests) = run_tests(commontests, 'meson-cross-test-run', ['--cross', cross_file])
34+
except StopException:
8135
pass
82-
print('\nRunning cross compilation tests.\n')
83-
[run_test(t) for t in commontests]
36+
print('\nTotal passed cross tests:', passing_tests)
37+
print('Total failed cross tests:', failing_tests)
38+
print('Total skipped cross tests:', skipped_tests)
39+
if failing_tests > 0 and ('TRAVIS' in os.environ or 'APPVEYOR' in os.environ):
40+
print('\nMesonlogs of failing tests\n')
41+
for l in failing_logs:
42+
print(l, '\n')
43+
sys.exit(failing_tests)
8444

8545
if __name__ == '__main__':
86-
script_dir = os.path.split(__file__)[0]
87-
if script_dir != '':
88-
os.chdir(script_dir)
89-
run_tests()
46+
setup_commands('ninja')
47+
cross_file = sys.argv[1]
48+
runtests(cross_file)

run_project_tests.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ def __exit__(self, _type, value, traceback):
6363
raise
6464
time.sleep(0.1 * (2**i))
6565

66-
passing_tests = 0
67-
failing_tests = 0
68-
skipped_tests = 0
6966
failing_logs = []
7067
print_debug = 'MESON_PRINT_TEST_OUTPUT' in os.environ
7168
do_debug = not {'MESON_PRINT_TEST_OUTPUT', 'TRAVIS', 'APPVEYOR'}.isdisjoint(os.environ)
@@ -370,14 +367,18 @@ def detect_tests_to_run():
370367
all_tests.append(('python3', gather_tests('test cases/python3'), False if using_backend('ninja') and shutil.which('python3') else True))
371368
return all_tests
372369

373-
def run_tests(extra_args):
374-
global install_commands, passing_tests, failing_tests, stop, executor, futures
375-
all_tests = detect_tests_to_run()
376-
logfile = open('meson-test-run.txt', 'w', encoding="utf_8")
370+
def run_tests(all_tests, log_name_base, extra_args):
371+
global stop, executor, futures
372+
txtname = log_name_base + '.txt'
373+
xmlname = log_name_base + '.xml'
374+
logfile = open(txtname, 'w', encoding="utf_8")
377375
junit_root = ET.Element('testsuites')
378376
conf_time = 0
379377
build_time = 0
380378
test_time = 0
379+
passing_tests = 0
380+
failing_tests = 0
381+
skipped_tests = 0
381382

382383
try:
383384
# This fails in some CI environments for unknown reasons.
@@ -412,7 +413,6 @@ def run_tests(extra_args):
412413
current_test = ET.SubElement(current_suite, 'testcase', {'name' : testname,
413414
'classname' : name})
414415
ET.SubElement(current_test, 'skipped', {})
415-
global skipped_tests
416416
skipped_tests += 1
417417
else:
418418
without_install = "" if len(install_commands) > 0 else " (without install)"
@@ -442,7 +442,8 @@ def run_tests(extra_args):
442442
print("\nTotal configuration time: %.2fs" % conf_time)
443443
print("Total build time: %.2fs" % build_time)
444444
print("Total test time: %.2fs" % test_time)
445-
ET.ElementTree(element=junit_root).write('meson-test-run.xml', xml_declaration=True, encoding='UTF-8')
445+
ET.ElementTree(element=junit_root).write(xmlname, xml_declaration=True, encoding='UTF-8')
446+
return (passing_tests, failing_tests, skipped_tests)
446447

447448
def check_file(fname):
448449
linenum = 1
@@ -539,7 +540,8 @@ def generate_prebuilt():
539540
check_format()
540541
pbfiles = generate_prebuilt()
541542
try:
542-
run_tests(options.extra_args)
543+
all_tests = detect_tests_to_run()
544+
(passing_tests, failing_tests, skipped_tests) = run_tests(all_tests, 'meson-test-run', options.extra_args)
543545
except StopException:
544546
pass
545547
for f in pbfiles:

run_tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@
2323
if mesonlib.is_linux():
2424
print('Running unittests.\n')
2525
returncode += subprocess.call([sys.executable, 'run_unittests.py', '-v'])
26+
if shutil.which('arm-linux-gnueabihf-gcc-6'): # Ubuntu packages do not have a binary without -6 suffix.
27+
print('Running cross compilation tests.\n')
28+
returncode += subprocess.call([sys.executable, 'run_cross_test.py', 'cross/ubuntu-armhf.txt'])
2629
returncode += subprocess.call([sys.executable, 'run_project_tests.py'] + sys.argv[1:])
2730
sys.exit(returncode)
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
project('manygen', 'c')
22

3-
subdir('subdir')
3+
if meson.is_cross_build()
4+
# FIXME error out with skip message once cross test runner
5+
# recognizes it.
6+
message('Not running this test during cross build.')
7+
else
8+
subdir('subdir')
49

5-
exe = executable('depuser', 'depuser.c',
6-
generated)
10+
exe = executable('depuser', 'depuser.c',
11+
generated)
712

8-
test('depuser test', exe)
13+
test('depuser test', exe)
14+
endif

test cases/common/111 has header symbol/meson.build

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ assert (cpp.has_header_symbol('iostream', 'std::iostream'), 'iostream not found
2424
assert (cpp.has_header_symbol('vector', 'std::vector'), 'vector not found in vector.h')
2525
assert (not cpp.has_header_symbol('limits.h', 'std::iostream'), 'iostream should not be defined in limits.h')
2626

27-
boost = dependency('boost', required : false)
28-
if boost.found()
29-
assert (cpp.has_header_symbol('boost/math/quaternion.hpp', 'boost::math::quaternion', dependencies : boost), 'quaternion not found')
30-
else
31-
assert (not cpp.has_header_symbol('boost/math/quaternion.hpp', 'boost::math::quaternion', dependencies : boost), 'quaternion found?!')
27+
# Cross compilation and boost do not mix.
28+
if not meson.is_cross_build()
29+
boost = dependency('boost', required : false)
30+
if boost.found()
31+
assert (cpp.has_header_symbol('boost/math/quaternion.hpp', 'boost::math::quaternion', dependencies : boost), 'quaternion not found')
32+
else
33+
assert (not cpp.has_header_symbol('boost/math/quaternion.hpp', 'boost::math::quaternion', dependencies : boost), 'quaternion found?!')
34+
endif
3235
endif

test cases/common/97 selfbuilt custom/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ project('selfbuilt custom', 'cpp')
33
# Build an exe and use it in a custom target
44
# whose output is used to build a different exe.
55

6-
tool = executable('tool', 'tool.cpp')
6+
tool = executable('tool', 'tool.cpp', native : true)
77

88
hfile = custom_target('datah',
99
output : 'data.h',

0 commit comments

Comments
 (0)