Ejemplo n.º 1
0
 def test_no_overrides(self):
     if driver_test_utils.CanRunHost():
         pexe = self.getFakePexe()
         if self.platform == 'arm':
             expected_triple_cpu = ['-mtriple=arm.*', '-mcpu=cortex.*']
         elif self.platform == 'x86-32':
             expected_triple_cpu = ['-mtriple=i686.*', '-mcpu=pentium.*']
         elif self.platform == 'x86-64':
             expected_triple_cpu = ['-mtriple=x86_64.*', '-mcpu=core.*']
         elif self.platform == 'mips':
             expected_triple_cpu = ['-mtriple=mips.*', '-mcpu=mips32.*']
         else:
             raise Exception('Unknown platform: "%s"' % self.platform)
         # Test that certain defaults are set, when no flags are given.
         self.checkLLCTranslateFlags(
             pexe, self.platform, [],
             expected_triple_cpu + ['-bitcode-format=pnacl'])
         # Even with a single module StreamInitWithSplit is used.
         self.checkLLCTranslateFlags(pexe, self.platform,
                                     ['--pnacl-sb', '-split-module=1'],
                                     ['StreamInitWithSplit i\\(1\\).*'])
         # Test that StreamInitWithSplit is used with module splitting.
         # In the tests below, we don't care whether StreamInitWithSplit or
         # StreamInitWithOverrides
         self.checkLLCTranslateFlags(pexe, self.platform, [
             '--pnacl-sb', '-split-module=4'
         ], ['StreamInitWithSplit i\\(4\\) h\\(objfile\\).*h\\(invalid\\)'])
Ejemplo n.º 2
0
 def test_LLVMFile(self):
     if not driver_test_utils.CanRunHost():
         return
     pexe = self.getFakePexe(finalized=False)
     # For non-sandboxed pnacl-llc, the default -bitcode-format=llvm,
     # so there is nothing to really check.
     self.checkCompileTranslateFlags(pexe,
                                     self.platform,
                                     ['--allow-llvm-bitcode-input'],
                                     ['bitcode-format'],
                                     invert_match=True)
     # For sandboxed pnacl-llc, the default -bitcode-format=pnacl,
     # so we need to set -bitcode-format=llvm to read LLVM files.
     self.checkCompileTranslateFlags(
         pexe, self.platform, ['--pnacl-sb', '--allow-llvm-bitcode-input'],
         ['-bitcode-format=llvm'])
     # Check that we do not get streaming bitcode by default.
     self.checkCompileTranslateFlags(pexe,
                                     self.platform,
                                     ['--allow-llvm-bitcode-input'],
                                     ['-streaming-bitcode'],
                                     invert_match=True)
     # Test that we get streaming bitcode when we ask for it.
     self.checkCompileTranslateFlags(
         pexe, self.platform,
         ['--allow-llvm-bitcode-input', '-stream-bitcode'],
         ['-streaming-bitcode'])
     # ...even when using threading
     self.checkCompileTranslateFlags(pexe, self.platform, [
         '--allow-llvm-bitcode-input', '-stream-bitcode', '-split-module=4'
     ], ['-streaming-bitcode', '-split-module=4'])
Ejemplo n.º 3
0
    def test_TempFileNotTooLong(self):
        '''Test that temp files with too-long names are not generated'''
        if not driver_test_utils.CanRunHost() or driver_tools.IsWindowsPython(
        ):
            return

        # This name is chosen such that the .c file has the maximum length. pnacl-ld
        # should not generate any temp names longer than that.
        shortname = os.path.join(self.LongTempDir, 'a' * 12)

        self.WriteCFile(shortname + '.c')
        driver_tools.RunDriver(
            'pnacl-clang', [shortname + '.c', '-c', '-o', shortname + '.o'])

        driver_tools.RunDriver('pnacl-ld', [shortname + '.o', '-o', shortname])

        # If it's impossible to generate a temp file short enough using our scheme
        # (i.e. the directory name is so long that 8 chars will be over the limit),
        # make sure we still fail the right way.
        longerdir = os.path.join(self.LongTempDir, 'a' * 8)
        os.mkdir(longerdir)
        longname = os.path.join(longerdir, 'a' * 3)
        os.rename(shortname + '.o', longname + '.o')

        output = self.AssertRaisesAndReturnOutput(
            driver_test_utils.DriverExitException, driver_tools.RunDriver,
            'pnacl-ld', [longname + '.o', '-o', longname])

        self.assertIn('.pexe is too long', output)
