Files
clang-p2996/lldb/test/API/tools/lldb-server/test/test_lldbgdbserverutils.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

60 lines
2.1 KiB
Python

import unittest
import re
from lldbgdbserverutils import *
class TestLldbGdbServerUtils(unittest.TestCase):
def test_entry_exact_payload_match(self):
entry = GdbRemoteEntry(is_send_to_remote=False, exact_payload="$OK#9a")
entry.assert_match(self, "$OK#9a")
def test_entry_exact_payload_match_ignores_checksum(self):
entry = GdbRemoteEntry(is_send_to_remote=False, exact_payload="$OK#9a")
entry.assert_match(self, "$OK#00")
def test_entry_creates_context(self):
entry = GdbRemoteEntry(is_send_to_remote=False, exact_payload="$OK#9a")
context = entry.assert_match(self, "$OK#9a")
self.assertIsNotNone(context)
def test_entry_regex_matches(self):
entry = GdbRemoteEntry(
is_send_to_remote=False,
regex=re.compile(r"^\$QC([0-9a-fA-F]+)#"),
capture={1: "thread_id"},
)
context = entry.assert_match(self, "$QC980#00")
def test_entry_regex_saves_match(self):
entry = GdbRemoteEntry(
is_send_to_remote=False,
regex=re.compile(r"^\$QC([0-9a-fA-F]+)#"),
capture={1: "thread_id"},
)
context = entry.assert_match(self, "$QC980#00")
self.assertEqual(context["thread_id"], "980")
def test_entry_regex_expect_captures_success(self):
context = {"thread_id": "980"}
entry = GdbRemoteEntry(
is_send_to_remote=False,
regex=re.compile(r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+)"),
expect_captures={2: "thread_id"},
)
entry.assert_match(self, "$T11thread:980;", context=context)
def test_entry_regex_expect_captures_raises_on_fail(self):
context = {"thread_id": "980"}
entry = GdbRemoteEntry(
is_send_to_remote=False,
regex=re.compile(r"^\$T([0-9a-fA-F]{2})thread:([0-9a-fA-F]+)"),
expect_captures={2: "thread_id"},
)
try:
entry.assert_match(self, "$T11thread:970;", context=context)
self.fail()
except AssertionError:
# okay
return None