run_cross_test.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/env python3
  2. # Copyright 2013-2014 The Meson development team
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. '''Runs the basic test suite through a cross compiler.
  13. Not part of the main test suite because of two reasons:
  14. 1) setup of the cross build is platform specific
  15. 2) it can be slow (e.g. when invoking test apps via wine)
  16. Eventually migrate to something fancier.'''
  17. import os, subprocess, shutil, sys
  18. import environment
  19. from run_tests import gather_tests
  20. test_build_dir = 'work area'
  21. install_dir = os.path.join(os.path.split(os.path.abspath(__file__))[0], 'install dir')
  22. meson_command = './meson.py'
  23. extra_flags = ['--cross-file', sys.argv[1]]
  24. ninja_command = environment.detect_ninja()
  25. if ninja_command is None:
  26. raise RuntimeError('Could not find Ninja executable.')
  27. compile_commands = [ninja_command]
  28. test_commands = [ninja_command, 'test']
  29. install_commands = [ninja_command, 'install']
  30. def run_test(testdir, should_succeed=True):
  31. shutil.rmtree(test_build_dir)
  32. shutil.rmtree(install_dir)
  33. os.mkdir(test_build_dir)
  34. os.mkdir(install_dir)
  35. print('Running test: ' + testdir)
  36. gen_command = [sys.executable, meson_command, '--prefix', '/usr', '--libdir', 'lib', testdir, test_build_dir] + extra_flags
  37. p = subprocess.Popen(gen_command)
  38. p.wait()
  39. if not should_succeed:
  40. if p.returncode != 0:
  41. return
  42. raise RuntimeError('Test that should fail succeeded.')
  43. if p.returncode != 0:
  44. raise RuntimeError('Generating the build system failed.')
  45. pc = subprocess.Popen(compile_commands, cwd=test_build_dir)
  46. pc.wait()
  47. if pc.returncode != 0:
  48. raise RuntimeError('Compiling source code failed.')
  49. pt = subprocess.Popen(test_commands, cwd=test_build_dir)
  50. pt.wait()
  51. if pt.returncode != 0:
  52. raise RuntimeError('Running unit tests failed.')
  53. install_env = os.environ.copy()
  54. install_env['DESTDIR'] = install_dir
  55. pi = subprocess.Popen(install_commands, cwd=test_build_dir, env=install_env)
  56. pi.wait()
  57. if pi.returncode != 0:
  58. raise RuntimeError('Running install failed.')
  59. def run_tests():
  60. commontests = gather_tests('test cases/common')
  61. try:
  62. os.mkdir(test_build_dir)
  63. except OSError:
  64. pass
  65. try:
  66. os.mkdir(install_dir)
  67. except OSError:
  68. pass
  69. print('\nRunning cross compilation tests.\n')
  70. [run_test(t) for t in commontests]
  71. if __name__ == '__main__':
  72. script_dir = os.path.split(__file__)[0]
  73. if script_dir != '':
  74. os.chdir(script_dir)
  75. run_tests()