Ejemplo n.º 4
0
 def test_git_version(self):
     """Ensure the git hash is returned when invoking `--version`."""
     if not driver_test_utils.CanRunHost():
         return
     self.set_driver_rev_file('TEST_REV_GIT')
     self.check_flags(['--version'], pnacl_flag)
     self.assertEqual('ebba42f04c6a61f2a92e0a15ab835ef2371b6836',
                      pnacl_driver.ReadDriverRevision())
Ejemplo n.º 5
0
 def test_ll_bc_filetypes(self):
   if not driver_test_utils.CanRunHost():
     return
   ll, bc = self.getFakeLLAndBitcodeFile()
   self.assertTrue(filetype.FileType(ll.name) == 'll')
   self.assertTrue(filetype.FileType(bc.name) == 'po')
   self.assertFalse(filetype.IsLLVMBitcode(ll.name))
   self.assertTrue(filetype.IsLLVMBitcode(bc.name))
Ejemplo n.º 6
0
 def test_git_version_2(self):
     """Ensure the git hash is obtained when the URL doesn't end with `.git`."""
     if not driver_test_utils.CanRunHost():
         return
     self.set_driver_rev_file('TEST_REV_GIT2')
     self.check_flags(['--version'], pnacl_flag)
     self.assertEqual('587c9f0a79e679a27304980809e4f0bfd2a6c3c2',
                      pnacl_driver.ReadDriverRevision())
Ejemplo n.º 7
0
 def test_StripNativeArchive(self):
     if driver_test_utils.CanRunHost():
         src = self.getSource(0)
         obj = self.generateObjWithDebug(src, is_native=True)
         ar = self.generateArchive([obj])
         self.stripFileAndCheck(ar)
         src2 = self.getSource(1)
         obj2 = self.generateObjWithDebug(src2, is_native=True)
         ar2 = self.generateArchive([obj, obj2])
         self.stripFileAndCheck(ar2)
Ejemplo n.º 8
0
 def test_overrideTranslateFast(self):
     if driver_test_utils.CanRunHost():
         pexe = self.getFakePexe()
         # Test that you get O0 when you ask for -translate-fast.
         # In this case... you don't get no frame pointer elimination.
         self.checkLLCTranslateFlags(pexe, self.platform,
                                     ['-translate-fast'], ['-O0'])
         self.checkLLCTranslateFlags(
             pexe, self.platform, ['-translate-fast', '--pnacl-sb'],
             ['StreamInitWithOverrides.*-O0.*-mcpu=.*'])
Ejemplo n.º 9
0
 def test_overrideO0(self):
     if driver_test_utils.CanRunHost():
         pexe = self.getFakePexe()
         # Test that you get O0 when you ask for O0.
         # You also get no frame pointer elimination.
         self.checkLLCTranslateFlags(pexe, self.platform, ['-O0'],
                                     ['-O0', '-disable-fp-elim '])
         self.checkLLCTranslateFlags(
             pexe, self.platform, ['-O0', '--pnacl-sb'],
             ['StreamInitWithOverrides.*-O0.*-disable-fp-elim.*-mcpu=.*'])
Ejemplo n.º 10
0
 def test_finalize(self):
   """ Test that pnacl-ld will finalize the pexe when requested"""
   if not driver_test_utils.CanRunHost():
     return
   bitcode = self.getBitcode()
   with self.getTemp(suffix='.pexe') as temp_output:
     driver_tools.RunDriver(
       'pnacl-ld', ['--finalize', bitcode.name, '-o', temp_output.name])
     self.assertFalse(filetype.IsLLVMBitcode(temp_output.name))
     self.assertTrue(filetype.IsPNaClBitcode(temp_output.name))
Ejemplo n.º 11
0
    def test_PathWithSpaces(self):
        '''Test that the driver correctly handles paths containing spaces'''
        if not driver_test_utils.CanRunHost():
            return

        name = os.path.join(self.ShorterTempDir, 'a file')
        self.WriteCFile(name + '.c')
        driver_tools.RunDriver('pnacl-clang',
                               [name + '.c', '-c', '-o', name + '.o'])
        self.assertEqual('po', filetype.FileType(name + '.o'))
