コード例 #1
0
    def mem_stats(self, map):
        """! Creates parser object
        @param map Path to linker map file to parse and decode
        @return Memory summary structure with memory usage statistics
                None if map file can't be opened and processed
        """
        toolchain = self.__class__.__name__

        # Create memap object
        memap = MemapParser()

        # Parse and decode a map file
        if memap.parse(abspath(map), toolchain) is False:
            self.info("Unknown toolchain for memory statistics %s" % toolchain)
            return None

        # Write output to stdout in text (pretty table) format
        memap.generate_output('table')

        # Write output to file in JSON format
        map_out = splitext(map)[0] + "_map.json"
        memap.generate_output('json', map_out)

        # Write output to file in CSV format for the CI
        map_csv = splitext(map)[0] + "_map.csv"
        memap.generate_output('csv-ci', map_csv)

        # Here we return memory statistics structure (constructed after
        # call to generate_output) which contains raw data in bytes
        # about sections + summary
        return memap.mem_summary
コード例 #2
0
ファイル: __init__.py プロジェクト: dotnfc/mbed-os
    def mem_stats(self, map):
        """! Creates parser object
        @param map Path to linker map file to parse and decode
        @return Memory summary structure with memory usage statistics
                None if map file can't be opened and processed
        """
        toolchain = self.__class__.__name__

        # Create memap object
        memap = MemapParser()

        # Parse and decode a map file
        if memap.parse(abspath(map), toolchain) is False:
            self.info("Unknown toolchain for memory statistics %s" % toolchain)
            return None

        # Write output to stdout in text (pretty table) format
        memap.generate_output('table')

        # Write output to file in JSON format
        map_out = splitext(map)[0] + "_map.json"
        memap.generate_output('json', map_out)

        # Write output to file in CSV format for the CI
        map_csv = splitext(map)[0] + "_map.csv"
        memap.generate_output('csv-ci', map_csv)

        # Here we return memory statistics structure (constructed after
        # call to generate_output) which contains raw data in bytes
        # about sections + summary
        return memap.mem_summary
コード例 #3
0
ファイル: __init__.py プロジェクト: DanKupiniak/mbed
    def mem_stats(self, map):
        # Creates parser object
        toolchain = self.__class__.__name__

        # Create memap object
        memap = MemapParser()

        # Parse and decode a map file
        if memap.parse(abspath(map), toolchain) is False:
            self.info("Unknown toolchain for memory statistics %s" % toolchain)
            return

        # Write output to stdout in text (pretty table) format
        memap.generate_output("table")

        # Write output to file in JSON format
        map_out = splitext(map)[0] + "_map.json"
        memap.generate_output("json", map_out)

        # Write output to file in CSV format for the CI
        map_csv = splitext(map)[0] + "_map.csv"
        memap.generate_output("csv-ci", map_csv)
コード例 #4
0
ファイル: __init__.py プロジェクト: babyge/mbed-beetle
    def mem_stats(self, map):
        # Creates parser object
        toolchain = self.__class__.__name__

        # Create memap object
        memap = MemapParser()

        # Parse and decode a map file
        if memap.parse(abspath(map), toolchain) is False:
            self.info("Unknown toolchain for memory statistics %s" % toolchain)
            return

        # Write output to stdout in text (pretty table) format
        memap.generate_output('table')

        # Write output to file in JSON format
        map_out = splitext(map)[0] + "_map.json"
        memap.generate_output('json', map_out)

        # Write output to file in CSV format for the CI
        map_csv = splitext(map)[0] + "_map.csv"
        memap.generate_output('csv-ci', map_csv)
