def test_update(self):
        symbol_mapping_cache = SymbolMappingCache()
        cache_f = cStringIO.StringIO()
        cache_f.write(self._TEST_FUNCTION_CACHE)

        # No update from self._TEST_FUNCTION_CACHE
        symbol_mapping_cache.update(
            FUNCTION_SYMBOLS,
            self.MockBucketSet(self._TEST_FUNCTION_ADDRESS_LIST1),
            self.MockSymbolFinder(self._TEST_FUNCTION_DICT), cache_f)
        for address in self._TEST_FUNCTION_ADDRESS_LIST1:
            self.assertEqual(
                self._TEST_FUNCTION_DICT[address],
                symbol_mapping_cache.lookup(FUNCTION_SYMBOLS, address))
        self.assertEqual(self._TEST_FUNCTION_CACHE, cache_f.getvalue())

        # Update to self._TEST_FUNCTION_ADDRESS_LIST2
        symbol_mapping_cache.update(
            FUNCTION_SYMBOLS,
            self.MockBucketSet(self._TEST_FUNCTION_ADDRESS_LIST2),
            self.MockSymbolFinder(self._TEST_FUNCTION_DICT), cache_f)
        for address in self._TEST_FUNCTION_ADDRESS_LIST2:
            self.assertEqual(
                self._TEST_FUNCTION_DICT[address],
                symbol_mapping_cache.lookup(FUNCTION_SYMBOLS, address))
        self.assertEqual(self._EXPECTED_TEST_FUNCTION_CACHE,
                         cache_f.getvalue())
 def load_basic_files(dump_path,
                      multiple,
                      no_dump=False,
                      alternative_dirs=None):
     prefix = SubCommand._find_prefix(dump_path)
     # If the target process is estimated to be working on Android, converts
     # a path in the Android device to a path estimated to be corresponding in
     # the host.  Use --alternative-dirs to specify the conversion manually.
     if not alternative_dirs:
         alternative_dirs = SubCommand._estimate_alternative_dirs(prefix)
     if alternative_dirs:
         for device, host in alternative_dirs.iteritems():
             LOGGER.info('Assuming %s on device as %s on host' %
                         (device, host))
     symbol_data_sources = SymbolDataSources(prefix, alternative_dirs)
     symbol_data_sources.prepare()
     bucket_set = BucketSet()
     bucket_set.load(prefix)
     if not no_dump:
         if multiple:
             dump_list = DumpList.load(
                 SubCommand._find_all_dumps(dump_path))
         else:
             dump = Dump.load(dump_path)
     symbol_mapping_cache = SymbolMappingCache()
     with open(prefix + '.cache.function', 'a+') as cache_f:
         symbol_mapping_cache.update(
             FUNCTION_SYMBOLS, bucket_set,
             SymbolFinder(FUNCTION_SYMBOLS, symbol_data_sources), cache_f)
     with open(prefix + '.cache.typeinfo', 'a+') as cache_f:
         symbol_mapping_cache.update(
             TYPEINFO_SYMBOLS, bucket_set,
             SymbolFinder(TYPEINFO_SYMBOLS, symbol_data_sources), cache_f)
     with open(prefix + '.cache.sourcefile', 'a+') as cache_f:
         symbol_mapping_cache.update(
             SOURCEFILE_SYMBOLS, bucket_set,
             SymbolFinder(SOURCEFILE_SYMBOLS, symbol_data_sources), cache_f)
     bucket_set.symbolize(symbol_mapping_cache)
     if no_dump:
         return bucket_set
     elif multiple:
         return (bucket_set, dump_list)
     else:
         return (bucket_set, dump)