"""Test the LLDB module cache funcionality."""
import glob
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
import os
import time
class ModuleCacheTestcaseSimple(TestBase):
def setUp(self):
TestBase.setUp(self)
self.cache_dir = os.path.join(self.getBuildDir(), "lldb-module-cache")
self.runCmd(
'settings set symbols.lldb-index-cache-path "%s"' % (self.cache_dir)
)
self.runCmd("settings set symbols.enable-lldb-index-cache true")
self.build()
def get_module_cache_files(self, basename):
module_file_glob = os.path.join(
self.cache_dir, "llvmcache-*%s*-symtab-*" % (basename)
)
return glob.glob(module_file_glob)
@no_debug_info_test
@skipIfWindows
def test(self):
"""
Test module cache functionality for a simple object file.
This will test that if we enable the module cache, we have a
corresponding index cache entry for the symbol table for the
executable. It also removes the executable, rebuilds so that the
modification time of the binary gets updated, and then creates a new
target and should cause the cache to get updated so the cache file
should get an updated modification time.
"""
exe = self.getBuildArtifact("a.out")
target = self.createTestTarget(load_dependent_modules=False)
main_module = target.GetModuleAtIndex(0)
self.assertTrue(main_module.IsValid())
main_module.GetNumSymbols()
cache_files = self.get_module_cache_files("a.out")
self.assertEqual(
len(cache_files), 1, "make sure there is only one cache file for 'a.out'"
)
symtab_cache_path = cache_files[0]
exe_mtime_1 = os.path.getmtime(exe)
symtab_mtime_1 = os.path.getmtime(symtab_cache_path)
os.remove(exe)
self.assertFalse(
os.path.exists(exe), "make sure we were able to remove the executable"
)
time.sleep(2)
self.build(dictionary={"CFLAGS_EXTRAS": "-DEXTRA_FUNCTION"})
self.assertTrue(
os.path.exists(exe), "make sure executable exists after rebuild"
)
exe_mtime_2 = os.path.getmtime(exe)
self.assertNotEqual(
exe_mtime_1,
exe_mtime_2,
"make sure the modification time of the executable has changed",
)
self.assertEqual(
symtab_mtime_1,
os.path.getmtime(symtab_cache_path),
"check that the 'symtab' cache file modification time doesn't match the executable modification time after rebuild",
)
target = self.createTestTarget(load_dependent_modules=False)
main_module = target.GetModuleAtIndex(0)
self.assertTrue(main_module.IsValid())
main_module.GetNumSymbols()
self.assertTrue(
os.path.exists(symtab_cache_path),
'make sure "symtab" cache files exists after cache is updated',
)
symtab_mtime_2 = os.path.getmtime(symtab_cache_path)
self.assertNotEqual(
symtab_mtime_1,
symtab_mtime_2,
'make sure modification time of "symtab-..." changed',
)