コード例 #5
0
ファイル: memap_test.py プロジェクト: MXCHIP/mbed-os-AZ3166
class MemapParserTests(unittest.TestCase):
    """
    Test cases for Test Api
    """
    def setUp(self):
        """
        Called before each test case

        :return:
        """
        self.memap_parser = MemapParser()

        self.memap_parser.modules = {
            "Misc": {
                "unknown": 0,
                ".ARM": 8,
                ".ARM.extab": 0,
                ".init": 12,
                "OUTPUT": 0,
                ".stack": 0,
                ".eh_frame": 0,
                ".fini_array": 4,
                ".heap": 0,
                ".stabstr": 0,
                ".interrupts_ram": 0,
                ".init_array": 0,
                ".stab": 0,
                ".ARM.attributes": 7347,
                ".bss": 8517,
                ".flash_config": 16,
                ".interrupts": 1024,
                ".data": 2325,
                ".ARM.exidx": 0,
                ".text": 59906,
                ".jcr": 0
            },
            "Fill": {
                "unknown": 12,
                ".ARM": 0,
                ".ARM.extab": 0,
                ".init": 0,
                "OUTPUT": 0,
                ".stack": 0,
                ".eh_frame": 0,
                ".fini_array": 0,
                ".heap": 65536,
                ".stabstr": 0,
                ".interrupts_ram": 1024,
                ".init_array": 0,
                ".stab": 0,
                ".ARM.attributes": 0,
                ".bss": 2235,
                ".flash_config": 0,
                ".interrupts": 0,
                ".data": 3,
                ".ARM.exidx": 0,
                ".text": 136,
                ".jcr": 0
            }
        }

        self.memap_parser.compute_report()

    def tearDown(self):
        """
        Called after each test case

        :return:
        """
        pass

    def generate_test_helper(self, output_type, file_output=None):
        """
        Helper that ensures that the member variables "modules", "mem_report",
        and "mem_summary" are unchanged after calling "generate_output"
        
        :param output_type: type string that is passed to "generate_output"
        :param file_output: path to output file that is passed to "generate_output"      
        :return:
        """

        old_modules = deepcopy(self.memap_parser.modules)
        old_report = deepcopy(self.memap_parser.mem_report)
        old_summary = deepcopy(self.memap_parser.mem_summary)
        self.memap_parser.generate_output(output_type, file_output)
        self.assertEqual(self.memap_parser.modules, old_modules,
                         "generate_output modified the 'modules' property")
        self.assertEqual(self.memap_parser.mem_report, old_report,
                         "generate_output modified the 'mem_report' property")
        self.assertEqual(
            self.memap_parser.mem_summary, old_summary,
            "generate_output modified the 'mem_summary' property")

    def test_report_computed(self):
        """
        Test ensures the report and summary are computed
        
        :return:
        """
        self.assertTrue(self.memap_parser.mem_report)
        self.assertTrue(self.memap_parser.mem_summary)
        self.assertEqual(
            self.memap_parser.mem_report[-1]['summary'],
            self.memap_parser.mem_summary,
            "mem_report did not contain a correct copy of mem_summary")

    def test_generate_output_table(self):
        """
        Test ensures that an output of type "table" can be generated correctly
        
        :return:
        """
        self.generate_test_helper('table')

    def test_generate_output_json(self):
        """
        Test ensures that an output of type "json" can be generated correctly
        
        :return:
        """
        file_name = '.json_test_output.json'
        self.generate_test_helper('json', file_output=file_name)
        self.assertTrue(os.path.exists(file_name),
                        "Failed to create json file")
        os.remove(file_name)

    def test_generate_output_csv_ci(self):
        """
        Test ensures that an output of type "csv-ci" can be generated correctly
        
        :return:
        """
        file_name = '.csv_ci_test_output.csv'
        self.generate_test_helper('csv-ci', file_output=file_name)
        self.assertTrue(os.path.exists(file_name),
                        "Failed to create csv-ci file")
        os.remove(file_name)
