2010-09-08 01:06:13 +08:00
|
|
|
"""
|
|
|
|
Test lldb settings command.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os, time
|
|
|
|
import unittest2
|
|
|
|
import lldb
|
|
|
|
from lldbtest import *
|
|
|
|
|
|
|
|
class SettingsCommandTestCase(TestBase):
|
|
|
|
|
|
|
|
mydir = "settings"
|
|
|
|
|
2010-09-16 09:53:04 +08:00
|
|
|
@classmethod
|
|
|
|
def classCleanup(cls):
|
|
|
|
system(["/bin/sh", "-c", "rm output.txt"])
|
2010-09-17 02:26:06 +08:00
|
|
|
#system(["/bin/sh", "-c", "rm stdout.txt"])
|
2010-09-16 09:53:04 +08:00
|
|
|
|
2010-09-08 01:06:13 +08:00
|
|
|
def test_set_prompt(self):
|
|
|
|
"""Test that 'set prompt' actually changes the prompt."""
|
2010-09-08 01:12:10 +08:00
|
|
|
|
|
|
|
# Use '-o' option to override the existing instance setting.
|
2010-09-08 01:06:13 +08:00
|
|
|
self.runCmd("settings set -o prompt 'lldb2'")
|
2010-09-08 01:12:10 +08:00
|
|
|
|
|
|
|
# Immediately test the setting.
|
2010-09-08 01:06:13 +08:00
|
|
|
self.expect("settings show prompt",
|
|
|
|
startstr = "prompt (string) = 'lldb2'")
|
2010-09-08 01:12:10 +08:00
|
|
|
|
|
|
|
# The overall display should also reflect the new setting.
|
2010-09-08 01:06:13 +08:00
|
|
|
self.expect("settings show",
|
|
|
|
substrs = ["prompt (string) = 'lldb2'"])
|
|
|
|
|
2010-09-08 01:31:05 +08:00
|
|
|
def test_set_term_width(self):
|
|
|
|
"""Test that 'set term-width' actually changes the term-width."""
|
|
|
|
|
|
|
|
# No '-o' option is needed for static setting.
|
|
|
|
self.runCmd("settings set term-width 70")
|
|
|
|
|
|
|
|
# Immediately test the setting.
|
|
|
|
self.expect("settings show term-width",
|
|
|
|
startstr = "term-width (int) = '70'")
|
|
|
|
|
|
|
|
# The overall display should also reflect the new setting.
|
|
|
|
self.expect("settings show",
|
2010-09-08 02:55:50 +08:00
|
|
|
startstr = "term-width (int) = '70'")
|
2010-09-08 01:31:05 +08:00
|
|
|
|
2010-09-16 06:27:29 +08:00
|
|
|
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
|
|
|
|
def test_with_dsym(self):
|
|
|
|
"""Test that run-args and env-vars are passed to the launched process."""
|
|
|
|
self.buildDsym()
|
|
|
|
self.pass_run_args_and_env_vars()
|
|
|
|
|
|
|
|
def test_with_dwarf(self):
|
|
|
|
"""Test that run-args and env-vars are passed to the launched process."""
|
|
|
|
self.buildDwarf()
|
|
|
|
self.pass_run_args_and_env_vars()
|
|
|
|
|
|
|
|
def pass_run_args_and_env_vars(self):
|
|
|
|
"""Test that run-args and env-vars are passed to the launched process."""
|
|
|
|
exe = os.path.join(os.getcwd(), "a.out")
|
|
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
|
|
|
|
# Set the run-args and the env-vars.
|
2010-09-21 04:44:43 +08:00
|
|
|
self.runCmd('settings set target.process.run-args A B C')
|
|
|
|
self.runCmd('settings set target.process.env-vars ["MY_ENV_VAR"]=YES')
|
2010-09-16 06:27:29 +08:00
|
|
|
|
|
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
|
|
|
|
# Read the output file produced by running the program.
|
2010-09-16 09:53:04 +08:00
|
|
|
output = open('output.txt', 'r').read()
|
2010-09-16 06:27:29 +08:00
|
|
|
|
|
|
|
self.assertTrue(output.startswith("argv[1] matches") and
|
|
|
|
output.find("argv[2] matches") > 0 and
|
|
|
|
output.find("argv[3] matches") > 0 and
|
|
|
|
output.find("Environment variable 'MY_ENV_VAR' successfully passed.") > 0)
|
|
|
|
|
2010-09-17 02:26:06 +08:00
|
|
|
@unittest2.expectedFailure
|
|
|
|
# rdar://problem/8435794
|
2010-09-21 04:44:43 +08:00
|
|
|
# settings set target.process.output-path does not seem to work
|
2010-09-17 02:26:06 +08:00
|
|
|
def test_set_output_path(self):
|
2010-09-21 04:44:43 +08:00
|
|
|
"""Test that setting target.process.output-path for the launched process works."""
|
2010-09-17 02:26:06 +08:00
|
|
|
self.buildDefault()
|
|
|
|
|
|
|
|
exe = os.path.join(os.getcwd(), "a.out")
|
|
|
|
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
|
|
|
|
|
|
|
|
# Set the output-path and verify it is set.
|
2010-09-21 04:44:43 +08:00
|
|
|
self.runCmd("settings set target.process.output-path 'stdout.txt'")
|
|
|
|
self.expect("settings show target.process.output-path",
|
|
|
|
startstr = "target.process.output-path (string) = 'stdout.txt'")
|
2010-09-17 02:26:06 +08:00
|
|
|
|
|
|
|
self.runCmd("run", RUN_SUCCEEDED)
|
|
|
|
|
|
|
|
# Read the output file produced by running the program.
|
|
|
|
output = open('stdout.txt', 'r').read()
|
|
|
|
|
|
|
|
self.assertTrue(
|
|
|
|
output.startswith("This message should go to standard out."))
|
|
|
|
|
2010-09-08 01:06:13 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import atexit
|
|
|
|
lldb.SBDebugger.Initialize()
|
|
|
|
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
|
|
|
unittest2.main()
|