Files
clang-p2996/lldb/test/API/functionalities/tty/TestTerminal.py
Jordan Rupprecht 5b386158aa [lldb][test] Switch LLDB API tests from vendored unittest2 to unittest (#79945)
This removes the dependency LLDB API tests have on
lldb/third_party/Python/module/unittest2, and instead uses the standard
one provided by Python.

This does not actually remove the vendored dep yet, nor update the docs.
I'll do both those once this sticks.

Non-trivial changes to call out:
- expected failures (i.e. "bugnumber") don't have a reason anymore, so
those params were removed
- `assertItemsEqual` is now called `assertCountEqual`
- When a test is marked xfail, our copy of unittest2 considers failures
during teardown to be OK, but modern unittest does not. See
TestThreadLocal.py. (Very likely could be a real bug/leak).
- Our copy of unittest2 was patched to print all test results, even ones
that don't happen, e.g. `(5 passes, 0 failures, 1 errors, 0 skipped,
...)`, but standard unittest prints a terser message that omits test
result types that didn't happen, e.g. `OK (skipped=1)`. Our lit
integration parses this stderr and needs to be updated w/ that
expectation.

I tested this w/ `ninja check-lldb-api` on Linux. There's a good chance
non-Linux tests have similar quirks, but I'm not able to uncover those.
2024-02-13 16:19:41 -06:00

49 lines
1.8 KiB
Python

"""
Test lldb command aliases.
"""
import unittest
import os
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
class LaunchInTerminalTestCase(TestBase):
# Darwin is the only platform that I know of that supports optionally launching
# a program in a separate terminal window. It would be great if other platforms
# added support for this.
@skipUnlessDarwin
# If the test is being run under sudo, the spawned terminal won't retain that elevated
# privilege so it can't open the socket to talk back to the test case
@unittest.skipIf(
hasattr(os, "geteuid") and os.geteuid() == 0, "test cannot be run as root"
)
# Do we need to disable this test if the testsuite is being run on a remote system?
# This env var is only defined when the shell is running in a local mac
# terminal window
@unittest.skipUnless(
"TERM_PROGRAM" in os.environ, "test must be run on local system"
)
@no_debug_info_test
def test_launch_in_terminal(self):
self.build()
exe = self.getBuildArtifact("a.out")
target = self.dbg.CreateTarget(exe)
launch_info = lldb.SBLaunchInfo(["-lAF", "/tmp/"])
launch_info.SetLaunchFlags(
lldb.eLaunchFlagLaunchInTTY | lldb.eLaunchFlagCloseTTYOnExit
)
error = lldb.SBError()
process = target.Launch(launch_info, error)
print("Error was: %s." % (error.GetCString()))
self.assertTrue(
error.Success(),
"Make sure launch happened successfully in a terminal window",
)
# Running in synchronous mode our process should have run and already
# exited by the time target.Launch() returns
self.assertState(process.GetState(), lldb.eStateExited)