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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
# TestExprInProtocolExtension.py
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ------------------------------------------------------------------------------
"""
Tests scoped variables with swift expressions
"""
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import os
import unittest2
class TestSwiftExprInProtocolExtension(TestBase):
def continue_to_bkpt(self, process, bkpt):
threads = lldbutil.continue_to_breakpoint(process, bkpt)
self.assertTrue(len(threads) == 1)
def continue_by_pattern(self, pattern):
bkpt = self.target.BreakpointCreateBySourceRegex(
pattern, self.main_source_spec)
self.assertTrue(bkpt.GetNumLocations() > 0, VALID_BREAKPOINT)
self.continue_to_bkpt(self.process, bkpt)
self.target.BreakpointDelete(bkpt.GetID())
@swiftTest
def test_protocol_extension(self):
"""Tests that swift expressions in protocol extension functions behave correctly"""
self.build()
# Create the target
target = self.dbg.CreateTarget(self.getBuildArtifact())
self.target = target
self.assertTrue(target, VALID_TARGET)
# Set the breakpoints
static_bkpt = target.BreakpointCreateBySourceRegex(
'break here in static func', lldb.SBFileSpec('main.swift'))
self.assertTrue(static_bkpt.GetNumLocations() > 0, VALID_BREAKPOINT)
method_bkpt = target.BreakpointCreateBySourceRegex(
'break here in method', lldb.SBFileSpec('main.swift'))
self.assertTrue(method_bkpt.GetNumLocations() > 0, VALID_BREAKPOINT)
# Launch the process, and do not stop at the entry point.
process = target.LaunchSimple(None, None, os.getcwd())
self.process = process
self.assertTrue(process, PROCESS_IS_VALID)
# Frame #0 should be at our breakpoint.
threads = lldbutil.get_threads_stopped_at_breakpoint(
process, method_bkpt)
self.assertTrue(len(threads) == 1)
# Check that we can evaluate expressions correctly in the struct
# method.
lldbutil.check_expression(self, self.frame(), "self.x", "10", False)
lldbutil.check_expression(self, self.frame(), "self.y", '"Hello world"', True)
lldbutil.check_expression(self, self.frame(), "local_var", "111", False)
# And check that we got the type of self right:
self_var = self.frame().EvaluateExpression(
"self", lldb.eDynamicCanRunTarget)
self_type_name = self_var.GetTypeName()
print("Self type name is: ", self_type_name)
# Not checking yet since we don't get this right.
# Now continue to the static method and check things there:
self.continue_to_bkpt(process, static_bkpt)
lldbutil.check_expression(self, self.frame(), "self.cvar", "333", False)
lldbutil.check_expression(self, self.frame(), "local_var", "222", False)
# This continues to the class version:
self.continue_to_bkpt(process, method_bkpt)
# Check that we can evaluate expressions correctly in the struct
# method.
lldbutil.check_expression(self, self.frame(), "self.x", "10", False)
lldbutil.check_expression(self, self.frame(), "self.y", '"Hello world"', True)
lldbutil.check_expression(self, self.frame(), "local_var", "111", False)
# And check that we got the type of self right:
self_var = self.frame().EvaluateExpression(
"self", lldb.eDynamicCanRunTarget)
self_type_name = self_var.GetTypeName()
print("Self type name is: ", self_type_name)
# Not checking yet since we don't get this right.
# Now continue to the static method and check things there:
self.continue_to_bkpt(process, static_bkpt)
lldbutil.check_expression(self, self.frame(), "self.cvar", "333", False)
lldbutil.check_expression(self, self.frame(), "local_var", "222", False)
# This continues to the enum version:
self.continue_to_bkpt(process, method_bkpt)
# Check that we can evaluate expressions correctly in the struct
# method.
lldbutil.check_expression(self, self.frame(), "self.x", "10", False)
lldbutil.check_expression(self, self.frame(), "self.y", '"Hello world"', True)
lldbutil.check_expression(self, self.frame(), "local_var", "111", False)
# And check that we got the type of self right:
self_var = self.frame().EvaluateExpression(
"self", lldb.eDynamicCanRunTarget)
self_type_name = self_var.GetTypeName()
print("Self type name is: ", self_type_name)
# Not checking yet since we don't get this right.
# Now continue to the static method and check things there:
self.continue_to_bkpt(process, static_bkpt)
lldbutil.check_expression(self, self.frame(), "self.cvar", "333", False)
lldbutil.check_expression(self, self.frame(), "local_var", "222", False)
|