Ejemplo n.º 12
0
 def test_ClangHelpMessage(self):
     env.set('SCRIPT_NAME', 'pnacl-clang')
     help_str = pnacl_clang.get_help(self.default_argv)
     self.assertNotEqual(help_str, driver_tools.HelpNotAvailable())
     self.assertTrue(len(help_str) > 0)
     # Clang also has a '--help-full'.
     if driver_test_utils.CanRunHost():
         help_full_str = pnacl_clang.get_help(['driver', '--help-full'])
         self.assertNotEqual(help_full_str, driver_tools.HelpNotAvailable())
         self.assertTrue(len(help_full_str) > 0)
Ejemplo n.º 13
0
 def test_inplace_finalize(self):
   if not driver_test_utils.CanRunHost():
     return
   ll, bc = self.getFakeLLAndBitcodeFile()
   self.assertTrue(filetype.FileType(bc.name) == 'po')
   self.assertTrue(filetype.IsLLVMBitcode(bc.name))
   self.assertFalse(filetype.IsPNaClBitcode(bc.name))
   driver_tools.RunDriver('finalize', [bc.name])
   self.assertFalse(filetype.IsLLVMBitcode(bc.name))
   self.assertTrue(filetype.IsPNaClBitcode(bc.name))
   self.assertTrue(filetype.FileType(bc.name) == 'pexe')
Ejemplo n.º 14
0
 def test_overrideTLSUseCall(self):
     if driver_test_utils.CanRunHost():
         pexe = self.getFakePexe()
         # Test that you -mtls-use-call, etc. when you ask for it.
         self.checkCompileTranslateFlags(
             pexe, self.platform,
             ['-mtls-use-call', '-fdata-sections', '-ffunction-sections'],
             ['-mtls-use-call', '-data-sections', '-function-sections'])
         self.checkCompileTranslateFlags(pexe, self.platform, [
             '-mtls-use-call', '-fdata-sections', '-ffunction-sections',
             '--pnacl-sb'
         ], ['-mtls-use-call.*-data-sections.*-function-sections'])
Ejemplo n.º 15
0
 def checkXFlagOutput(self, flags, expected):
   ''' Given |flags| for pnacl-clang, check that clang outputs the |expected|.
   '''
   if not driver_test_utils.CanRunHost():
     return
   temp_out = pathtools.normalize(tempfile.NamedTemporaryFile().name)
   driver_temps.TempFiles.add(temp_out)
   driver_tools.RunDriver('pnacl-clang', flags + ['-o', temp_out])
   output = open(temp_out, 'r').read()
   for e in expected:
     self.assertTrue(re.search(e, output),
                     msg='Searching for regex %s in %s' % (e, output))
Ejemplo n.º 16
0
 def test_OverrideStreaming(self):
     if not driver_test_utils.CanRunHost():
         return
     pexe = self.getFakePexe()
     # Test that we get streaming bitcode when we ask for it.
     self.checkCompileTranslateFlags(pexe, self.platform,
                                     ['-stream-bitcode'],
                                     ['-streaming-bitcode'])
     # ...even when using threading.
     self.checkCompileTranslateFlags(
         pexe, self.platform, ['-stream-bitcode', '-split-module=4'],
         ['-streaming-bitcode', '-split-module=4'])
Ejemplo n.º 17
0
 def test_LLVMFile(self):
     if not driver_test_utils.CanRunHost():
         return
     pexe = self.getFakePexe(finalized=False)
     # For non-sandboxed pnacl-llc, the default -bitcode-format=llvm,
     # so there is nothing to really check.
     self.checkLLCTranslateFlags(pexe, self.platform,
                                 ['--allow-llvm-bitcode-input'], [])
     # For sandboxed pnacl-llc, the default -bitcode-format=pnacl,
     # so we need to set -bitcode-format=llvm to read LLVM files.
     self.checkLLCTranslateFlags(
         pexe, self.platform, ['--pnacl-sb', '--allow-llvm-bitcode-input'],
         ['StreamInitWithSplit i.*C\\(.*-bitcode-format=llvm.*\\)'])
