Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/TestProcessLaunch.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/TestProcessLaunch.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/process_launch/TestProcessLaunch.py @@ -19,6 +19,7 @@ class ProcessLaunchTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True def setUp(self): # Call super's setUp(). @@ -38,8 +39,8 @@ patterns=["Current executable set to .*a.out"]) in_file = "input-file.txt" - out_file = "output-test.out" - err_file = "output-test.err" + out_file = lldbutil.append_to_process_working_directory(self, "output-test.out") + err_file = lldbutil.append_to_process_working_directory(self, "output-test.err") # Make sure the output files do not exist before launching the process try: @@ -52,8 +53,8 @@ except OSError: pass - launch_command = "process launch -i " + \ - in_file + " -o " + out_file + " -e " + err_file + launch_command = "process launch -i '{0}' -o '{1}' -e '{2}' -w '{3}'".format( + in_file, out_file, err_file, self.get_process_working_directory()) if lldb.remote_platform: self.runCmd('platform put-file "{local}" "{remote}"'.format( @@ -62,55 +63,19 @@ self.expect(launch_command, patterns=["Process .* launched: .*a.out"]) - if lldb.remote_platform: - self.runCmd('platform get-file "{remote}" "{local}"'.format( - remote=out_file, local=out_file)) - self.runCmd('platform get-file "{remote}" "{local}"'.format( - remote=err_file, local=err_file)) - success = True err_msg = "" - # Check to see if the 'stdout' file was created - try: - out_f = open(out_file) - except IOError: + out = lldbutil.read_file_on_target(self, out_file) + if out != "This should go to stdout.\n": success = False - err_msg = err_msg + " ERROR: stdout file was not created.\n" - else: - # Check to see if the 'stdout' file contains the right output - line = out_f.readline() - if line != "This should go to stdout.\n": - success = False - err_msg = err_msg + " ERROR: stdout file does not contain correct output.\n" - out_f.close() + err_msg = err_msg + " ERROR: stdout file does not contain correct output.\n" - # Try to delete the 'stdout' file - try: - os.remove(out_file) - except OSError: - pass - # Check to see if the 'stderr' file was created - try: - err_f = open(err_file) - except IOError: + err = lldbutil.read_file_on_target(self, err_file) + if err != "This should go to stderr.\n": success = False - err_msg = err_msg + " ERROR: stderr file was not created.\n" - else: - # Check to see if the 'stderr' file contains the right output - line = err_f.readline() - if line != "This should go to stderr.\n": - success = False - err_msg = err_msg + " ERROR: stderr file does not contain correct output.\n\ -" - err_f.close() - - # Try to delete the 'stderr' file - try: - os.remove(err_file) - except OSError: - pass + err_msg = err_msg + " ERROR: stderr file does not contain correct output.\n" if not success: self.fail(err_msg) Index: lldb/trunk/packages/Python/lldbsuite/test/functionalities/single-quote-in-filename-to-lldb/TestSingleQuoteInFilename.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/single-quote-in-filename-to-lldb/TestSingleQuoteInFilename.py +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/single-quote-in-filename-to-lldb/TestSingleQuoteInFilename.py @@ -10,7 +10,7 @@ from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil - +import six class SingleQuoteInCommandLineTestCase(TestBase): @@ -50,32 +50,24 @@ self.getBuildArtifact(self.myexe))) child = self.child child.setecho(True) - # Turn on logging for input/output to/from the child. - with open('child_send.txt', 'w') as f_send: - with open('child_read.txt', 'w') as f_read: - child.logfile_send = f_send - child.logfile_read = f_read - - child.expect_exact(prompt) - - child.send("help watchpoint") - child.sendline('') - child.expect_exact(prompt) + child.logfile_send = send = six.StringIO() + child.logfile_read = read = six.StringIO() + child.expect_exact(prompt) + + child.send("help watchpoint") + child.sendline('') + child.expect_exact(prompt) # Now that the necessary logging is done, restore logfile to None to # stop further logging. child.logfile_send = None child.logfile_read = None - with open('child_send.txt', 'r') as fs: - if self.TraceOn(): - print("\n\nContents of child_send.txt:") - print(fs.read()) - with open('child_read.txt', 'r') as fr: - from_child = fr.read() - if self.TraceOn(): - print("\n\nContents of child_read.txt:") - print(from_child) + if self.TraceOn(): + print("\n\nContents of send") + print(send.getvalue()) + print("\n\nContents of read") + print(read.getvalue()) - self.expect(from_child, exe=False, - substrs=["Current executable set to"]) + self.expect(read.getvalue(), exe=False, + substrs=["Current executable set to"]) Index: lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py +++ lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py @@ -1321,6 +1321,21 @@ target)) +def read_file_on_target(test, remote): + if lldb.remote_platform: + local = test.getBuildArtifact("file_from_target") + error = lldb.remote_platform.Get(lldb.SBFileSpec(remote, False), + lldb.SBFileSpec(local, True)) + test.assertTrue(error.Success(), "Reading file {0} failed: {1}".format(remote, error)) + else: + local = remote + with open(local, 'r') as f: + return f.read() + +def read_file_from_process_wd(test, name): + path = append_to_process_working_directory(test, name) + return read_file_on_target(test, path) + def wait_for_file_on_target(testcase, file_path, max_attempts=6): for i in range(max_attempts): err, retcode, msg = testcase.run_platform_command("ls %s" % file_path) @@ -1335,9 +1350,4 @@ "File %s not found even after %d attempts." % (file_path, max_attempts)) - err, retcode, data = testcase.run_platform_command("cat %s" % (file_path)) - - testcase.assertTrue( - err.Success() and retcode == 0, "Failed to read file %s: %s, retcode: %d" % - (file_path, err.GetCString(), retcode)) - return data + return read_file_on_target(testcase, file_path) Index: lldb/trunk/packages/Python/lldbsuite/test/settings/TestSettings.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/settings/TestSettings.py +++ lldb/trunk/packages/Python/lldbsuite/test/settings/TestSettings.py @@ -17,16 +17,8 @@ class SettingsCommandTestCase(TestBase): mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True - @classmethod - def classCleanup(cls): - """Cleanup the test byproducts.""" - cls.RemoveTempFile("output1.txt") - cls.RemoveTempFile("output2.txt") - cls.RemoveTempFile("stderr.txt") - cls.RemoveTempFile("stdout.txt") - - @no_debug_info_test def test_apropos_should_also_search_settings_description(self): """Test that 'apropos' command should also search descriptions for the settings variables.""" @@ -35,7 +27,6 @@ "environment variables", "executable's environment"]) - @no_debug_info_test def test_append_target_env_vars(self): """Test that 'append target.run-args' works.""" # Append the env-vars. @@ -48,7 +39,6 @@ self.expect('settings show target.env-vars', substrs=['MY_ENV_VAR=YES']) - @no_debug_info_test def test_insert_before_and_after_target_run_args(self): """Test that 'insert-before/after target.run-args' works.""" # Set the run-args first. @@ -70,7 +60,6 @@ '[3]: "b"', '[4]: "c"']) - @no_debug_info_test def test_replace_target_run_args(self): """Test that 'replace target.run-args' works.""" # Set the run-args and then replace the index-0 element. @@ -88,7 +77,6 @@ '[1]: "b"', '[2]: "c"']) - @no_debug_info_test def test_set_prompt(self): """Test that 'set prompt' actually changes the prompt.""" @@ -106,7 +94,6 @@ # Use '-r' option to reset to the original default prompt. self.runCmd("settings clear prompt") - @no_debug_info_test def test_set_term_width(self): """Test that 'set term-width' actually changes the term-width.""" @@ -153,7 +140,8 @@ substrs=[format_string]) self.runCmd("breakpoint set -n main") - self.runCmd("run") + self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), + RUN_SUCCEEDED) self.expect("thread backtrace", substrs=["`main", self.getSourceDir()]) @@ -231,13 +219,11 @@ self.addTearDownHook( lambda: self.runCmd("settings clear target.env-vars")) - self.runCmd("run", RUN_SUCCEEDED) + self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), + RUN_SUCCEEDED) # Read the output file produced by running the program. - if lldb.remote_platform: - self.runCmd('platform get-file "output2.txt" "output2.txt"') - with open('output2.txt', 'r') as f: - output = f.read() + output = lldbutil.read_file_from_process_wd(self, "output2.txt") self.expect( output, @@ -272,13 +258,11 @@ os.environ.pop("MY_HOST_ENV_VAR2") self.addTearDownHook(unset_env_variables) - self.runCmd("run", RUN_SUCCEEDED) + self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), + RUN_SUCCEEDED) # Read the output file produced by running the program. - if lldb.remote_platform: - self.runCmd('platform get-file "output1.txt" "output1.txt"') - with open('output1.txt', 'r') as f: - output = f.read() + output = lldbutil.read_file_from_process_wd(self, "output1.txt") self.expect( output, @@ -296,8 +280,10 @@ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Set the error-path and output-path and verify both are set. - self.runCmd("settings set target.error-path stderr.txt") - self.runCmd("settings set target.output-path stdout.txt") + self.runCmd("settings set target.error-path '{0}'".format( + lldbutil.append_to_process_working_directory(self, "stderr.txt"))) + self.runCmd("settings set target.output-path '{0}".format( + lldbutil.append_to_process_working_directory(self, "stdout.txt"))) # And add hooks to restore the original settings during tearDown(). self.addTearDownHook( lambda: self.runCmd("settings clear target.output-path")) @@ -306,44 +292,26 @@ self.expect("settings show target.error-path", SETTING_MSG("target.error-path"), - substrs=['target.error-path (file) = "stderr.txt"']) + substrs=['target.error-path (file)', 'stderr.txt"']) self.expect("settings show target.output-path", SETTING_MSG("target.output-path"), - substrs=['target.output-path (file) = "stdout.txt"']) - - self.runCmd("run", RUN_SUCCEEDED) - - if lldb.remote_platform: - self.runCmd('platform get-file "stderr.txt" "stderr.txt"') - self.runCmd('platform get-file "stdout.txt" "stdout.txt"') - - # The 'stderr.txt' file should now exist. - self.assertTrue(os.path.isfile("stderr.txt"), - "'stderr.txt' exists due to target.error-path.") + substrs=['target.output-path (file)', 'stdout.txt"']) - # Read the output file produced by running the program. - with open('stderr.txt', 'r') as f: - output = f.read() + self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), + RUN_SUCCEEDED) + output = lldbutil.read_file_from_process_wd(self, "stderr.txt") message = "This message should go to standard error." if lldbplatformutil.hasChattyStderr(self): self.expect(output, exe=False, substrs=[message]) else: self.expect(output, exe=False, startstr=message) - # The 'stdout.txt' file should now exist. - self.assertTrue(os.path.isfile("stdout.txt"), - "'stdout.txt' exists due to target.output-path.") - - # Read the output file produced by running the program. - with open('stdout.txt', 'r') as f: - output = f.read() - + output = lldbutil.read_file_from_process_wd(self, "stdout.txt") self.expect(output, exe=False, startstr="This message should go to standard out.") - @no_debug_info_test def test_print_dictionary_setting(self): self.runCmd("settings clear target.env-vars") self.runCmd("settings set target.env-vars [\"MY_VAR\"]=some-value") @@ -351,7 +319,6 @@ substrs=["MY_VAR=some-value"]) self.runCmd("settings clear target.env-vars") - @no_debug_info_test def test_print_array_setting(self): self.runCmd("settings clear target.run-args") self.runCmd("settings set target.run-args gobbledy-gook") @@ -359,7 +326,6 @@ substrs=['[0]: "gobbledy-gook"']) self.runCmd("settings clear target.run-args") - @no_debug_info_test def test_settings_with_quotes(self): self.runCmd("settings clear target.run-args") self.runCmd("settings set target.run-args a b c") @@ -392,7 +358,6 @@ 'thread-format (format-string) = "abc def "') self.runCmd('settings clear thread-format') - @no_debug_info_test def test_settings_with_trailing_whitespace(self): # boolean @@ -517,7 +482,6 @@ substrs=['disassembly-format (format-string) = "foo "']) self.runCmd("settings clear disassembly-format", check=False) - @no_debug_info_test def test_all_settings_exist(self): self.expect("settings show", substrs=["auto-confirm", Index: lldb/trunk/packages/Python/lldbsuite/test/terminal/TestSTTYBeforeAndAfter.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/terminal/TestSTTYBeforeAndAfter.py +++ lldb/trunk/packages/Python/lldbsuite/test/terminal/TestSTTYBeforeAndAfter.py @@ -7,6 +7,7 @@ import os import lldb +import six from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil @@ -58,13 +59,10 @@ child.expect(expect_prompt) # Turn on loggings for input/output to/from the child. - with open('child_send1.txt', 'w') as f_send1: - with open('child_read1.txt', 'w') as f_read1: - child.logfile_send = f_send1 - child.logfile_read = f_read1 - - child.sendline('stty -a') - child.expect(expect_prompt) + child.logfile_send = child_send1 = six.StringIO() + child.logfile_read = child_read1 = six.StringIO() + child.sendline('stty -a') + child.expect(expect_prompt) # Now that the stage1 logging is done, restore logfile to None to # stop further logging. @@ -79,43 +77,30 @@ child.sendline('quit') child.expect(expect_prompt) - with open('child_send2.txt', 'w') as f_send2: - with open('child_read2.txt', 'w') as f_read2: - child.logfile_send = f_send2 - child.logfile_read = f_read2 - - child.sendline('stty -a') - child.expect(expect_prompt) + child.logfile_send = child_send2 = six.StringIO() + child.logfile_read = child_read2 = six.StringIO() + child.sendline('stty -a') + child.expect(expect_prompt) - child.sendline('exit') + child.sendline('exit') # Now that the stage2 logging is done, restore logfile to None to # stop further logging. child.logfile_send = None child.logfile_read = None - with open('child_send1.txt', 'r') as fs: - if self.TraceOn(): - print("\n\nContents of child_send1.txt:") - print(fs.read()) - with open('child_read1.txt', 'r') as fr: - from_child1 = fr.read() - if self.TraceOn(): - print("\n\nContents of child_read1.txt:") - print(from_child1) - - with open('child_send2.txt', 'r') as fs: - if self.TraceOn(): - print("\n\nContents of child_send2.txt:") - print(fs.read()) - with open('child_read2.txt', 'r') as fr: - from_child2 = fr.read() - if self.TraceOn(): - print("\n\nContents of child_read2.txt:") - print(from_child2) + if self.TraceOn(): + print("\n\nContents of child_send1:") + print(child_send1.getvalue()) + print("\n\nContents of child_read1:") + print(child_read1.getvalue()) + print("\n\nContents of child_send2:") + print(child_send2.getvalue()) + print("\n\nContents of child_read2:") + print(child_read2.getvalue()) - stty_output1_lines = from_child1.splitlines() - stty_output2_lines = from_child2.splitlines() + stty_output1_lines = child_read1.getvalue().splitlines() + stty_output2_lines = child_read2.getvalue().splitlines() zipped = list(zip(stty_output1_lines, stty_output2_lines)) for tuple in zipped: if self.TraceOn(): Index: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiFile.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiFile.py +++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/TestMiFile.py @@ -59,7 +59,7 @@ # Test that -file-exec-and-symbols works for relative path import os - path = os.path.relpath(self.myexe) + path = os.path.relpath(self.myexe, self.getBuildDir()) self.runCmd("-file-exec-and-symbols %s" % path) self.expect("\^done") Index: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/lldbmi_testcase.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/lldbmi_testcase.py +++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/lldbmi_testcase.py @@ -44,7 +44,7 @@ def spawnLldbMi(self, args=None): import pexpect self.child = pexpect.spawn("%s --interpreter %s" % ( - self.lldbMiExec, args if args else "")) + self.lldbMiExec, args if args else ""), cwd=self.getBuildDir()) self.child.setecho(True) self.mylog = self.getBuildArtifact("child.log") self.child.logfile_read = open(self.mylog, "w") Index: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/startup_options/TestMiStartupOptions.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/startup_options/TestMiStartupOptions.py +++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/startup_options/TestMiStartupOptions.py @@ -94,7 +94,7 @@ """Test that 'lldb-mi --interpreter %s' loads executable which is specified via relative path.""" # Prepare path to executable - path = os.path.relpath(self.myexe) + path = os.path.relpath(self.myexe, self.getBuildDir()) self.spawnLldbMi(args="%s" % path) # Test that the executable is loaded when file was specified using @@ -258,7 +258,7 @@ def test_lldbmi_log_option(self): """Test that 'lldb-mi --log' creates a log file in the current directory.""" - logDirectory = "." + logDirectory = self.getBuildDir() self.spawnLldbMi(args="%s --log" % self.myexe) # Test that the executable is loaded when file was specified Index: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/syntax/TestMiSyntax.py =================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/syntax/TestMiSyntax.py +++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-mi/syntax/TestMiSyntax.py @@ -47,7 +47,7 @@ """Test that 'lldb-mi --interpreter' handles complicated strings.""" # Create an alias for myexe - complicated_myexe = "C--mpl-x file's`s @#$%^&*()_+-={}[]| name" + complicated_myexe = self.getBuildArtifact("C--mpl-x file's`s @#$%^&*()_+-={}[]| name") os.symlink(self.myexe, complicated_myexe) self.addTearDownHook(lambda: os.unlink(complicated_myexe))