Пример #1
0
    def __init__(self,
                 files,
                 exported_symbols_file,
                 gccxml_config=None,
                 optimize_queries=True,
                 encoding='ascii'):
        """
        :param files: list of files, declarations from them you want to export
        :type files: list of strings or :class:`parser.file_configuration_t` instances
        """
        module_builder.module_builder_t.__init__(self,
                                                 global_ns=None,
                                                 encoding=encoding)

        self.global_ns = self.__parse_declarations(files, gccxml_config)
        self.global_ns.decls(
            recursive=True, allow_empty=True
        )._code_generator = decl_wrappers.CODE_GENERATOR_TYPES.CTYPES
        self.__blob2decl = binary_parsers.merge_information(
            self.global_ns, exported_symbols_file)

        self.__apply_defaults()

        self.__code_creator = None
        if optimize_queries:
            self.run_query_optimizer()

        self.__treat_char_ptr_as_binary_data = None

        self.__module_code_head = []
        self.__module_code_tail = []
Пример #2
0
    def __init__( self
                  , files
                  , exported_symbols_file
                  , gccxml_config=None
                  , optimize_queries=True
                  , encoding='ascii' ):
        """
        :param files: list of files, declarations from them you want to export
        :type files: list of strings or :class:`parser.file_configuration_t` instances
        """
        module_builder.module_builder_t.__init__( self, global_ns=None, encoding=encoding )

        self.global_ns = self.__parse_declarations( files, gccxml_config )
        self.global_ns.decls(recursive=True, allow_empty=True)._code_generator = decl_wrappers.CODE_GENERATOR_TYPES.CTYPES
        self.__blob2decl = binary_parsers.merge_information( self.global_ns, exported_symbols_file )

        self.__apply_defaults()

        self.__code_creator = None
        if optimize_queries:
            self.run_query_optimizer()

        self.__treat_char_ptr_as_binary_data = None

        self.__module_code_head = []
        self.__module_code_tail = []
Пример #3
0
    def dont_test_print( self ):
        """primary used for debugging"""
        symbols, parser = binary_parsers.merge_information( self.global_ns, self.so_file, runs_under_unittest=True )
        for f in self.global_ns.calldefs( allow_empty=True, recursive=True ):
            print binary_parsers.format_decl( f, 'nm' )

        for v in self.global_ns.variables( allow_empty=True, recursive=True ):
            print binary_parsers.format_decl( v, 'nm' )
Пример #4
0
    def test_z_compare_parsers( self ):
        if 'nt' != os.name:
            return
        dsymbols, dparser = binary_parsers.merge_information( self.global_ns, self.dll_file, runs_under_unittest=True )
        msymbols, mparser = binary_parsers.merge_information( self.global_ns, self.map_file, runs_under_unittest=True )

        self.failUnless( len( dparser.loaded_symbols ) == len( mparser.loaded_symbols ) )

        was_error = False
        for blob, decl in dsymbols.iteritems():
            if blob not in msymbols:
                was_error = True
                print '\n%s could not be found in .map file' % binary_parsers.undecorate_blob( blob )
                #~ self.failUnless( blob in msymbols, binary_parsers.undecorate_blob( blob ) )
            else:
                mdecl = msymbols[ blob ]
                self.failUnless( mdecl is decl )
        self.failUnless( was_error == False )
Пример #5
0
    def dont_test_print(self):
        """primary used for debugging"""
        symbols, parser = binary_parsers.merge_information(
            self.global_ns, self.so_file, runs_under_unittest=True)
        for f in self.global_ns.calldefs(allow_empty=True, recursive=True):
            print(binary_parsers.format_decl(f, 'nm'))

        for v in self.global_ns.variables(allow_empty=True, recursive=True):
            print(binary_parsers.format_decl(v, 'nm'))
