|
| 1 | +# tests/products/test_swift.py ----------------------------------*- python -*- |
| 2 | +# |
| 3 | +# This source file is part of the Swift.org open source project |
| 4 | +# |
| 5 | +# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors |
| 6 | +# Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +# |
| 8 | +# See http://swift.org/LICENSE.txt for license information |
| 9 | +# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +# ---------------------------------------------------------------------------- |
| 11 | + |
| 12 | +import argparse |
| 13 | +import os |
| 14 | +import platform |
| 15 | +import shutil |
| 16 | +import sys |
| 17 | +import tempfile |
| 18 | +import unittest |
| 19 | +try: |
| 20 | + # py2 |
| 21 | + from StringIO import StringIO |
| 22 | +except ImportError: |
| 23 | + # py3 |
| 24 | + from io import StringIO |
| 25 | + |
| 26 | +from swift_build_support import shell |
| 27 | +from swift_build_support import xcrun |
| 28 | +from swift_build_support.products import Swift |
| 29 | +from swift_build_support.toolchain import host_toolchain |
| 30 | +from swift_build_support.workspace import Workspace |
| 31 | + |
| 32 | + |
| 33 | +class SwiftTestCase(unittest.TestCase): |
| 34 | + |
| 35 | + def setUp(self): |
| 36 | + # Setup workspace |
| 37 | + tmpdir1 = os.path.realpath(tempfile.mkdtemp()) |
| 38 | + tmpdir2 = os.path.realpath(tempfile.mkdtemp()) |
| 39 | + os.makedirs(os.path.join(tmpdir1, 'swift')) |
| 40 | + |
| 41 | + self.workspace = Workspace(source_root=tmpdir1, |
| 42 | + build_root=tmpdir2) |
| 43 | + |
| 44 | + # Setup toolchain |
| 45 | + self.toolchain = host_toolchain() |
| 46 | + self.toolchain.cc = '/path/to/cc' |
| 47 | + self.toolchain.cxx = '/path/to/cxx' |
| 48 | + |
| 49 | + # Setup args |
| 50 | + self.args = argparse.Namespace( |
| 51 | + enable_tsan_runtime=False, |
| 52 | + darwin_deployment_version_osx="10.9") |
| 53 | + |
| 54 | + # Setup shell |
| 55 | + shell.dry_run = True |
| 56 | + self._orig_stdout = sys.stdout |
| 57 | + self._orig_stderr = sys.stderr |
| 58 | + self.stdout = StringIO() |
| 59 | + self.stderr = StringIO() |
| 60 | + sys.stdout = self.stdout |
| 61 | + sys.stderr = self.stderr |
| 62 | + |
| 63 | + def tearDown(self): |
| 64 | + shutil.rmtree(self.workspace.build_root) |
| 65 | + shutil.rmtree(self.workspace.source_root) |
| 66 | + sys.stdout = self._orig_stdout |
| 67 | + sys.stderr = self._orig_stderr |
| 68 | + shell.dry_run = False |
| 69 | + self.workspace = None |
| 70 | + self.toolchain = None |
| 71 | + self.args = None |
| 72 | + |
| 73 | + def test_swift_runtime_tsan(self): |
| 74 | + self.args.enable_tsan_runtime = True |
| 75 | + swift = Swift( |
| 76 | + args=self.args, |
| 77 | + toolchain=self.toolchain, |
| 78 | + source_dir='/path/to/src', |
| 79 | + build_dir='/path/to/build') |
| 80 | + self.assertEqual(swift.cmake_options, ['-DSWIFT_RUNTIME_USE_SANITIZERS=Thread']) |
0 commit comments