File: TestSwiftCPPExceptionsInREPL.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 (78 lines) | stat: -rw-r--r-- 3,159 bytes parent folder | download
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
"""
Make sure we don't trap exceptions with SetREPLEnabled(true) or "lldb --repl"
"""

from __future__ import print_function


import os
import time
import re
import subprocess
import lldb
import swift
import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *


class TestSwiftREPLExceptions(TestBase):

    # If your test case doesn't stress debug info, the 
    # set this to true.  That way it won't be run once for
    # each debug info format.
    NO_DEBUG_INFO_TESTCASE = True

    @skipUnlessDarwin
    @swiftTest
    def DISABLED_test_set_repl_mode_exceptions(self):
        """ Test that SetREPLMode turns off trapping exceptions."""
        self.build()
        self.main_source_file = lldb.SBFileSpec("main.swift")
        self.do_repl_mode_test()

    @skipUnlessDarwin
    @swiftTest
    def test_repl_exceptions(self):
        """ Test the lldb --repl turns off trapping exceptions."""
        self.build()
        self.do_repl_test()

    @skipIfRemote
    def do_repl_test(self):
        sdk_root = ""
        with open(self.getBuildArtifact("sdkroot.txt"), 'r') as f:
            sdk_root = f.readlines()[0]
        self.assertGreater(len(sdk_root), 0)
        if sdk_root[-1] == '\n':
            sdk_root = sdk_root[:-1]
        build_dir = self.getBuildDir()
        repl_args = [lldbtest_config.lldbExec, "-x", "--repl=-enable-objc-interop -sdk %s -L%s -I%s"%(sdk_root, build_dir, build_dir)]
        repl_proc = subprocess.Popen(repl_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=build_dir)
        input_str = "import Wrapper\ncall_cpp()\n:quit"
        (stdoutdata, stderrdata) = repl_proc.communicate(input=input_str.encode())
        stdoutdata = stdoutdata.decode("utf-8") if stdoutdata else None
        stderrdata = stderrdata.decode("utf-8") if stderrdata else None
        self.assertTrue("I called it successfully" in stdoutdata, "Didn't call call_cpp successfully: out: \n%s\nerr: %s"%(stdoutdata, stderrdata))
        
    def do_repl_mode_test(self):
        target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
        self.assertTrue(target, VALID_TARGET)
        self.registerSharedLibrariesWithTarget(target, ['Wrapper'])

        if lldb.remote_platform:
            wd = lldb.remote_platform.GetWorkingDirectory()
            filename = 'libCppLib.dylib'
            err = lldb.remote_platform.Put(
                lldb.SBFileSpec(self.getBuildArtifact(filename)),
                lldb.SBFileSpec(os.path.join(wd, filename)))
            self.assertFalse(err.Fail(), 'Failed to copy ' + filename)
        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
                                   "Set a breakpoint here", self.main_source_file)

        frame = thread.GetFrameAtIndex(0)
        options = lldb.SBExpressionOptions()
        options.SetREPLMode(True)
        val = frame.EvaluateExpression("call_cpp(); 5", options)
        self.assertSuccess(val.GetError(), "Got an error evaluating expression")
        self.assertEqual(val.GetValueAsUnsigned(), 5,"The expression didn't return the correct result")