Esempio n. 1
0
 def test_getFoldedSections(self):
     """Test ExpandMoreArgs' _getFoldedSections"""
     # Divert subprocess.Popen
     subprocess_popen = subprocess.Popen
     subprocess.Popen = SubprocessPopen(self)
     config.LD_PRINT_ICF_SECTIONS = "-Wl,--print-icf-sections"
     args = ExpandArgsMore(["foo", "-bar", "bar.o", "foo.o"])
     self.assertEqual(args._getFoldedSections(), {".text.hello": [".text.hi"], ".text.hi": [".text.hello"]})
     subprocess.Popen = subprocess_popen
 def test_getFoldedSections(self):
     '''Test ExpandMoreArgs' _getFoldedSections'''
     # Divert subprocess.Popen
     subprocess_popen = subprocess.Popen
     subprocess.Popen = SubprocessPopen(self)
     config.LD_PRINT_ICF_SECTIONS = '-Wl,--print-icf-sections'
     args = ExpandArgsMore(['foo', '-bar', 'bar.o', 'foo.o'])
     self.assertEqual(args._getFoldedSections(), {'.text.hello': '.text.hi', '.text.hi': ['.text.hello']})
     subprocess.Popen = subprocess_popen
Esempio n. 3
0
 def test_getFoldedSections(self):
     '''Test ExpandMoreArgs' _getFoldedSections'''
     # Divert subprocess.Popen
     subprocess_popen = subprocess.Popen
     subprocess.Popen = SubprocessPopen(self)
     config.LD_PRINT_ICF_SECTIONS = '-Wl,--print-icf-sections'
     args = ExpandArgsMore(['foo', '-bar', 'bar.o', 'foo.o'])
     self.assertEqual(args._getFoldedSections(), {'.text.hello': ['.text.hi'], '.text.hi': ['.text.hello']})
     subprocess.Popen = subprocess_popen
 def test_getOrderedSectionsWithICF(self):
     '''Test ExpandMoreArgs' _getOrderedSections, with ICF'''
     # Divert subprocess.Popen
     subprocess_popen = subprocess.Popen
     subprocess.Popen = SubprocessPopen(self)
     config.EXPAND_LIBS_ORDER_STYLE = 'linkerscript'
     config.OBJ_SUFFIX = '.o'
     config.LIB_SUFFIX = '.a'
     config.LD_PRINT_ICF_SECTIONS = '-Wl,--print-icf-sections'
     args = ExpandArgsMore(['foo', '-bar', 'bar.o', 'foo.o'])
     self.assertEqual(args._getOrderedSections(['hello', '_Z6barbazv']), ['.text.hi', '.text.hello', '.text.hot._Z6barbazv'])
     self.assertEqual(args._getOrderedSections(['_ZThn4_6foobarv', 'hi', '_Z6barbazv']), ['.text._Z6foobarv', '.text._ZThn4_6foobarv', '.text.hi', '.text.hello', '.text.hot._Z6barbazv'])
     subprocess.Popen = subprocess_popen
Esempio n. 5
0
 def test_getOrderedSectionsWithICF(self):
     '''Test ExpandMoreArgs' _getOrderedSections, with ICF'''
     # Divert subprocess.Popen
     subprocess_popen = subprocess.Popen
     subprocess.Popen = SubprocessPopen(self)
     config.EXPAND_LIBS_ORDER_STYLE = 'linkerscript'
     config.OBJ_SUFFIX = '.o'
     config.LIB_SUFFIX = '.a'
     config.LD_PRINT_ICF_SECTIONS = '-Wl,--print-icf-sections'
     args = ExpandArgsMore(['foo', '-bar', 'bar.o', 'foo.o'])
     self.assertEqual(args._getOrderedSections(['hello', '_Z6barbazv']), ['.text.hello', '.text.hi', '.text.hot._Z6barbazv'])
     self.assertEqual(args._getOrderedSections(['_ZThn4_6foobarv', 'hi', '_Z6barbazv']), ['.text._Z6foobarv', '.text._ZThn4_6foobarv', '.text.hi', '.text.hello', '.text.hot._Z6barbazv'])
     subprocess.Popen = subprocess_popen
