Index: packages/Python/lldbsuite/test/api/listeners/TestListener.py =================================================================== --- packages/Python/lldbsuite/test/api/listeners/TestListener.py +++ packages/Python/lldbsuite/test/api/listeners/TestListener.py @@ -23,10 +23,10 @@ def setUp(self): # Call super's setUp(). TestBase.setUp(self) - self.build() def test_receiving_breakpoint_added(self): """Test that we get breakpoint added events, waiting on event classes on the debugger""" + self.build() my_listener = lldb.SBListener("test_listener") Index: packages/Python/lldbsuite/test/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py =================================================================== --- packages/Python/lldbsuite/test/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py +++ packages/Python/lldbsuite/test/functionalities/breakpoint/comp_dir_symlink/TestCompDirSymLink.py @@ -28,8 +28,6 @@ self.line = line_number( os.path.join(self.getSourceDir(), "main.cpp"), '// Set break point at this line.') - self.src_path = self.getBuildArtifact(_SRC_FILE) - @skipIf(hostoslist=["windows"]) def test_symlink_paths_set(self): @@ -38,7 +36,8 @@ self.runCmd( "settings set %s %s" % (_COMP_DIR_SYM_LINK_PROP, pwd_symlink)) - lldbutil.run_break_set_by_file_and_line(self, self.src_path, self.line) + src_path = self.getBuildArtifact(_SRC_FILE) + lldbutil.run_break_set_by_file_and_line(self, src_path, self.line) @skipIf(hostoslist=no_match(["linux"])) def test_symlink_paths_set_procselfcwd(self): @@ -48,21 +47,24 @@ self.runCmd( "settings set %s %s" % (_COMP_DIR_SYM_LINK_PROP, pwd_symlink)) - lldbutil.run_break_set_by_file_and_line(self, self.src_path, self.line) + src_path = self.getBuildArtifact(_SRC_FILE) + lldbutil.run_break_set_by_file_and_line(self, src_path, self.line) @skipIf(hostoslist=["windows"]) def test_symlink_paths_unset(self): pwd_symlink = self.create_src_symlink() self.doBuild(pwd_symlink) self.runCmd('settings clear ' + _COMP_DIR_SYM_LINK_PROP) + src_path = self.getBuildArtifact(_SRC_FILE) self.assertRaises( AssertionError, lldbutil.run_break_set_by_file_and_line, self, - self.src_path, + src_path, self.line) def create_src_symlink(self): + self.makeBuildDir() pwd_symlink = self.getBuildArtifact('pwd_symlink') if os.path.exists(pwd_symlink): os.unlink(pwd_symlink) Index: packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py =================================================================== --- packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py +++ packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py @@ -22,13 +22,15 @@ def setUp(self): # Call super's setUp(). TestBase.setUp(self) - lldbutil.mkdir_p(self.getBuildArtifact("hidden")) # Find the line number to break for main.cpp. self.line = line_number( 'main.cpp', '// Set break point at this line for test_lldb_process_load_and_unload_commands().') self.line_d_function = line_number( 'd.cpp', '// Find this line number within d_dunction().') + + def setup_test(self): + lldbutil.mkdir_p(self.getBuildArtifact("hidden")) if not self.platformIsDarwin(): if not lldb.remote_platform and "LD_LIBRARY_PATH" in os.environ: self.runCmd( @@ -94,7 +96,7 @@ @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently def test_modules_search_paths(self): """Test target modules list after loading a different copy of the library libd.dylib, and verifies that it works with 'target modules search-paths add'.""" - + self.setup_test() # Invoke the default build rule. self.build() @@ -157,7 +159,7 @@ @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently def test_dyld_library_path(self): """Test (DY)LD_LIBRARY_PATH after moving libd.dylib, which defines d_function, somewhere else.""" - + self.setup_test() # Invoke the default build rule. self.build() self.copy_shlibs_to_remote(hidden_dir=True) @@ -224,7 +226,7 @@ @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently def test_lldb_process_load_and_unload_commands(self): """Test that lldb process load/unload command work correctly.""" - + self.setup_test() # Invoke the default build rule. self.build() self.copy_shlibs_to_remote() @@ -298,7 +300,7 @@ @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support def test_load_unload(self): """Test breakpoint by name works correctly with dlopen'ing.""" - + self.setup_test() # Invoke the default build rule. self.build() self.copy_shlibs_to_remote() @@ -341,7 +343,7 @@ @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently def test_step_over_load(self): """Test stepping over code that loads a shared library works correctly.""" - + self.setup_test() # Invoke the default build rule. self.build() self.copy_shlibs_to_remote() @@ -376,7 +378,7 @@ @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently def test_static_init_during_load(self): """Test that we can set breakpoints correctly in static initializers""" - + self.setup_test() self.build() self.copy_shlibs_to_remote() Index: packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_on_vectors/TestValueOfVectorVariable.py =================================================================== --- packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_on_vectors/TestValueOfVectorVariable.py +++ packages/Python/lldbsuite/test/functionalities/watchpoint/watchpoint_on_vectors/TestValueOfVectorVariable.py @@ -22,8 +22,10 @@ bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows") def test_value_of_vector_variable_using_watchpoint_set(self): """Test verify displayed value of vector variable.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) + exe = self.getBuildArtifact("a.out") + d = {'C_SOURCES': self.source, 'EXE': exe} + self.build(dictionary=d) + self.setTearDownCleanup(dictionary=d) self.value_of_vector_variable_with_watchpoint_set() def setUp(self): @@ -31,12 +33,11 @@ TestBase.setUp(self) # Our simple source filename. self.source = 'main.c' - self.exe_name = self.getBuildArtifact("a.out") - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} def value_of_vector_variable_with_watchpoint_set(self): """Test verify displayed value of vector variable""" exe = self.getBuildArtifact("a.out") + d = {'C_SOURCES': self.source, 'EXE': exe} self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Set break to get a frame Index: packages/Python/lldbsuite/test/lldbinline.py =================================================================== --- packages/Python/lldbsuite/test/lldbinline.py +++ packages/Python/lldbsuite/test/lldbinline.py @@ -88,13 +88,14 @@ # The -N option says to NOT run a if it matches the option argument, so # if we are using dSYM we say to NOT run dwarf (-N dwarf) and vice # versa. + testdir, _ = self.mydir if self.using_dsym is None: # The test was skipped altogether. return "" elif self.using_dsym: - return "-N dwarf %s" % (self.mydir) + return "-N dwarf %s" % (testdir) else: - return "-N dsym %s" % (self.mydir) + return "-N dsym %s" % (testdir) def BuildMakefile(self): self.makeBuildDir() @@ -114,8 +115,9 @@ makefile = open(makefilePath, 'w+') + testdir, _ = self.mydir level = os.sep.join( - [".."] * len(self.mydir.split(os.sep))) + os.sep + "make" + [".."] * len(testdir.split(os.sep))) + os.sep + "make" makefile.write("LEVEL = " + level + "\n") Index: packages/Python/lldbsuite/test/lldbtest.py =================================================================== --- packages/Python/lldbsuite/test/lldbtest.py +++ packages/Python/lldbsuite/test/lldbtest.py @@ -523,11 +523,20 @@ @staticmethod def compute_mydir(test_file): - '''Subclasses should call this function to correctly calculate the required "mydir" attribute as follows: + '''Subclasses should call this function to correctly calculate the + required "mydir" attribute as follows: - mydir = TestBase.compute_mydir(__file__)''' - test_dir = os.path.dirname(test_file) - return test_dir[len(os.environ["LLDB_TEST"]) + 1:] + mydir = TestBase.compute_mydir(__file__) + ''' + # /abs/path/to/packages/group/subdir/mytest.py -> group/subdir, mytest + rel_prefix = test_file[len(os.environ["LLDB_TEST"]) + 1:] + if rel_prefix[-3:] == ".py": + rel_prefix = rel_prefix[:-3] + elif rel_prefix[-4:] == ".pyc": + rel_prefix = rel_prefix[:-4] + else: + raise Exception("test_file is not a python file") + return os.path.split(rel_prefix) def TraceOn(self): """Returns True if we are in trace mode (tracing detailed test execution).""" @@ -549,32 +558,11 @@ # Change current working directory if ${LLDB_TEST} is defined. # See also dotest.py which sets up ${LLDB_TEST}. if ("LLDB_TEST" in os.environ): - full_dir = os.path.join(os.environ["LLDB_TEST"], cls.mydir) + full_dir = os.path.join(os.environ["LLDB_TEST"], + cls.mydir[0]) if traceAlways: print("Change dir to:", full_dir, file=sys.stderr) - os.chdir(os.path.join(os.environ["LLDB_TEST"], cls.mydir)) - - # TODO: Obsolete this by creating one working dir per configuration. - if debug_confirm_directory_exclusivity: - import lock - cls.dir_lock = lock.Lock(os.path.join(full_dir, ".dirlock")) - try: - cls.dir_lock.try_acquire() - # write the class that owns the lock into the lock file - cls.dir_lock.handle.write(cls.__name__) - except IOError as ioerror: - # nothing else should have this directory lock - # wait here until we get a lock - cls.dir_lock.acquire() - # read the previous owner from the lock file - lock_id = cls.dir_lock.handle.read() - print( - "LOCK ERROR: {} wants to lock '{}' but it is already locked by '{}'".format( - cls.__name__, - full_dir, - lock_id), - file=sys.stderr) - raise ioerror + os.chdir(full_dir) # Set platform context. cls.platformContext = lldbplatformutil.createPlatformContext() @@ -694,7 +682,7 @@ if not lldb.remote_platform or not configuration.lldb_platform_working_dir: return - components = [str(self.test_number)] + self.mydir.split(os.path.sep) + components = [str(self.test_number)] + self.mydir[0].split(os.path.sep) remote_test_dir = configuration.lldb_platform_working_dir for c in components: remote_test_dir = lldbutil.join_remote_paths(remote_test_dir, c) @@ -721,11 +709,17 @@ def getSourceDir(self): """Return the full path to the current test.""" - return os.path.join(os.environ["LLDB_TEST"], self.mydir) + subdir, stem = self.mydir + return os.path.join(os.environ["LLDB_TEST"], subdir) def getBuildDir(self): """Return the full path to the current test.""" - return os.path.join(os.environ["LLDB_BUILD"], self.mydir) + variant = self.debug_info + subdir, stem = self.mydir + if not variant: + variant = 'default' + return os.path.join(os.environ["LLDB_BUILD"], subdir, + stem + '.' + variant) def makeBuildDir(self): @@ -1777,6 +1771,7 @@ supported_categories = [ x for x in categories if test_categories.is_supported_on_platform( x, target_platform, configuration.compiler)] + if "dsym" in supported_categories: @decorators.add_test_categories(["dsym"]) @wraps(attrvalue) Index: packages/Python/lldbsuite/test/plugins/builder_base.py =================================================================== --- packages/Python/lldbsuite/test/plugins/builder_base.py +++ packages/Python/lldbsuite/test/plugins/builder_base.py @@ -50,30 +50,32 @@ return ("ARCHFLAG=" + archflag) if archflag else "" -def getMake(test_subdir): +def getMake(dir_stem, variant = "default"): """Returns the invocation for GNU make. - The argument test_subdir is the relative path to the testcase.""" + The first argument is a tuple of the relative path to the testcase + and its filename stem.""" if platform.system() == "FreeBSD" or platform.system() == "NetBSD": make = "gmake" else: make = "make" # Construct the base make invocation. + test_subdir, test_stem = dir_stem lldb_test = os.environ["LLDB_TEST"] lldb_build = os.environ["LLDB_BUILD"] - if not (lldb_test and lldb_build and test_subdir and + if not (lldb_test and lldb_build and test_subdir and test_stem and (not os.path.isabs(test_subdir))): raise Exception("Could not derive test directories") - build_dir = os.path.join(lldb_build, test_subdir) - test_dir = os.path.join(lldb_test, test_subdir) + build_dir = os.path.join(lldb_build, test_subdir, test_stem + '.' + variant) + src_dir = os.path.join(lldb_test, test_subdir) # This is a bit of a hack to make inline testcases work. - makefile = os.path.join(test_dir, "Makefile") + makefile = os.path.join(src_dir, "Makefile") if not os.path.isfile(makefile): makefile = os.path.join(build_dir, "Makefile") return [make, - "VPATH="+test_dir, + "VPATH="+src_dir, "-C", build_dir, - "-I", test_dir, + "-I", src_dir, "-f", makefile] @@ -164,9 +166,11 @@ """Build the binaries with dwarf debug info.""" commands = [] if clean: - commands.append(getMake(testdir) + ["clean", getCmdLine(dictionary)]) - commands.append(getMake(testdir) + ["MAKE_DSYM=NO", getArchSpec( - architecture), getCCSpec(compiler), getCmdLine(dictionary)]) + commands.append(getMake(testdir, "dwarf") + + ["clean", getCmdLine(dictionary)]) + commands.append(getMake(testdir, "dwarf") + + ["MAKE_DSYM=NO", getArchSpec(architecture), + getCCSpec(compiler), getCmdLine(dictionary)]) runBuildCommands(commands, sender=sender) # True signifies that we can handle building dwarf. @@ -183,8 +187,9 @@ """Build the binaries with dwarf debug info.""" commands = [] if clean: - commands.append(getMake(testdir) + ["clean", getCmdLine(dictionary)]) - commands.append(getMake(testdir) + + commands.append(getMake(testdir, "dwo") + + ["clean", getCmdLine(dictionary)]) + commands.append(getMake(testdir, "dwo") + ["MAKE_DSYM=NO", "MAKE_DWO=YES", getArchSpec(architecture), getCCSpec(compiler), @@ -205,8 +210,9 @@ """Build the binaries with dwarf debug info.""" commands = [] if clean: - commands.append(getMake(testdir) + ["clean", getCmdLine(dictionary)]) - commands.append(getMake(testdir) + + commands.append(getMake(testdir, "gmodules") + + ["clean", getCmdLine(dictionary)]) + commands.append(getMake(testdir, "gmodules") + ["MAKE_DSYM=NO", "MAKE_GMODULES=YES", getArchSpec(architecture), Index: packages/Python/lldbsuite/test/plugins/builder_darwin.py =================================================================== --- packages/Python/lldbsuite/test/plugins/builder_darwin.py +++ packages/Python/lldbsuite/test/plugins/builder_darwin.py @@ -16,8 +16,9 @@ commands = [] if clean: - commands.append(getMake(testdir) + ["clean", getCmdLine(dictionary)]) - commands.append(getMake(testdir) + + commands.append(getMake(testdir, "dsym") + + ["clean", getCmdLine(dictionary)]) + commands.append(getMake(testdir, "dsym") + ["MAKE_DSYM=YES", getArchSpec(architecture), getCCSpec(compiler), Index: packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py =================================================================== --- packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py +++ packages/Python/lldbsuite/test/python_api/hello_world/TestHelloWorld.py @@ -20,9 +20,6 @@ def setUp(self): # Call super's setUp(). TestBase.setUp(self) - # Get the full path to our executable to be attached/debugged. - self.exe = self.getBuildArtifact(self.testMethodName) - self.d = {'EXE': self.testMethodName} # Find a couple of the line numbers within main.c. self.line1 = line_number('main.c', '// Set break point at this line.') self.line2 = line_number('main.c', '// Waiting to be attached...') @@ -37,9 +34,12 @@ @skipIfiOSSimulator def test_with_process_launch_api(self): """Create target, breakpoint, launch a process, and then kill it.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - target = self.dbg.CreateTarget(self.exe) + # Get the full path to our executable to be attached/debugged. + exe = self.getBuildArtifact(self.testMethodName) + d = {'EXE': exe} + self.build(dictionary=d) + self.setTearDownCleanup(dictionary=d) + target = self.dbg.CreateTarget(exe) breakpoint = target.BreakpointCreateByLocation("main.c", self.line1) @@ -82,12 +82,14 @@ @expectedFailureAll(oslist=['ios', 'watchos', 'tvos', 'bridgeos'], bugnumber="") # old lldb-server has race condition, launching an inferior and then launching debugserver in quick succession sometimes fails def test_with_attach_to_process_with_id_api(self): """Create target, spawn a process, and attach to it with process id.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - target = self.dbg.CreateTarget(self.exe) + exe = self.getBuildArtifact(self.testMethodName) + d = {'EXE': exe} + self.build(dictionary=d) + self.setTearDownCleanup(dictionary=d) + target = self.dbg.CreateTarget(exe) # Spawn a new process - popen = self.spawnSubprocess(self.exe, ["abc", "xyz"]) + popen = self.spawnSubprocess(exe, ["abc", "xyz"]) self.addTearDownHook(self.cleanupSubprocesses) # Give the subprocess time to start and wait for user input @@ -112,12 +114,14 @@ @expectedFailureAll(oslist=['ios', 'watchos', 'tvos', 'bridgeos'], bugnumber="") # old lldb-server has race condition, launching an inferior and then launching debugserver in quick succession sometimes fails def test_with_attach_to_process_with_name_api(self): """Create target, spawn a process, and attach to it with process name.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - target = self.dbg.CreateTarget(self.exe) + exe = self.getBuildArtifact(self.testMethodName) + d = {'EXE': exe} + self.build(dictionary=d) + self.setTearDownCleanup(dictionary=d) + target = self.dbg.CreateTarget(exe) # Spawn a new process - popen = self.spawnSubprocess(self.exe, ["abc", "xyz"]) + popen = self.spawnSubprocess(exe, ["abc", "xyz"]) self.addTearDownHook(self.cleanupSubprocesses) # Give the subprocess time to start and wait for user input @@ -127,7 +131,7 @@ error = lldb.SBError() # Pass 'False' since we don't want to wait for new instance of # "hello_world" to be launched. - name = os.path.basename(self.exe) + name = os.path.basename(exe) # While we're at it, make sure that passing a None as the process name # does not hang LLDB. Index: packages/Python/lldbsuite/test/python_api/process/io/TestProcessIO.py =================================================================== --- packages/Python/lldbsuite/test/python_api/process/io/TestProcessIO.py +++ packages/Python/lldbsuite/test/python_api/process/io/TestProcessIO.py @@ -19,6 +19,8 @@ def setUp(self): # Call super's setUp(). TestBase.setUp(self) + + def setup_test(self): # Get the full path to our executable to be debugged. self.exe = self.getBuildArtifact("process_io") self.local_input_file = self.getBuildArtifact("input.txt") @@ -38,6 +40,7 @@ @expectedFlakeyLinux(bugnumber="llvm.org/pr26437") def test_stdin_by_api(self): """Exercise SBProcess.PutSTDIN().""" + self.setup_test() self.build() self.create_target() self.run_process(True) @@ -49,6 +52,7 @@ @expectedFlakeyLinux(bugnumber="llvm.org/pr26437") def test_stdin_redirection(self): """Exercise SBLaunchInfo::AddOpenFileAction() for STDIN without specifying STDOUT or STDERR.""" + self.setup_test() self.build() self.create_target() self.redirect_stdin() @@ -62,6 +66,7 @@ @skipIfDarwinEmbedded # debugserver can't create/write files on the device def test_stdout_redirection(self): """Exercise SBLaunchInfo::AddOpenFileAction() for STDOUT without specifying STDIN or STDERR.""" + self.setup_test() self.build() self.create_target() self.redirect_stdout() @@ -76,6 +81,7 @@ @skipIfDarwinEmbedded # debugserver can't create/write files on the device def test_stderr_redirection(self): """Exercise SBLaunchInfo::AddOpenFileAction() for STDERR without specifying STDIN or STDOUT.""" + self.setup_test() self.build() self.create_target() self.redirect_stderr() @@ -90,6 +96,7 @@ @skipIfDarwinEmbedded # debugserver can't create/write files on the device def test_stdout_stderr_redirection(self): """Exercise SBLaunchInfo::AddOpenFileAction() for STDOUT and STDERR without redirecting STDIN.""" + self.setup_test() self.build() self.create_target() self.redirect_stdout() Index: packages/Python/lldbsuite/test/python_api/symbol-context/TestSymbolContext.py =================================================================== --- packages/Python/lldbsuite/test/python_api/symbol-context/TestSymbolContext.py +++ packages/Python/lldbsuite/test/python_api/symbol-context/TestSymbolContext.py @@ -73,10 +73,7 @@ str(compileUnit), "The compile unit should match", exe=False, - substrs=[ - os.path.join( - self.mydir, - 'main.c')]) + substrs=[self.getSourcePath('main.c')]) function = context.GetFunction() self.assertTrue(function) @@ -88,12 +85,12 @@ lineEntry = context.GetLineEntry() #print("line entry:", lineEntry) + reldir, _ = self.mydir self.expect( lineEntry.GetFileSpec().GetDirectory(), "The line entry should have the correct directory", exe=False, - substrs=[ - self.mydir]) + substrs=[reldir]) self.expect( lineEntry.GetFileSpec().GetFilename(), "The line entry should have the correct filename", Index: packages/Python/lldbsuite/test/python_api/value_var_update/TestValueVarUpdate.py =================================================================== --- packages/Python/lldbsuite/test/python_api/value_var_update/TestValueVarUpdate.py +++ packages/Python/lldbsuite/test/python_api/value_var_update/TestValueVarUpdate.py @@ -20,16 +20,16 @@ def setUp(self): # Call super's setUp(). TestBase.setUp(self) - # Get the full path to our executable to be attached/debugged. - self.exe = self.getBuildArtifact(self.testMethodName) - self.d = {'EXE': self.testMethodName} @add_test_categories(['pyapi']) def test_with_process_launch_api(self): """Test SBValue::GetValueDidChange""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - target = self.dbg.CreateTarget(self.exe) + # Get the full path to our executable to be attached/debugged. + exe = self.getBuildArtifact(self.testMethodName) + d = {'EXE': exe} + self.build(dictionary=d) + self.setTearDownCleanup(dictionary=d) + target = self.dbg.CreateTarget(exe) breakpoint = target.BreakpointCreateBySourceRegex( "break here", lldb.SBFileSpec("main.c"))