File: TestObjCRecognizer.py

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (83 lines) | stat: -rw-r--r-- 3,290 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
Test that the built in ObjC exception throw recognizer works
"""

import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.lldbtest import *


class TestObjCRecognizer(TestBase):
    NO_DEBUG_INFO_TESTCASE = True

    @skipUnlessDarwin
    def test_exception_recognizer_sub_class(self):
        """There can be many tests in a test case - describe this test here."""
        self.build()
        self.main_source_file = lldb.SBFileSpec("main.m")
        self.objc_recognizer_test(True)

    @skipUnlessDarwin
    def test_exception_recognizer_plain(self):
        """There can be many tests in a test case - describe this test here."""
        self.build()
        self.main_source_file = lldb.SBFileSpec("main.m")
        self.objc_recognizer_test(False)

    def objc_recognizer_test(self, sub_class):
        """Make sure we stop at the exception and get all the fields out of the recognizer.
        If sub_class is True, we make a subclass of NSException and throw that."""
        if sub_class:
            bkpt_string = "Set a breakpoint here for MyException"
        else:
            bkpt_string = "Set a breakpoint here for plain exception"

        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
            self, bkpt_string, self.main_source_file
        )

        # Now turn on the ObjC Exception breakpoint and continue to hit it:
        exception_bkpt = target.BreakpointCreateForException(
            lldb.eLanguageTypeObjC, False, True
        )
        self.assertTrue(
            exception_bkpt.GetNumLocations() > 0, "Got some exception locations"
        )

        threads = lldbutil.continue_to_breakpoint(process, exception_bkpt)
        self.assertEqual(len(threads), 1, "One thread hit exception breakpoint")
        frame = threads[0].frame[0]

        var_opts = lldb.SBVariablesOptions()
        var_opts.SetIncludeRecognizedArguments(True)
        var_opts.SetUseDynamic(True)
        vars = frame.GetVariables(var_opts)
        self.assertEqual(len(vars), 1, "Got the synthetic argument")
        self.assertTrue(vars[0].IsValid(), "Got a valid Exception variable")

        # This will be a pointer

        ns_exception_children = [
            ValueCheck(type="NSObject"),
            ValueCheck(name="name", summary='"NSException"'),
            ValueCheck(name="reason", summary='"Simple Reason"'),
            ValueCheck(name="userInfo"),
            ValueCheck(name="reserved"),
        ]
        ns_exception = ValueCheck(type="NSException", children=ns_exception_children)
        if not sub_class:
            simple_check = ValueCheck(name="exception", dereference=ns_exception)
            simple_check.check_value(self, vars[0], "Simple exception is right")
        else:
            my_exception_children = [
                ns_exception,
                ValueCheck(name="extra_info", type="int", value="100"),
            ]
            my_exception = ValueCheck(
                type="MyException", children=my_exception_children
            )
            sub_check = ValueCheck(
                name="exception", type="MyException *", dereference=my_exception
            )
            sub_check.check_value(self, vars[0], "Subclass exception is right")