コード例 #6
0
class MemapParserTests(unittest.TestCase):
    """
    Test cases for Test Api
    """

    def setUp(self):
        """
        Called before each test case

        :return:
        """
        self.memap_parser = MemapParser()

        self.memap_parser.modules = {
            "mbed-os/targets/TARGET/TARGET_MCUS/api/pinmap.o": {
                ".text": 1,
                ".data": 2,
                ".bss": 3,
                ".heap": 0,
                ".stack": 0,
                ".interrupts_ram":0,
                ".init":0,
                ".ARM.extab":0,
                ".ARM.exidx":0,
                ".ARM.attributes":0,
                ".eh_frame":0,
                ".init_array":0,
                ".fini_array":0,
                ".jcr":0,
                ".stab":0,
                ".stabstr":0,
                ".ARM.exidx":0,
                ".ARM":0,
                ".interrupts":0,
                ".flash_config":0,
                "unknown":0,
                "OUTPUT":0,
                },
            "[lib]/libc.a/lib_a-printf.o": {
                ".text": 4,
                ".data": 5,
                ".bss": 6,
                ".heap": 0,
                ".stack": 0,
                ".interrupts_ram":0,
                ".init":0,
                ".ARM.extab":0,
                ".ARM.exidx":0,
                ".ARM.attributes":0,
                ".eh_frame":0,
                ".init_array":0,
                ".fini_array":0,
                ".jcr":0,
                ".stab":0,
                ".stabstr":0,
                ".ARM.exidx":0,
                ".ARM":0,
                ".interrupts":0,
                ".flash_config":0,
                "unknown":0,
                "OUTPUT":0,
                },
            "main.o": {
                ".text": 7,
                ".data": 8,
                ".bss": 0,
                ".heap": 0,
                ".stack": 0,
                ".interrupts_ram":0,
                ".init":0,
                ".ARM.extab":0,
                ".ARM.exidx":0,
                ".ARM.attributes":0,
                ".eh_frame":0,
                ".init_array":0,
                ".fini_array":0,
                ".jcr":0,
                ".stab":0,
                ".stabstr":0,
                ".ARM.exidx":0,
                ".ARM":0,
                ".interrupts":0,
                ".flash_config":0,
                "unknown":0,
                "OUTPUT":0,
                },
            "test.o": {
                ".text": 0,
                ".data": 0,
                ".bss": 0,
                ".heap": 0,
                ".stack": 0,
                ".interrupts_ram":0,
                ".init":0,
                ".ARM.extab":0,
                ".ARM.exidx":0,
                ".ARM.attributes":0,
                ".eh_frame":0,
                ".init_array":0,
                ".fini_array":0,
                ".jcr":0,
                ".stab":0,
                ".stabstr":0,
                ".ARM.exidx":0,
                ".ARM":0,
                ".interrupts":0,
                ".flash_config":0,
                "unknown":0,
                "OUTPUT":0,
                },
        }

    def tearDown(self):
        """
        Called after each test case

        :return:
        """
        pass

    def generate_test_helper(self, output_type, depth, file_output=None):
        """
        Helper that ensures that the member variables "modules" is
        unchanged after calling "generate_output"

        :param output_type: type string that is passed to "generate_output"
        :param file_output: path to output file that is passed to "generate_output"
        :return:
        """

        old_modules = deepcopy(self.memap_parser.modules)

        self.memap_parser.generate_output(output_type, depth, file_output)

        self.assertEqual(self.memap_parser.modules, old_modules,
                        "generate_output modified the 'modules' property")


    def test_report_computed(self):
        """
        Test ensures the report and summary are computed

        :return:
        """

        self.memap_parser.generate_output('table', 2)

        # Report is created after generating output
        self.assertTrue(self.memap_parser.mem_summary)
        self.assertTrue(self.memap_parser.mem_report)

    def test_generate_output_table(self):
        """
        Test ensures that an output of type "table" can be generated correctly

        :return:
        """
        depth = 2
        self.generate_test_helper('table', depth)

    def test_generate_output_json(self):
        """
        Test ensures that an output of type "json" can be generated correctly

        :return:
        """
        file_name = '.json_test_output.json'
        depth = 2
        self.generate_test_helper('json', depth, file_output=file_name)
        self.assertTrue(os.path.exists(file_name), "Failed to create json file")
        os.remove(file_name)

    def test_generate_output_csv_ci(self):
        """
        Test ensures that an output of type "csv-ci" can be generated correctly

        :return:
        """
        file_name = '.csv_ci_test_output.csv'
        depth = 2
        self.generate_test_helper('csv-ci', depth, file_output=file_name)
        self.assertTrue(os.path.exists(file_name), "Failed to create csv-ci file")
        os.remove(file_name)
