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