Ejemplo n.º 18
0
 def test_no_overrides(self):
     if driver_test_utils.CanRunHost():
         pexe = self.getFakePexe()
         if self.platform == 'arm':
             expected_triple_cpu = ['-mtriple=arm.*', '-mcpu=cortex.*']
         elif self.platform == 'x86-32':
             expected_triple_cpu = ['-mtriple=i686.*', '-mcpu=pentium4m.*']
         elif self.platform == 'x86-64':
             expected_triple_cpu = ['-mtriple=x86_64.*', '-mcpu=x86-64.*']
         elif self.platform == 'mips':
             expected_triple_cpu = ['-mtriple=mips.*', '-mcpu=mips32.*']
         else:
             raise Exception('Unknown platform: "%s"' % self.platform)
         # Test that certain defaults are set, when no flags are given.
         self.checkCompileTranslateFlags(
             pexe, self.platform, [],
             expected_triple_cpu + ['-bitcode-format=pnacl'])
         # Check that the driver sets the number of threads and modules
         # correctly (1 vs 4).
         self.checkCompileTranslateFlags(
             pexe,
             self.platform, ['--pnacl-sb', '-split-module=1'],
             [' -E NACL_IRT_PNACL_TRANSLATOR_COMPILE_THREADS=1 '],
             expected_args=['-split-module=1'],
             expected_output_file_count=1)
         self.checkCompileTranslateFlags(
             pexe,
             self.platform, ['--pnacl-sb', '-split-module=4'],
             [' -E NACL_IRT_PNACL_TRANSLATOR_COMPILE_THREADS=4 '],
             expected_args=['-split-module=4'],
             expected_output_file_count=4)
         # Check that -split-module=auto does something sensible (1, 2, 3, or 4).
         self.checkCompileTranslateFlags(
             pexe, self.platform, ['--pnacl-sb', '-split-module=auto'],
             [' -E NACL_IRT_PNACL_TRANSLATOR_COMPILE_THREADS=[1234] '])
         # Check that omitting -split-module is the same as auto.
         self.checkCompileTranslateFlags(
             pexe, self.platform, ['--pnacl-sb'],
             [' -E NACL_IRT_PNACL_TRANSLATOR_COMPILE_THREADS=[1234] '])
         # Check that -split-module=seq is the same as -split-module=1.
         self.checkCompileTranslateFlags(
             pexe,
             self.platform, ['--pnacl-sb', '-split-module=seq'],
             [' -E NACL_IRT_PNACL_TRANSLATOR_COMPILE_THREADS=1 '],
             expected_args=['-split-module=1'],
             expected_output_file_count=1)
         # Check that we do not get streaming bitcode by default.
         self.checkCompileTranslateFlags(pexe,
                                         self.platform, [],
                                         ['-streaming-bitcode'],
                                         invert_match=True)
Ejemplo n.º 19
0
 def test_overrideMAttr(self):
     if driver_test_utils.CanRunHost():
         pexe = self.getFakePexe()
         if self.platform == 'arm':
             mattr_flags, mattr_pat = '-mattr=+hwdiv', r'-mattr=\+hwdiv'
         elif self.platform == 'x86-32' or self.platform == 'x86-64':
             mattr_flags, mattr_pat = '-mattr=+avx2,+sse41', r'-mattr=\+avx2,\+sse41'
         else:
             raise Exception('Unknown platform')
         # Test that you get the -mattr=.* that you ask for.
         self.checkLLCTranslateFlags(pexe, self.platform, [mattr_flags],
                                     [mattr_pat])
         self.checkLLCTranslateFlags(
             pexe, self.platform, [mattr_flags, '--pnacl-sb'],
             ['StreamInitWithOverrides.*' + mattr_pat + '.*-mcpu=.*'])
Ejemplo n.º 20
0
 def test_no_overrides(self):
     if driver_test_utils.CanRunHost():
         pexe = self.getFakePexe()
         if self.platform == 'arm':
             expected_triple_cpu = ['-mtriple=arm.*', '-mcpu=cortex.*']
         elif self.platform == 'x86-32':
             expected_triple_cpu = ['-mtriple=i686.*', '-mcpu=pentium.*']
         elif self.platform == 'x86-64':
             expected_triple_cpu = ['-mtriple=x86_64.*', '-mcpu=core.*']
         else:
             raise Exception('Unknown platform')
         # Test that certain defaults are set, when no flags are given.
         self.checkLLCTranslateFlags(pexe, self.platform, [],
                                     expected_triple_cpu)
         self.checkLLCTranslateFlags(pexe, self.platform, ['--pnacl-sb'],
                                     ['StreamInit h'])