コード例 #7
0
ファイル: memap_test.py プロジェクト: akselsm/mbed
class MemapParserTests(unittest.TestCase):
    """
    Test cases for Test Api
    """

    def setUp(self):
        """
        Called before each test case

        :return:
        """
        self.memap_parser = MemapParser()
        
        self.memap_parser.modules = {
            "Misc": {
                "unknown": 0,
                ".ARM": 8,
                ".ARM.extab": 0,
                ".init": 12,
                "OUTPUT": 0,
                ".stack": 0,
                ".eh_frame": 0,
                ".fini_array": 4,
                ".heap": 0,
                ".stabstr": 0,
                ".interrupts_ram": 0,
                ".init_array": 0,
                ".stab": 0,
                ".ARM.attributes": 7347,
                ".bss": 8517,
                ".flash_config": 16,
                ".interrupts": 1024,
                ".data": 2325,
                ".ARM.exidx": 0,
                ".text": 59906,
                ".jcr": 0
            },
            "Fill": {
                "unknown": 12,
                ".ARM": 0,
                ".ARM.extab": 0,
                ".init": 0,
                "OUTPUT": 0,
                ".stack": 0,
                ".eh_frame": 0,
                ".fini_array": 0,
                ".heap": 65536,
                ".stabstr": 0,
                ".interrupts_ram": 1024,
                ".init_array": 0,
                ".stab": 0,
                ".ARM.attributes": 0,
                ".bss": 2235,
                ".flash_config": 0,
                ".interrupts": 0,
                ".data": 3,
                ".ARM.exidx": 0,
                ".text": 136,
                ".jcr": 0
            }
        }
        
        self.memap_parser.compute_report()

    def tearDown(self):
        """
        Called after each test case

        :return:
        """
        pass
    
    def generate_test_helper(self, output_type, file_output=None):
        """
        Helper that ensures that the member variables "modules", "mem_report",
        and "mem_summary" are unchanged after calling "generate_output"
        
        :param output_type: type string that is passed to "generate_output"
        :param file_output: path to output file that is passed to "generate_output"      
        :return:
        """
        
        old_modules = deepcopy(self.memap_parser.modules)
        old_report = deepcopy(self.memap_parser.mem_report)
        old_summary = deepcopy(self.memap_parser.mem_summary)
        self.memap_parser.generate_output(output_type, file_output)
        self.assertEqual(self.memap_parser.modules, old_modules,
                         "generate_output modified the 'modules' property")
        self.assertEqual(self.memap_parser.mem_report, old_report,
                         "generate_output modified the 'mem_report' property")
        self.assertEqual(self.memap_parser.mem_summary, old_summary,
                         "generate_output modified the 'mem_summary' property")

    def test_report_computed(self):
        """
        Test ensures the report and summary are computed
        
        :return:
        """
        self.assertTrue(self.memap_parser.mem_report)
        self.assertTrue(self.memap_parser.mem_summary)
        self.assertEqual(self.memap_parser.mem_report[-1]['summary'],
                         self.memap_parser.mem_summary,
                         "mem_report did not contain a correct copy of mem_summary")
    
    def test_generate_output_table(self):
        """
        Test ensures that an output of type "table" can be generated correctly
        
        :return:
        """
        self.generate_test_helper('table')
    
    def test_generate_output_json(self):
        """
        Test ensures that an output of type "json" can be generated correctly
        
        :return:
        """
        file_name = '.json_test_output.json'
        self.generate_test_helper('json', file_output=file_name)
        self.assertTrue(os.path.exists(file_name), "Failed to create json file")
        os.remove(file_name)
    
    def test_generate_output_csv_ci(self):
        """
        Test ensures that an output of type "csv-ci" can be generated correctly
        
        :return:
        """
        file_name = '.csv_ci_test_output.csv'
        self.generate_test_helper('csv-ci', file_output=file_name)
        self.assertTrue(os.path.exists(file_name), "Failed to create csv-ci file")
        os.remove(file_name)