Esempio n. 6
0
    def test_makelist(self):
        '''Test grouping object files in lists'''
        # ExpandArgsMore does the same as ExpandArgs
        with ExpandArgsMore(['foo', '-bar'] + self.arg_files + [self.tmpfile('liby', Lib('y'))]) as args:
            self.assertRelEqual(args, ['foo', '-bar'] + self.files + self.liby_files + self.libx_files) 

            # But also has an extra method replacing object files with a list
            args.makelist()
            # self.files has objects at #1, #2, #4
            self.assertRelEqual(args[:3], ['foo', '-bar'] + self.files[:1])
            self.assertRelEqual(args[4:], [self.files[3]] + self.files[5:] + [self.tmpfile('liby', Lib('z'))])

            # Check the list file content
            objs = [f for f in self.files + self.liby_files + self.libx_files if f.endswith(config.OBJ_SUFFIX)]
            if config.EXPAND_LIBS_LIST_STYLE == "linkerscript":
                self.assertNotEqual(args[3][0], '@')
                filename = args[3]
                content = ['INPUT("{0}")'.format(relativize(f)) for f in objs]
                with open(filename, 'r') as f:
                    self.assertEqual([l.strip() for l in f.readlines() if len(l.strip())], content)
            elif config.EXPAND_LIBS_LIST_STYLE == "list":
                self.assertEqual(args[3][0], '@')
                filename = args[3][1:]
                content = objs
                with open(filename, 'r') as f:
                    self.assertRelEqual([l.strip() for l in f.readlines() if len(l.strip())], content)

            tmp = args.tmp
        # Check that all temporary files are properly removed
        self.assertEqual(True, all([not os.path.exists(f) for f in tmp]))
Esempio n. 7
0
 def test_getOrderedSectionsWithICF(self):
     """Test ExpandMoreArgs' _getOrderedSections, with ICF"""
     # Divert subprocess.Popen
     subprocess_popen = subprocess.Popen
     subprocess.Popen = SubprocessPopen(self)
     config.EXPAND_LIBS_ORDER_STYLE = "linkerscript"
     config.OBJ_SUFFIX = ".o"
     config.LIB_SUFFIX = ".a"
     config.LD_PRINT_ICF_SECTIONS = "-Wl,--print-icf-sections"
     args = ExpandArgsMore(["foo", "-bar", "bar.o", "foo.o"])
     self.assertEqual(
         args._getOrderedSections(["hello", "_Z6barbazv"]), [".text.hello", ".text.hi", ".text.hot._Z6barbazv"]
     )
     self.assertEqual(
         args._getOrderedSections(["_ZThn4_6foobarv", "hi", "_Z6barbazv"]),
         [".text._Z6foobarv", ".text._ZThn4_6foobarv", ".text.hi", ".text.hello", ".text.hot._Z6barbazv"],
     )
     subprocess.Popen = subprocess_popen
    def test_extract(self):
        '''Test library extraction'''
        # Divert subprocess.call
        subprocess_call = subprocess.call
        extracted = {}

        def call(args, **kargs):
            # The command called is always AR_EXTRACT
            ar_extract = config.AR_EXTRACT.split()
            self.assertRelEqual(args[:len(ar_extract)], ar_extract)
            # Remaining argument is always one library
            self.assertRelEqual(
                [os.path.splitext(arg)[1] for arg in args[len(ar_extract):]],
                [config.LIB_SUFFIX])
            # Simulate AR_EXTRACT extracting one object file for the library
            lib = os.path.splitext(os.path.basename(args[len(ar_extract)]))[0]
            extracted[lib] = os.path.join(kargs['cwd'], "%s" % Obj(lib))
            self.touch([extracted[lib]])

        subprocess.call = call

        # ExpandArgsMore does the same as ExpandArgs
        self.touch([self.tmpfile('liby', Lib('y'))])
        with ExpandArgsMore(['foo', '-bar'] + self.arg_files +
                            [self.tmpfile('liby', Lib('y'))]) as args:
            self.assertRelEqual(args, ['foo', '-bar'] + self.files +
                                [self.tmpfile('liby', Lib('y'))])

            # ExpandArgsMore also has an extra method extracting static libraries
            # when possible
            args.extract()

            files = self.files + self.liby_files + self.libx_files
            if not len(config.AR_EXTRACT):
                # If we don't have an AR_EXTRACT, extract() expands libraries with a
                # descriptor when the corresponding library exists (which ExpandArgs
                # alone doesn't)
                self.assertRelEqual(args, ['foo', '-bar'] + files)
            else:
                # With AR_EXTRACT, it uses the descriptors when there are, and actually
                # extracts the remaining libraries
                self.assertRelEqual(args, ['foo', '-bar'] + [
                    extracted[os.path.splitext(os.path.basename(f))[0]]
                    if f.endswith(config.LIB_SUFFIX) else f for f in files
                ])

            tmp = args.tmp
        # Check that all temporary files are properly removed
        self.assertEqual(True, all([not os.path.exists(f) for f in tmp]))

        # Restore subprocess.call
        subprocess.call = subprocess_call