Ejemplo n.º 21
0
    def test_with_pnacl_flag(self):
        """ Test that we do not pass the made-up --pnacl-* flags along to clang.

    Previously, when we ran --version and other "diagnostic" flags, there
    was a special invocation of clang, where we did not filter out the
    --pnacl-* driver-only flags.
    """
        if not driver_test_utils.CanRunHost():
            return
        self.check_flags(['-v'], pnacl_flag)
        self.check_flags(['-v', '-E', '-xc', os.devnull], pnacl_flag)
        self.check_flags(['-print-file-name=libc'], pnacl_flag)
        self.check_flags(['-print-libgcc-file-name'], pnacl_flag)
        self.check_flags(['-print-multi-directory'], pnacl_flag)
        self.check_flags(['-print-multi-lib'], pnacl_flag)
        self.check_flags(['-print-multi-os-directory'], pnacl_flag)
Ejemplo n.º 22
0
 def test_overrideMCPU(self):
     if driver_test_utils.CanRunHost():
         pexe = self.getFakePexe()
         if self.platform == 'arm':
             mcpu_pattern = '-mcpu=cortex-a15'
         elif self.platform == 'x86-32':
             mcpu_pattern = '-mcpu=atom'
         elif self.platform == 'x86-64':
             mcpu_pattern = '-mcpu=corei7'
         else:
             raise Exception('Unknown platform')
         # Test that you get the -mcpu that you ask for.
         self.checkLLCTranslateFlags(pexe, self.platform, [mcpu_pattern],
                                     [mcpu_pattern])
         self.checkLLCTranslateFlags(
             pexe, self.platform, [mcpu_pattern, '--pnacl-sb'],
             ['StreamInitWithOverrides.*' + mcpu_pattern])
Ejemplo n.º 23
0
    def test_DriverXNONE(self):
        """Test that "-x none" clears the file type."""
        if not driver_test_utils.CanRunHost():
            return
        # Add a string stream to capture output.
        capture_out = cStringIO.StringIO()
        driver_log.Log.CaptureToStream(capture_out)

        # Major hack to capture the exit (prevent Log.Fatal from blowin up).
        backup_exit = sys.exit
        sys.exit = driver_test_utils.FakeExit
        self.assertRaises(driver_test_utils.DriverExitException,
                          driver_tools.RunDriver, 'clang',
                          ['-E', '-x', 'c', '-x', 'none', os.devnull, '-dM'])
        driver_log.Log.ResetStreams()
        out = capture_out.getvalue()
        sys.exit = backup_exit
        self.assertTrue('Unrecognized file type' in out)
Ejemplo n.º 24
0
    def test_ExpandedPathTooLong(self):
        '''Test that the expanded path is checked with a short relative path'''
        if not driver_test_utils.CanRunHost() or driver_tools.IsWindowsPython(
        ):
            return

        os.chdir(self.LongTempDir)

        shortname = 'a' * 10
        longname = 'a' * 32

        # Now we are in a state where the file can be referred to by a relative
        # path or a normalized absolute path. For 'shortname', both are short
        # enough
        assert len(os.path.join(self.LongTempDir, shortname)) + 2 < 255
        assert len(os.path.join(self.LongTempDir, longname)) + 2 > 255
        self.WriteCFile(shortname + '.c')

        # Test that using a relative almost-too-long path works
        driver_tools.RunDriver(
            'pnacl-clang', [shortname + '.c', '-c', '-o', shortname + '.o'])

        driver_tools.RunDriver('pnacl-ld', [shortname + '.o'])

        # This name has a short-enough relative path and a short-enough normalized
        # final path, but the intermediate concatenation of pwd + rel path is too
        # long
        name_with_traversals = os.path.join('..',
                                            os.path.basename(self.LongTempDir),
                                            shortname)

        output = self.AssertRaisesAndReturnOutput(
            driver_test_utils.DriverExitException, driver_tools.RunDriver,
            'pnacl-clang',
            [name_with_traversals + '.c', '-c', '-o', shortname + '.o'])
        self.assertIn('expanded', output)

        # The previous test only gives a long input name. Also test that the output
        # name is checked.
        output = self.AssertRaisesAndReturnOutput(
            driver_test_utils.DriverExitException, driver_tools.RunDriver,
            'pnacl-clang',
            [shortname + '.c', '-c', '-o', name_with_traversals + '.o'])
        self.assertIn('expanded', output)
