| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import os | 6 import os |
| 7 import shutil |
| 7 import sys | 8 import sys |
| 9 import tarfile |
| 8 import unittest | 10 import unittest |
| 9 | 11 |
| 10 # add tools folder to sys.path | 12 # add tools folder to sys.path |
| 11 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 13 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 12 sys.path.append(os.path.join(SCRIPT_DIR, 'tools', 'tests')) | 14 TOOLS_DIR = os.path.join(SCRIPT_DIR, 'tools') |
| 13 sys.path.append(os.path.join(SCRIPT_DIR, 'tools', 'lib', 'tests')) | 15 BUILD_TOOLS_DIR = os.path.join(SCRIPT_DIR, 'build_tools') |
| 14 sys.path.append(os.path.join(SCRIPT_DIR, 'build_tools', 'tests')) | 16 sys.path.append(TOOLS_DIR) |
| 17 sys.path.append(os.path.join(TOOLS_DIR, 'tests')) |
| 18 sys.path.append(os.path.join(TOOLS_DIR, 'lib', 'tests')) |
| 19 sys.path.append(BUILD_TOOLS_DIR) |
| 20 sys.path.append(os.path.join(BUILD_TOOLS_DIR, 'tests')) |
| 21 |
| 22 import build_paths |
| 23 import getos |
| 24 |
| 25 TOOLCHAIN_OUT = os.path.join(build_paths.OUT_DIR, 'sdk_tests', 'toolchain') |
| 26 NACL_X86_GLIBC_TOOLCHAIN = os.path.join(TOOLCHAIN_OUT, 'nacl_x86_glibc') |
| 15 | 27 |
| 16 TEST_MODULES = [ | 28 TEST_MODULES = [ |
| 17 'create_html_test', | 29 'create_html_test', |
| 18 'create_nmf_test', | 30 'create_nmf_test', |
| 19 'easy_template_test', | 31 'easy_template_test', |
| 20 'elf_test', | 32 'elf_test', |
| 21 'fix_deps_test', | 33 'fix_deps_test', |
| 22 'getos_test', | 34 'getos_test', |
| 23 'get_shared_deps_test', | 35 'get_shared_deps_test', |
| 24 'httpd_test', | 36 'httpd_test', |
| 25 'nacl_config_test', | 37 'nacl_config_test', |
| 26 'oshelpers_test', | 38 'oshelpers_test', |
| 27 'parse_dsc_test', | 39 'parse_dsc_test', |
| 28 'quote_test', | 40 'quote_test', |
| 29 'sdktools_commands_test', | 41 'sdktools_commands_test', |
| 30 'sdktools_config_test', | 42 'sdktools_config_test', |
| 31 'sdktools_test', | 43 'sdktools_test', |
| 32 'sel_ldr_test', | 44 'sel_ldr_test', |
| 33 'update_nacl_manifest_test', | 45 'update_nacl_manifest_test', |
| 34 'verify_filelist_test', | 46 'verify_filelist_test', |
| 35 'verify_ppapi_test', | 47 'verify_ppapi_test', |
| 36 ] | 48 ] |
| 37 | 49 |
| 50 def ExtractToolchain(): |
| 51 # TODO(dyen): This function is basically all temporary code. After the DEPS |
| 52 # roll, replace this untar with package_version.py which will do the |
| 53 # untarring and be able to check whether or not the toolchain is out of date. |
| 54 platform_name = getos.GetPlatform() |
| 55 nacl_x86_glibc_tar = os.path.join(build_paths.NACL_DIR, 'toolchain', '.tars', |
| 56 'toolchain_%s_x86.tar.bz2' % platform_name) |
| 57 assert os.path.isfile(nacl_x86_glibc_tar), 'Could not locate toolchain tar' |
| 58 |
| 59 stamp_file = os.path.join(NACL_X86_GLIBC_TOOLCHAIN, 'extract.stamp') |
| 60 if (not os.path.isfile(stamp_file) or |
| 61 os.path.getmtime(stamp_file) < os.path.getmtime(nacl_x86_glibc_tar)): |
| 62 |
| 63 print 'Extracting nacl_x86_glibc...' |
| 64 temp_dir = os.path.join(TOOLCHAIN_OUT, 'temp') |
| 65 if os.path.isdir(temp_dir): |
| 66 shutil.rmtree(temp_dir) |
| 67 os.makedirs(temp_dir) |
| 68 with tarfile.open(nacl_x86_glibc_tar) as f: |
| 69 f.extractall(temp_dir) |
| 70 |
| 71 if os.path.isdir(NACL_X86_GLIBC_TOOLCHAIN): |
| 72 shutil.rmtree(NACL_X86_GLIBC_TOOLCHAIN) |
| 73 parent_dir = os.path.dirname(NACL_X86_GLIBC_TOOLCHAIN) |
| 74 if not os.path.isdir(parent_dir): |
| 75 os.makedirs(parent_dir) |
| 76 |
| 77 extracted_path = os.path.join(temp_dir, 'toolchain', |
| 78 '%s_x86' % platform_name) |
| 79 os.rename(extracted_path, NACL_X86_GLIBC_TOOLCHAIN) |
| 80 |
| 81 with open(stamp_file, 'wt') as f: |
| 82 f.write(nacl_x86_glibc_tar) |
| 83 |
| 38 def main(): | 84 def main(): |
| 85 # Some of the unit tests utilize nacl_x86_glibc. Untar a copy in the output |
| 86 # directory for the tests to use. |
| 87 ExtractToolchain() |
| 88 |
| 39 suite = unittest.TestSuite() | 89 suite = unittest.TestSuite() |
| 40 for module_name in TEST_MODULES: | 90 for module_name in TEST_MODULES: |
| 41 module = __import__(module_name) | 91 module = __import__(module_name) |
| 42 suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(module)) | 92 suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(module)) |
| 43 | 93 |
| 44 result = unittest.TextTestRunner(verbosity=2).run(suite) | 94 result = unittest.TextTestRunner(verbosity=2).run(suite) |
| 45 return int(not result.wasSuccessful()) | 95 return int(not result.wasSuccessful()) |
| 46 | 96 |
| 47 if __name__ == '__main__': | 97 if __name__ == '__main__': |
| 48 sys.exit(main()) | 98 sys.exit(main()) |
| OLD | NEW |