AbstractBase.py revision 51a9e00e10d29ba01af7bc2d5efbcf31ec1f76a4
10b3ee55c77954ce4359499af2a0c27f1f75c10f1Johnny Chen""" 27c52ff1d83ec262f35c9a825af107735913e7225Johnny ChenAbstract base class of basic types provides a generic type tester method. 30b3ee55c77954ce4359499af2a0c27f1f75c10f1Johnny Chen""" 40b3ee55c77954ce4359499af2a0c27f1f75c10f1Johnny Chen 50b3ee55c77954ce4359499af2a0c27f1f75c10f1Johnny Chenimport os, time 6091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chenimport re 70b3ee55c77954ce4359499af2a0c27f1f75c10f1Johnny Chenimport lldb 80b3ee55c77954ce4359499af2a0c27f1f75c10f1Johnny Chenfrom lldbtest import * 90b3ee55c77954ce4359499af2a0c27f1f75c10f1Johnny Chen 10091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chendef Msg(var, val): 11091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen return "'frame variable %s' matches the compiler's output: %s" % (var, val) 12091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen 1351a9e00e10d29ba01af7bc2d5efbcf31ec1f76a4Johnny Chenclass GenericTester(TestBase): 140b3ee55c77954ce4359499af2a0c27f1f75c10f1Johnny Chen 15091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # This is the pattern by design to match the " var = 'value'" output from 16091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # printf() stmts (see basic_type.cpp). 17091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen pattern = re.compile(" (\*?a[^=]*) = '([^=]*)'$") 18091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen 198ba13e6dda85f15dcd83f14d32edbbd99eed2405Johnny Chen def generic_type_tester(self, atoms, quotedDisplay=False): 20091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen """Test that variables with basic types are displayed correctly.""" 21091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen 22091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # First, capture the golden output emitted by the oracle, i.e., the 23091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # series of printf statements. 24091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen go = system("./a.out") 25091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # This golden list contains a list of (variable, value) pairs extracted 26091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # from the golden output. 27091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen gl = [] 280b3ee55c77954ce4359499af2a0c27f1f75c10f1Johnny Chen 29091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # Scan the golden output line by line, looking for the pattern: 30091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # 31091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # variable = 'value' 32091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # 33091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # Filter out the following lines, for the time being: 34091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # 35091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # 'a_ref = ...' 36091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # 'a_class_ref.m_a = ...' 37091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # 'a_class_ref.m_b = ...' 38091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # 'a_struct_ref.a = ...' 39091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # 'a_struct_ref.b = ...' 40091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # 'a_union_zero_ref.a = ...' 41091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # 'a_union_nonzero_ref.u.a = ...' 42091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # 43091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # rdar://problem/8471016 frame variable a_ref should display the referenced value as well 44091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # rdar://problem/8470987 frame variable a_class_ref.m_a does not work 45091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen notnow = set(['a_ref', 46091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen 'a_class_ref.m_a', 'a_class_ref.m_b', 47091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen 'a_struct_ref.a', 'a_struct_ref.b', 48091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen 'a_union_zero_ref.a', 'a_union_nonzero_ref.u.a']) 49091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen for line in go.split(os.linesep): 50091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen match = self.pattern.search(line) 51091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen if match: 52091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen var, val = match.group(1), match.group(2) 53091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen if var in notnow: 54091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen continue 55091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen gl.append((var, val)) 56091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen #print "golden list:", gl 57091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen 58091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # Bring the program to the point where we can issue a series of 59091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # 'frame variable' command. 60091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) 61091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen self.runCmd("breakpoint set --name Puts") 62091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen self.runCmd("run", RUN_SUCCEEDED) 630b3ee55c77954ce4359499af2a0c27f1f75c10f1Johnny Chen self.runCmd("thread step-out", STEP_OUT_SUCCEEDED) 640b3ee55c77954ce4359499af2a0c27f1f75c10f1Johnny Chen 6555e16329fc1ef032feddf1df0e94f11547ebcc66Johnny Chen #self.runCmd("frame variable") 664ec97859ca68e299b5b2beb0313fffeea9d0119eJohnny Chen 67091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # Now iterate through the golden list, comparing against the output from 68091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen # 'frame variable var'. 69091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen for var, val in gl: 70091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen self.runCmd("frame variable %s" % var) 71091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen output = self.res.GetOutput() 72757396a950315670e3400b97b51a081a8dcb4fc3Johnny Chen 738ba13e6dda85f15dcd83f14d32edbbd99eed2405Johnny Chen # The input type is in a canonical form as a set named atoms. 748ba13e6dda85f15dcd83f14d32edbbd99eed2405Johnny Chen # The display type string must conatin each and every element. 75757396a950315670e3400b97b51a081a8dcb4fc3Johnny Chen dt = re.match("^\((.*)\)", output).group(1) 76757396a950315670e3400b97b51a081a8dcb4fc3Johnny Chen 778ba13e6dda85f15dcd83f14d32edbbd99eed2405Johnny Chen # Expect the display type string to contain each and every atoms. 788ba13e6dda85f15dcd83f14d32edbbd99eed2405Johnny Chen self.expect(dt, 798ba13e6dda85f15dcd83f14d32edbbd99eed2405Johnny Chen "Display type: '%s' must contain the type atoms: '%s'" % 808ba13e6dda85f15dcd83f14d32edbbd99eed2405Johnny Chen (dt, atoms), 818ba13e6dda85f15dcd83f14d32edbbd99eed2405Johnny Chen exe=False, 828ba13e6dda85f15dcd83f14d32edbbd99eed2405Johnny Chen substrs = list(atoms)) 83757396a950315670e3400b97b51a081a8dcb4fc3Johnny Chen 84757396a950315670e3400b97b51a081a8dcb4fc3Johnny Chen # The (var, val) pair must match, too. 854ec97859ca68e299b5b2beb0313fffeea9d0119eJohnny Chen nv = (" %s = '%s'" if quotedDisplay else " %s = %s") % (var, val) 86091bb1de9d5cd0f974b91da621e638a22f5b03b5Johnny Chen self.expect(output, Msg(var, val), exe=False, 874ec97859ca68e299b5b2beb0313fffeea9d0119eJohnny Chen substrs = [nv]) 88