Ejemplo n.º 25
0
 def test_overrideMCPU(self):
     if driver_test_utils.CanRunHost():
         pexe = self.getFakePexe()
         if self.platform == 'arm':
             mcpu_pattern = '-mcpu=cortex-a15'
         elif self.platform == 'x86-32':
             mcpu_pattern = '-mcpu=atom'
         elif self.platform == 'x86-64':
             mcpu_pattern = '-mcpu=corei7'
         elif self.platform == 'mips':
             mcpu_pattern = '-mcpu=mips32'
         else:
             raise Exception('Unknown platform: "%s"' % self.platform)
         # Test that you get the -mcpu that you ask for.
         self.checkCompileTranslateFlags(pexe, self.platform,
                                         [mcpu_pattern], [mcpu_pattern])
         self.checkCompileTranslateFlags(pexe, self.platform,
                                         [mcpu_pattern, '--pnacl-sb'],
                                         [mcpu_pattern])
Ejemplo n.º 26
0
 def test_subzero_flags(self):
     # Subzero only supports x86-32 for now.
     if self.platform != 'x86-32':
         return
     if driver_test_utils.CanRunHost():
         pexe = self.getFakePexe()
         # Test Subzero's default args. Assume default is -split-module=auto.
         # In that case # of modules is 1..4, and the only special param
         # is the optimization level.
         self.checkCompileTranslateFlags(
             pexe,
             self.platform, ['--pnacl-sb', '--use-sz'],
             [' -E NACL_IRT_PNACL_TRANSLATOR_COMPILE_THREADS=[1234] '],
             expected_args=['-O2'],
             expected_output_file_count=1)
         # Similar, but with explicitly set -split-module=auto.
         self.checkCompileTranslateFlags(
             pexe,
             self.platform,
             ['--pnacl-sb', '--use-sz', '-split-module=auto'],
             [' -E NACL_IRT_PNACL_TRANSLATOR_COMPILE_THREADS=[1234] '],
             expected_args=['-O2'],
             expected_output_file_count=1)
         # Similar, but with explicitly set split-module=seq.
         self.checkCompileTranslateFlags(
             pexe,
             self.platform, ['--pnacl-sb', '--use-sz', '-split-module=seq'],
             [' -E NACL_IRT_PNACL_TRANSLATOR_COMPILE_THREADS=[1234] '],
             expected_args=['-O2'],
             expected_output_file_count=1)
         # Test that we can bump the thread count up (e.g., up to 4).
         self.checkCompileTranslateFlags(
             pexe,
             self.platform, ['--pnacl-sb', '--use-sz', '-split-module=4'],
             [' -E NACL_IRT_PNACL_TRANSLATOR_COMPILE_THREADS=4 '],
             expected_args=['-O2'],
             expected_output_file_count=1)
         # Test that you get Om1 when you ask for O0.
         self.checkCompileTranslateFlags(pexe,
                                         self.platform,
                                         ['-O0', '--pnacl-sb', '--use-sz'],
                                         [],
                                         expected_args=['-Om1'])
Ejemplo n.º 27
0
    def test_with_pnacl_flag(self):
        """ Test that we do not pass the made-up --pnacl-* flags along to clang.

    Previously, when we ran --version and other "diagnostic" flags, there
    was a special invocation of clang, where we did not filter out the
    --pnacl-* driver-only flags.
    """
        if not driver_test_utils.CanRunHost():
            return
        # Pick a particular --pnacl-* flag to test. Don't use
        # --pnacl-driver-verbose to test this, because --pnacl-driver-verbose
        # has a side-effect that isn't cleared by the env.pop() of RunDriver().
        pnacl_flag = '--pnacl-disable-abi-check'
        self.check_flags(['--version'], pnacl_flag)
        self.check_flags(['-v'], pnacl_flag)
        self.check_flags(['-v', '-E', '-xc', os.devnull], pnacl_flag)
        self.check_flags(['-print-file-name=libc'], pnacl_flag)
        self.check_flags(['-print-libgcc-file-name'], pnacl_flag)
        self.check_flags(['-print-multi-directory'], pnacl_flag)
        self.check_flags(['-print-multi-lib'], pnacl_flag)
        self.check_flags(['-print-multi-os-directory'], pnacl_flag)
