1""" 2Test lldb command aliases. 3""" 4 5from __future__ import print_function 6 7 8import unittest2 9import os 10import lldb 11from lldbsuite.test.decorators import * 12from lldbsuite.test.lldbtest import * 13from lldbsuite.test import lldbutil 14 15 16class LaunchInTerminalTestCase(TestBase): 17 18 mydir = TestBase.compute_mydir(__file__) 19 20 # Darwin is the only platform that I know of that supports optionally launching 21 # a program in a separate terminal window. It would be great if other platforms 22 # added support for this. 23 @skipUnlessDarwin 24 # If the test is being run under sudo, the spawned terminal won't retain that elevated 25 # privilege so it can't open the socket to talk back to the test case 26 @unittest2.skipIf(hasattr(os, 'geteuid') and os.geteuid() 27 == 0, "test cannot be run as root") 28 # Do we need to disable this test if the testsuite is being run on a remote system? 29 # This env var is only defined when the shell is running in a local mac 30 # terminal window 31 @unittest2.skipUnless( 32 'TERM_PROGRAM' in os.environ, 33 "test must be run on local system") 34 @no_debug_info_test 35 def test_launch_in_terminal(self): 36 self.build() 37 exe = self.getBuildArtifact("a.out") 38 39 target = self.dbg.CreateTarget(exe) 40 launch_info = lldb.SBLaunchInfo(["-lAF", "/tmp/"]) 41 launch_info.SetLaunchFlags( 42 lldb.eLaunchFlagLaunchInTTY | lldb.eLaunchFlagCloseTTYOnExit) 43 error = lldb.SBError() 44 process = target.Launch(launch_info, error) 45 print("Error was: %s."%(error.GetCString())) 46 self.assertTrue( 47 error.Success(), 48 "Make sure launch happened successfully in a terminal window") 49 # Running in synchronous mode our process should have run and already 50 # exited by the time target.Launch() returns 51 self.assertEqual(process.GetState(), lldb.eStateExited) 52