Esempio n. 9
0
    def test_reorder(self):
        '''Test object reordering'''
        # We don't care about AR_EXTRACT testing, which is done in test_extract
        config.AR_EXTRACT = ''

        # ExpandArgsMore does the same as ExpandArgs
        with ExpandArgsMore(['foo', '-bar'] + self.arg_files + [self.tmpfile('liby', Lib('y'))]) as args:
            self.assertRelEqual(args, ['foo', '-bar'] + self.files + self.liby_files + self.libx_files) 

            # Use an order containing object files from libraries
            order_files = [self.libx_files[1], self.libx_files[0], self.liby_files[2], self.files[1]]
            order = [os.path.splitext(os.path.basename(f))[0] for f in order_files]
            args.reorder(order[:2] + ['unknown'] + order[2:])

            # self.files has objects at #1, #2, #4
            self.assertRelEqual(args[:3], ['foo', '-bar'] + self.files[:1])
            self.assertRelEqual(args[3:7], order_files)
            self.assertRelEqual(args[7:9], [self.files[2], self.files[4]])
            self.assertRelEqual(args[9:11], self.liby_files[:2])
            self.assertRelEqual(args[11:12], [self.libx_files[2]])
            self.assertRelEqual(args[12:14], [self.files[3], self.files[5]])
            self.assertRelEqual(args[14:], [self.liby_files[3]])
Esempio n. 10
0
    def test_extract(self):
        '''Test library extraction'''
        # Divert subprocess.call
        subprocess_call = subprocess.call
        subprocess_check_output = subprocess.check_output
        def call(args, **kargs):
            if config.AR == 'lib':
                self.assertEqual(args[:2], [config.AR, '-NOLOGO'])
                self.assertTrue(args[2].startswith('-EXTRACT:'))
                extract = [args[2][len('-EXTRACT:'):]]
                self.assertTrue(extract)
                args = args[3:]
            else:
                # The command called is always AR_EXTRACT
                ar_extract = config.AR_EXTRACT.split()
                self.assertEqual(args[:len(ar_extract)], ar_extract)
                args = args[len(ar_extract):]
            # Remaining argument is always one library
            self.assertEqual(len(args), 1)
            arg = args[0]
            self.assertEqual(os.path.splitext(arg)[1], config.LIB_SUFFIX)
            # Simulate file extraction
            lib = os.path.splitext(os.path.basename(arg))[0]
            if config.AR != 'lib':
                extract = [lib, lib + '2']
            extract = [os.path.join(kargs['cwd'], f) for f in extract]
            if config.AR != 'lib':
                extract = [Obj(f) for f in extract]
            if not lib in extracted:
                extracted[lib] = []
            extracted[lib].extend(extract)
            self.touch(extract)
        subprocess.call = call

        def check_output(args, **kargs):
            # The command called is always AR
            ar = config.AR
            self.assertEqual(args[0:3], [ar, '-NOLOGO', '-LIST'])
            # Remaining argument is always one library
            self.assertRelEqual([os.path.splitext(arg)[1] for arg in args[3:]],
[config.LIB_SUFFIX])
            # Simulate LIB -NOLOGO -LIST
            lib = os.path.splitext(os.path.basename(args[3]))[0]
            return '%s\n%s\n' % (Obj(lib), Obj(lib + '2'))
        subprocess.check_output = check_output

        # ExpandArgsMore does the same as ExpandArgs
        self.touch([self.tmpfile('liby', Lib('y'))])
        for iteration in (1, 2):
            with ExpandArgsMore(['foo', '-bar'] + self.arg_files + [self.tmpfile('liby', Lib('y'))]) as args:
                self.assertRelEqual(args, ['foo', '-bar'] + self.files + [self.tmpfile('liby', Lib('y'))])

                extracted = {}
                # ExpandArgsMore also has an extra method extracting static libraries
                # when possible
                args.extract()

                files = self.files + self.liby_files + self.libx_files
                # With AR_EXTRACT, it uses the descriptors when there are, and
                # actually
                # extracts the remaining libraries
                extracted_args = []
                for f in files:
                    if f.endswith(config.LIB_SUFFIX):
                        base = os.path.splitext(os.path.basename(f))[0]
                        # On the first iteration, we test the behavior of
                        # extracting archives that don't have a copy of their
                        # contents next to them, which is to use the file
                        # extracted from the archive in a temporary directory.
                        # On the second iteration, we test extracting archives
                        # that do have a copy of their contents next to them,
                        # in which case those contents are used instead of the
                        # temporarily extracted files.
                        if iteration == 1:
                            extracted_args.extend(sorted(extracted[base]))
                        else:
                            dirname = os.path.dirname(f[len(self.tmpdir)+1:])
                            if base.endswith('f'):
                                dirname = os.path.join(dirname, 'foo', 'bar')
                            extracted_args.extend([self.tmpfile(dirname, Obj(base)), self.tmpfile(dirname, Obj(base + '2'))])
                    else:
                        extracted_args.append(f)
                self.assertRelEqual(args, ['foo', '-bar'] + extracted_args)

                tmp = args.tmp
            # Check that all temporary files are properly removed
            self.assertEqual(True, all([not os.path.exists(f) for f in tmp]))

            # Create archives contents next to them for the second iteration.
            base = os.path.splitext(Lib('_'))[0]
            self.touch(self.tmpfile(Obj(base.replace('_', suffix))) for suffix in ('a', 'a2', 'd', 'd2'))
            try:
                os.makedirs(self.tmpfile('foo', 'bar'))
            except:
                pass
            self.touch(self.tmpfile('foo', 'bar', Obj(base.replace('_', suffix))) for suffix in ('f', 'f2'))
            self.touch(self.tmpfile('liby', Obj(base.replace('_', suffix))) for suffix in ('z', 'z2'))

        # Restore subprocess.call and subprocess.check_output
        subprocess.call = subprocess_call
        subprocess.check_output = subprocess_check_output