Ejemplo n.º 28
0
 def test_finalize_keep_syms(self):
     """Test that finalize is still able to create a pexe w/ -no-strip-syms."""
     if not driver_test_utils.CanRunHost():
         return
     bc = self.getBCWithDebug()
     self.assertTrue(filetype.FileType(bc.name) == 'po')
     self.assertTrue(filetype.IsLLVMBitcode(bc.name))
     self.assertFalse(filetype.IsPNaClBitcode(bc.name))
     driver_tools.RunDriver('pnacl-finalize', [bc.name, '--no-strip-syms'])
     self.assertFalse(filetype.IsLLVMBitcode(bc.name))
     self.assertTrue(filetype.IsPNaClBitcode(bc.name))
     self.assertTrue(filetype.FileType(bc.name) == 'pexe')
     # Use pnacl-dis instead of llvm-nm, since llvm-nm won't know how to
     # handle finalized bitcode for now:
     # https://code.google.com/p/nativeclient/issues/detail?id=3993
     with self.getTemp(suffix='.ll') as temp_ll:
         driver_tools.RunDriver('pnacl-dis', [bc.name, '-o', temp_ll.name])
         with open(temp_ll.name, 'r') as dis_file:
             file_contents = dis_file.read()
             self.assertTrue(re.search(r'define .*@baz', file_contents))
             self.assertTrue(re.search(r'define .*@foo', file_contents))
Ejemplo n.º 29
0
    def test_InputPathTooLong(self):
        '''Test that clang and ld reject input paths that are too long

     Test that compiling and linking paths shorter than 255 succeeds and paths
     longer than 255 fails.
     Operations in python (e.g. rename) on long paths don't work on Windows,
     so just run the tests on Linux/Mac (the checks are enabled in unittest
     mode)
     '''
        if not driver_test_utils.CanRunHost() or driver_tools.IsWindowsPython(
        ):
            return

        shortname = os.path.join(self.LongTempDir, 'a' * 10)
        longname = os.path.join(self.LongTempDir, 'a' * 32)

        assert len(shortname) + 2 < 255
        assert len(longname) + 2 > 255
        self.WriteCFile(shortname + '.c')

        driver_tools.RunDriver(
            'pnacl-clang', [shortname + '.c', '-c', '-o', shortname + '.o'])

        driver_tools.RunDriver('pnacl-ld', [shortname + '.o'])

        os.rename(shortname + '.c', longname + '.c')
        os.rename(shortname + '.o', longname + '.o')

        output = self.AssertRaisesAndReturnOutput(
            driver_test_utils.DriverExitException, driver_tools.RunDriver,
            'pnacl-clang', [longname + '.c', '-c', '-o', longname + '.o'])

        self.assertIn('too long', output)

        output = self.AssertRaisesAndReturnOutput(
            driver_test_utils.DriverExitException, driver_tools.RunDriver,
            'pnacl-ld', [longname + '.o'])

        self.assertIn('too long', output)
Ejemplo n.º 30
0
 def test_overrideMAttr(self):
     if driver_test_utils.CanRunHost():
         pexe = self.getFakePexe()
         if self.platform == 'arm':
             mattr_flags, mattr_pat = '-mattr=+hwdiv', r'-mattr=\+hwdiv'
         elif self.platform == 'x86-32' or self.platform == 'x86-64':
             mattr_flags, mattr_pat = '-mattr=+avx2,+sse41', r'-mattr=\+avx2,\+sse41'
         elif self.platform == 'mips':
             mattr_flags, mattr_pat = '-mattr=+fp64', r'-mattr=\+fp64'
         else:
             raise Exception('Unknown platform: "%s"' % self.platform)
         # Test that you get the -mattr=.* that you ask for.
         self.checkCompileTranslateFlags(pexe, self.platform, [mattr_flags],
                                         [mattr_pat])
         self.checkCompileTranslateFlags(pexe, self.platform,
                                         [mattr_flags, '--pnacl-sb'],
                                         [mattr_pat + '.*-mcpu=.*'])
         # Same for subzero (only test supported architectures).
         if self.platform == 'x86-32':
             self.checkCompileTranslateFlags(
                 pexe, self.platform,
                 [mattr_flags, '--pnacl-sb', '--use-sz'], [mattr_pat])