def CLANG_BASE(version): version = Version(version) return FakeCompiler({ '__clang__': 1, '__clang_major__': version.major, '__clang_minor__': version.minor, '__clang_patchlevel__': version.patch, })
def GCC_BASE(version): version = Version(version) return FakeCompiler({ '__GNUC__': version.major, '__GNUC_MINOR__': version.minor, '__GNUC_PATCHLEVEL__': version.patch, '__STDC__': 1, })
def GCC_BASE(version): version = Version(version) return FakeCompiler({ '__GNUC__': version.major, '__GNUC_MINOR__': version.minor, '__GNUC_PATCHLEVEL__': version.patch, '__STDC__': 1, '__ORDER_LITTLE_ENDIAN__': 1234, '__ORDER_BIG_ENDIAN__': 4321, })
def VS(version): version = Version(version) return FakeCompiler({ None: { '_MSC_VER': '%02d%02d' % (version.major, version.minor), '_MSC_FULL_VER': '%02d%02d%05d' % (version.major, version.minor, version.patch), }, '*.cpp': DEFAULT_CXX_97, })
def mock_compiler(stdin, args): args, test_file = args[:-1], args[-1] self.assertIn('-c', args) for flag in expected_flags: self.assertIn(flag, args) if expected_test_content: with open(test_file) as fh: test_content = fh.read() self.assertEqual(test_content, expected_test_content) return FakeCompiler()(None, args)
def CLANG_PLATFORM(gcc_platform): base = { '--target=x86_64-linux-gnu': GCC_PLATFORM_X86_64_LINUX[None], '--target=x86_64-darwin11.2.0': GCC_PLATFORM_X86_64_OSX[None], '--target=i686-linux-gnu': GCC_PLATFORM_X86_LINUX[None], '--target=i686-darwin11.2.0': GCC_PLATFORM_X86_OSX[None], '--target=arm-linux-gnu': GCC_PLATFORM_ARM_LINUX[None], } undo_gcc_platform = { k: {symbol: False for symbol in gcc_platform[None]} for k in base } return FakeCompiler(gcc_platform, undo_gcc_platform, base)
def mock_compiler(stdin, args): test_file = [a for a in args if not a.startswith('-')] self.assertEqual(len(test_file), 1) test_file = test_file[0] args = [a for a in args if a.startswith('-')] self.assertIn('-c', args) for flag in expected_flags: self.assertIn(flag, args) if expected_test_content: with open(test_file) as fh: test_content = fh.read() self.assertEqual(test_content, expected_test_content) return FakeCompiler()(None, args)
class LinuxCrossCompileToolchainTest(BaseToolchainTest): TARGET = 'arm-unknown-linux-gnu' PATHS = { '/usr/bin/arm-linux-gnu-gcc': GCC_4_9 + GCC_PLATFORM_ARM_LINUX, '/usr/bin/arm-linux-gnu-g++': GXX_4_9 + GCC_PLATFORM_ARM_LINUX, '/usr/bin/arm-linux-gnu-gcc-4.7': GCC_4_7 + GCC_PLATFORM_ARM_LINUX, '/usr/bin/arm-linux-gnu-g++-4.7': GXX_4_7 + GCC_PLATFORM_ARM_LINUX, '/usr/bin/arm-linux-gnu-gcc-5': GCC_5 + GCC_PLATFORM_ARM_LINUX, '/usr/bin/arm-linux-gnu-g++-5': GXX_5 + GCC_PLATFORM_ARM_LINUX, } PATHS.update(LinuxToolchainTest.PATHS) ARM_GCC_4_7_RESULT = LinuxToolchainTest.GXX_4_7_RESULT ARM_GCC_5_RESULT = LinuxToolchainTest.GCC_5_RESULT + { 'compiler': '/usr/bin/arm-linux-gnu-gcc-5', } ARM_GXX_5_RESULT = LinuxToolchainTest.GXX_5_RESULT + { 'compiler': '/usr/bin/arm-linux-gnu-g++-5', } CLANG_3_6_RESULT = LinuxToolchainTest.CLANG_3_6_RESULT CLANGXX_3_6_RESULT = LinuxToolchainTest.CLANGXX_3_6_RESULT GCC_4_9_RESULT = LinuxToolchainTest.GCC_4_9_RESULT GXX_4_9_RESULT = LinuxToolchainTest.GXX_4_9_RESULT little_endian = FakeCompiler(GCC_PLATFORM_LINUX, GCC_PLATFORM_LITTLE_ENDIAN) big_endian = FakeCompiler(GCC_PLATFORM_LINUX, GCC_PLATFORM_BIG_ENDIAN) PLATFORMS = { 'i686-pc-linux-gnu': GCC_PLATFORM_X86_LINUX, 'x86_64-pc-linux-gnu': GCC_PLATFORM_X86_64_LINUX, 'arm-unknown-linux-gnu': GCC_PLATFORM_ARM_LINUX, 'aarch64-unknown-linux-gnu': little_endian + { '__aarch64__': 1, }, 'ia64-unknown-linux-gnu': little_endian + { '__ia64__': 1, }, 's390x-unknown-linux-gnu': big_endian + { '__s390x__': 1, '__s390__': 1, }, 's390-unknown-linux-gnu': big_endian + { '__s390__': 1, }, 'powerpc64-unknown-linux-gnu': big_endian + { None: { '__powerpc64__': 1, '__powerpc__': 1, }, '-m32': { '__powerpc64__': False, }, }, 'powerpc-unknown-linux-gnu': big_endian + { None: { '__powerpc__': 1, }, '-m64': { '__powerpc64__': 1, }, }, 'alpha-unknown-linux-gnu': little_endian + { '__alpha__': 1, }, 'hppa-unknown-linux-gnu': big_endian + { '__hppa__': 1, }, 'sparc64-unknown-linux-gnu': big_endian + { None: { '__arch64__': 1, '__sparc__': 1, }, '-m32': { '__arch64__': False, }, }, 'sparc-unknown-linux-gnu': big_endian + { None: { '__sparc__': 1, }, '-m64': { '__arch64__': 1, }, }, 'mips64-unknown-linux-gnuabi64': big_endian + { '__mips64': 1, '__mips__': 1, }, 'mips-unknown-linux-gnu': big_endian + { '__mips__': 1, }, } PLATFORMS['powerpc64le-unknown-linux-gnu'] = \ PLATFORMS['powerpc64-unknown-linux-gnu'] + GCC_PLATFORM_LITTLE_ENDIAN PLATFORMS['mips64el-unknown-linux-gnuabi64'] = \ PLATFORMS['mips64-unknown-linux-gnuabi64'] + GCC_PLATFORM_LITTLE_ENDIAN PLATFORMS['mipsel-unknown-linux-gnu'] = \ PLATFORMS['mips-unknown-linux-gnu'] + GCC_PLATFORM_LITTLE_ENDIAN def do_test_cross_gcc_32_64(self, host, target): self.HOST = host self.TARGET = target paths = { '/usr/bin/gcc': GCC_4_9 + self.PLATFORMS[host], '/usr/bin/g++': GXX_4_9 + self.PLATFORMS[host], } cross_flags = { 'flags': ['-m64' if '64' in target else '-m32'] } self.do_toolchain_test(paths, { 'c_compiler': self.GCC_4_9_RESULT + cross_flags, 'cxx_compiler': self.GXX_4_9_RESULT + cross_flags, 'host_c_compiler': self.GCC_4_9_RESULT, 'host_cxx_compiler': self.GXX_4_9_RESULT, }) self.HOST = LinuxCrossCompileToolchainTest.HOST self.TARGET = LinuxCrossCompileToolchainTest.TARGET def test_cross_x86_x64(self): self.do_test_cross_gcc_32_64( 'i686-pc-linux-gnu', 'x86_64-pc-linux-gnu') self.do_test_cross_gcc_32_64( 'x86_64-pc-linux-gnu', 'i686-pc-linux-gnu') def test_cross_sparc_sparc64(self): self.do_test_cross_gcc_32_64( 'sparc-unknown-linux-gnu', 'sparc64-unknown-linux-gnu') self.do_test_cross_gcc_32_64( 'sparc64-unknown-linux-gnu', 'sparc-unknown-linux-gnu') def test_cross_ppc_ppc64(self): self.do_test_cross_gcc_32_64( 'powerpc-unknown-linux-gnu', 'powerpc64-unknown-linux-gnu') self.do_test_cross_gcc_32_64( 'powerpc64-unknown-linux-gnu', 'powerpc-unknown-linux-gnu') def do_test_cross_gcc(self, host, target): self.HOST = host self.TARGET = target host_cpu = host.split('-')[0] cpu, manufacturer, os = target.split('-', 2) toolchain_prefix = '/usr/bin/%s-%s' % (cpu, os) paths = { '/usr/bin/gcc': GCC_4_9 + self.PLATFORMS[host], '/usr/bin/g++': GXX_4_9 + self.PLATFORMS[host], } self.do_toolchain_test(paths, { 'c_compiler': ('Target C compiler target CPU (%s) ' 'does not match --target CPU (%s)' % (host_cpu, cpu)), }) paths.update({ '%s-gcc' % toolchain_prefix: GCC_4_9 + self.PLATFORMS[target], '%s-g++' % toolchain_prefix: GXX_4_9 + self.PLATFORMS[target], }) self.do_toolchain_test(paths, { 'c_compiler': self.GCC_4_9_RESULT + { 'compiler': '%s-gcc' % toolchain_prefix, }, 'cxx_compiler': self.GXX_4_9_RESULT + { 'compiler': '%s-g++' % toolchain_prefix, }, 'host_c_compiler': self.GCC_4_9_RESULT, 'host_cxx_compiler': self.GXX_4_9_RESULT, }) self.HOST = LinuxCrossCompileToolchainTest.HOST self.TARGET = LinuxCrossCompileToolchainTest.TARGET def test_cross_gcc_misc(self): for target in self.PLATFORMS: if not target.endswith('-pc-linux-gnu'): self.do_test_cross_gcc('x86_64-pc-linux-gnu', target) def test_cannot_cross(self): self.TARGET = 'mipsel-unknown-linux-gnu' paths = { '/usr/bin/gcc': GCC_4_9 + self.PLATFORMS['mips-unknown-linux-gnu'], '/usr/bin/g++': GXX_4_9 + self.PLATFORMS['mips-unknown-linux-gnu'], } self.do_toolchain_test(paths, { 'c_compiler': ('Target C compiler target endianness (big) ' 'does not match --target endianness (little)'), }) self.TARGET = LinuxCrossCompileToolchainTest.TARGET def test_overridden_cross_gcc(self): self.do_toolchain_test(self.PATHS, { 'c_compiler': self.ARM_GCC_5_RESULT, 'cxx_compiler': self.ARM_GXX_5_RESULT, 'host_c_compiler': self.GCC_4_9_RESULT, 'host_cxx_compiler': self.GXX_4_9_RESULT, }, environ={ 'CC': 'arm-linux-gnu-gcc-5', 'CXX': 'arm-linux-gnu-g++-5', }) def test_overridden_unsupported_cross_gcc(self): self.do_toolchain_test(self.PATHS, { 'c_compiler': self.ARM_GCC_4_7_RESULT, }, environ={ 'CC': 'arm-linux-gnu-gcc-4.7', 'CXX': 'arm-linux-gnu-g++-4.7', }) def test_guess_cross_cxx(self): # When CXX is not set, we guess it from CC. self.do_toolchain_test(self.PATHS, { 'c_compiler': self.ARM_GCC_5_RESULT, 'cxx_compiler': self.ARM_GXX_5_RESULT, 'host_c_compiler': self.GCC_4_9_RESULT, 'host_cxx_compiler': self.GXX_4_9_RESULT, }, environ={ 'CC': 'arm-linux-gnu-gcc-5', }) self.do_toolchain_test(self.PATHS, { 'c_compiler': self.ARM_GCC_5_RESULT, 'cxx_compiler': self.ARM_GXX_5_RESULT, 'host_c_compiler': self.CLANG_3_6_RESULT, 'host_cxx_compiler': self.CLANGXX_3_6_RESULT, }, environ={ 'CC': 'arm-linux-gnu-gcc-5', 'HOST_CC': 'clang', }) self.do_toolchain_test(self.PATHS, { 'c_compiler': self.ARM_GCC_5_RESULT, 'cxx_compiler': self.ARM_GXX_5_RESULT, 'host_c_compiler': self.CLANG_3_6_RESULT, 'host_cxx_compiler': self.CLANGXX_3_6_RESULT, }, environ={ 'CC': 'arm-linux-gnu-gcc-5', 'CXX': 'arm-linux-gnu-g++-5', 'HOST_CC': 'clang', }) def test_cross_clang(self): cross_clang_result = self.CLANG_3_6_RESULT + { 'flags': ['--target=arm-linux-gnu'], } cross_clangxx_result = self.CLANGXX_3_6_RESULT + { 'flags': ['--target=arm-linux-gnu'], } self.do_toolchain_test(self.PATHS, { 'c_compiler': cross_clang_result, 'cxx_compiler': cross_clangxx_result, 'host_c_compiler': self.CLANG_3_6_RESULT, 'host_cxx_compiler': self.CLANGXX_3_6_RESULT, }, environ={ 'CC': 'clang', 'HOST_CC': 'clang', }) self.do_toolchain_test(self.PATHS, { 'c_compiler': cross_clang_result, 'cxx_compiler': cross_clangxx_result, 'host_c_compiler': self.CLANG_3_6_RESULT, 'host_cxx_compiler': self.CLANGXX_3_6_RESULT, }, environ={ 'CC': 'clang', }) def test_cross_atypical_clang(self): paths = dict(self.PATHS) paths.update({ '/usr/bin/afl-clang-fast': paths['/usr/bin/clang'], '/usr/bin/afl-clang-fast++': paths['/usr/bin/clang++'], }) afl_clang_result = self.CLANG_3_6_RESULT + { 'compiler': '/usr/bin/afl-clang-fast', } afl_clangxx_result = self.CLANGXX_3_6_RESULT + { 'compiler': '/usr/bin/afl-clang-fast++', } self.do_toolchain_test(paths, { 'c_compiler': afl_clang_result + { 'flags': ['--target=arm-linux-gnu'], }, 'cxx_compiler': afl_clangxx_result + { 'flags': ['--target=arm-linux-gnu'], }, 'host_c_compiler': afl_clang_result, 'host_cxx_compiler': afl_clangxx_result, }, environ={ 'CC': 'afl-clang-fast', 'CXX': 'afl-clang-fast++', })
GCC_4_7 = GCC('4.7.3') GXX_4_7 = GXX('4.7.3') GCC_4_9 = GCC('4.9.3') GXX_4_9 = GXX('4.9.3') GCC_5 = GCC('5.2.1') + DEFAULT_C11 GXX_5 = GXX('5.2.1') GCC_PLATFORM_LITTLE_ENDIAN = { '__BYTE_ORDER__': 1234, } GCC_PLATFORM_BIG_ENDIAN = { '__BYTE_ORDER__': 4321, } GCC_PLATFORM_X86 = FakeCompiler(GCC_PLATFORM_LITTLE_ENDIAN) + { None: { '__i386__': 1, }, '-m64': { '__i386__': False, '__x86_64__': 1, }, } GCC_PLATFORM_X86_64 = FakeCompiler(GCC_PLATFORM_LITTLE_ENDIAN) + { None: { '__x86_64__': 1, }, '-m32': { '__x86_64__': False,