Пример #6
0
    def test_z_compare_parsers(self):
        if 'nt' != os.name:
            return
        dsymbols, dparser = binary_parsers.merge_information(
            self.global_ns, self.dll_file, runs_under_unittest=True)
        msymbols, mparser = binary_parsers.merge_information(
            self.global_ns, self.map_file, runs_under_unittest=True)

        self.assertTrue(
            len(dparser.loaded_symbols) == len(mparser.loaded_symbols))

        was_error = False
        for blob, decl in dsymbols.items():
            if blob not in msymbols:
                was_error = True
                print('\n%s could not be found in .map file' %
                      binary_parsers.undecorate_blob(blob))
                # self.assertTrue( blob in msymbols,
                # binary_parsers.undecorate_blob( blob ) )
            else:
                mdecl = msymbols[blob]
                self.assertTrue(mdecl is decl)
        self.assertTrue(was_error is False)
Пример #7
0
    def __tester_impl(self, fname, expected_symbols):
        symbols, parser = binary_parsers.merge_information(
            self.global_ns, fname, runs_under_unittest=True)
        # this doesn't work reliably
        # self.assertTrue(
        #    len(symbols) == expected_symbols,
        # "The expected symbols number(%d),
        # is different from the actual one(%d)"
        # % ( expected_symbols, len(symbols) ) )
        self.assertTrue('identity' in symbols)

        msg = []
        blob_names = set()
        for blob in parser.loaded_symbols:
            if isinstance(blob, tuple):
                blob = blob[0]
            if 'nt' == os.name:
                # TODO: find out where undecorate function is exposed on linux
                undname = binary_parsers.undecorate_blob(blob)
                if "`" in undname:
                    continue
            blob_names.add(blob)

        decl_blob_names = set(symbols.keys())

        issuperset = decl_blob_names.issuperset(blob_names)
        if not issuperset:
            common = decl_blob_names.intersection(blob_names)

            decl_blob_names.difference_update(common)
            blob_names.difference_update(common)
            if not self.known_issues.issubset(blob_names):
                blob_names.difference_update(self.known_issues)
                if sys.version_info[0] == 2 and sys.version_info[1] == 5:
                    if 0 == len(decl_blob_names) and 0 == len(blob_names):
                        return
                msg.append("decl_blob_names :")
                for i in decl_blob_names:
                    msg.append('\t==>%s<==' % i)
                msg.append("blob_names :")
                for i in blob_names:
                    msg.append('\t==>%s<==' % i)

                self.fail(os.linesep.join(msg))
Пример #8
0
    def __tester_impl(self, fname, expected_symbols):
        symbols, parser = binary_parsers.merge_information(
            self.global_ns, fname, runs_under_unittest=True)
        # this doesn't work reliably
        # self.assertTrue(
        #    len(symbols) == expected_symbols,
        # "The expected symbols number(%d),
        # is different from the actual one(%d)"
        # % ( expected_symbols, len(symbols) ) )
        self.assertTrue('identity' in symbols)

        msg = []
        blob_names = set()
        for blob in parser.loaded_symbols:
            if isinstance(blob, tuple):
                blob = blob[0]
            if 'nt' == os.name:
                # TODO: find out where undecorate function is exposed on linux
                undname = binary_parsers.undecorate_blob(blob)
                if "`" in undname:
                    continue
            blob_names.add(blob)

        decl_blob_names = set(symbols.keys())

        issuperset = decl_blob_names.issuperset(blob_names)
        if not issuperset:
            common = decl_blob_names.intersection(blob_names)

            decl_blob_names.difference_update(common)
            blob_names.difference_update(common)
            if not self.known_issues.issubset(blob_names):
                blob_names.difference_update(self.known_issues)
                if sys.version_info[0] == 2 and sys.version_info[1] == 5:
                    if 0 == len(decl_blob_names) and 0 == len(blob_names):
                        return
                msg.append("decl_blob_names :")
                for i in decl_blob_names:
                    msg.append('\t==>%s<==' % i)
                msg.append("blob_names :")
                for i in blob_names:
                    msg.append('\t==>%s<==' % i)

                self.fail(os.linesep.join(msg))