Esempio n. 11
0
    def test_extract(self):
        '''Test library extraction'''
        # Divert subprocess.call
        subprocess_call = subprocess.call
        extracted = {}

        def call(args, **kargs):
            if config.AR == 'lib':
                self.assertEqual(args[:2], [config.AR, '-NOLOGO'])
                self.assertTrue(args[2].startswith('-EXTRACT:'))
                extract = [args[2][len('-EXTRACT:'):]]
                self.assertTrue(extract)
                args = args[3:]
            else:
                # The command called is always AR_EXTRACT
                ar_extract = config.AR_EXTRACT.split()
                self.assertEqual(args[:len(ar_extract)], ar_extract)
                args = args[len(ar_extract):]
            # Remaining argument is always one library
            self.assertEqual(len(args), 1)
            arg = args[0]
            self.assertEqual(os.path.splitext(arg)[1], config.LIB_SUFFIX)
            # Simulate file extraction
            lib = os.path.splitext(os.path.basename(arg))[0]
            if config.AR != 'lib':
                extract = [lib, lib + '2']
            extract = [os.path.join(kargs['cwd'], f) for f in extract]
            if config.AR != 'lib':
                extract = [Obj(f) for f in extract]
            if not lib in extracted:
                extracted[lib] = []
            extracted[lib].extend(extract)
            self.touch(extract)

        subprocess.call = call

        def check_output(args, **kargs):
            # The command called is always AR
            ar = config.AR
            self.assertEqual(args[0:3], [ar, '-NOLOGO', '-LIST'])
            # Remaining argument is always one library
            self.assertRelEqual([os.path.splitext(arg)[1] for arg in args[3:]],
                                [config.LIB_SUFFIX])
            # Simulate LIB -NOLOGO -LIST
            lib = os.path.splitext(os.path.basename(args[3]))[0]
            return '%s\n%s\n' % (Obj(lib), Obj(lib + '2'))

        subprocess.check_output = check_output

        # ExpandArgsMore does the same as ExpandArgs
        self.touch([self.tmpfile('liby', Lib('y'))])
        with ExpandArgsMore(['foo', '-bar'] + self.arg_files +
                            [self.tmpfile('liby', Lib('y'))]) as args:
            self.assertRelEqual(args, ['foo', '-bar'] + self.files +
                                [self.tmpfile('liby', Lib('y'))])

            # ExpandArgsMore also has an extra method extracting static libraries
            # when possible
            args.extract()

            files = self.files + self.liby_files + self.libx_files
            # With AR_EXTRACT, it uses the descriptors when there are, and
            # actually
            # extracts the remaining libraries
            extracted_args = []
            for f in files:
                if f.endswith(config.LIB_SUFFIX):
                    extracted_args.extend(
                        sorted(extracted[os.path.splitext(
                            os.path.basename(f))[0]]))
                else:
                    extracted_args.append(f)
            self.assertRelEqual(args, ['foo', '-bar'] + extracted_args)

            tmp = args.tmp
        # Check that all temporary files are properly removed
        self.assertEqual(True, all([not os.path.exists(f) for f in tmp]))

        # Restore subprocess.call
        subprocess.call = subprocess_call