def check_computegcmaptable(format, path): print print path.basename lines = path.readlines() expectedlines = lines[:] tracker = FunctionGcRootTracker(lines, format=format) table = tracker.computegcmaptable(verbose=sys.maxint) tabledict = {} seen = {} for entry in table: print '%s: %s' % (entry[0], format_callshape(entry[1])) tabledict[entry[0]] = entry[1] # find the ";; expected" lines prevline = "" for i, line in enumerate(lines): match = r_expected.match(line) if match: expected = match.group(1) prevmatch = r_globallabel.match(prevline) assert prevmatch, "the computed table is not complete" label = prevmatch.group(1) assert label in tabledict got = tabledict[label] assert format_callshape(got) == expected seen[label] = True expectedlines.insert(i - 2, '\t.globl\t%s\n' % (label, )) expectedlines.insert(i - 1, '%s=.+%d\n' % (label, OFFSET_LABELS)) prevline = line assert len(seen) == len(tabledict), ( "computed table contains unexpected entries:\n%r" % [key for key in tabledict if key not in seen]) assert lines == expectedlines
def check_computegcmaptable(path): print print path.basename lines = path.readlines() expectedlines = lines[:] tracker = FunctionGcRootTracker(lines) table = tracker.computegcmaptable(verbose=sys.maxint) tabledict = {} seen = {} for entry in table: print '%s: %s' % (entry[0], format_callshape(entry[1])) tabledict[entry[0]] = entry[1] # find the ";; expected" lines prevline = "" for i, line in enumerate(lines): match = r_expected.match(line) if match: expected = match.group(1) prevmatch = r_globallabel.match(prevline) assert prevmatch, "the computed table is not complete" label = prevmatch.group(1) assert label in tabledict got = tabledict[label] assert format_callshape(got) == expected seen[label] = True expectedlines.insert(i-2, '\t.globl\t%s\n' % (label,)) expectedlines.insert(i-1, '%s:\n' % (label,)) prevline = line assert len(seen) == len(tabledict), ( "computed table contains unexpected entries:\n%r" % [key for key in tabledict if key not in seen]) assert lines == expectedlines
def check_computegcmaptable(format, path): if format == 'msvc': r_globallabel = re.compile(r"([\w]+)::") else: r_globallabel = re.compile(r"([\w]+)=[.]+") print print path.dirpath().basename + '/' + path.basename lines = path.readlines() expectedlines = lines[:] tracker = PARSERS[format].FunctionGcRootTracker(lines) table = tracker.computegcmaptable(verbose=sys.maxint) tabledict = {} seen = {} for entry in table: print '%s: %s' % (entry[0], format_callshape(entry[1])) tabledict[entry[0]] = entry[1] # find the ";; expected" lines prevline = "" for i, line in enumerate(lines): match = r_expected.match(line) if match: expected = match.group(1) prevmatch = r_globallabel.match(prevline) assert prevmatch, "the computed table is not complete" label = prevmatch.group(1) assert label in tabledict got = tabledict[label] assert format_callshape(got) == expected seen[label] = True if format == 'msvc': expectedlines.insert(i-2, 'PUBLIC\t%s\n' % (label,)) expectedlines.insert(i-1, '%s::\n' % (label,)) else: expectedlines.insert(i-2, '\t.globl\t%s\n' % (label,)) expectedlines.insert(i-1, '%s=.+%d\n' % (label, tracker.OFFSET_LABELS)) if format == 'msvc' and r_gcroot_constant.match(line): expectedlines[i] = ';' + expectedlines[i] expectedlines[i+1] = (expectedlines[i+1] .replace('\timul\t', '\tmov\t') + '\t; GCROOT\n') prevline = line assert len(seen) == len(tabledict), ( "computed table contains unexpected entries:\n%r" % [key for key in tabledict if key not in seen]) print '--------------- got ---------------' print ''.join(lines) print '------------- expected ------------' print ''.join(expectedlines) print '-----------------------------------' assert lines == expectedlines
def check_computegcmaptable(format, path): if format == 'msvc': r_globallabel = re.compile(r"([\w]+)::") else: r_globallabel = re.compile(r"([\w]+)=[.]+") print print path.dirpath().basename + '/' + path.basename lines = path.readlines() expectedlines = lines[:] tracker = PARSERS[format].FunctionGcRootTracker(lines) table = tracker.computegcmaptable(verbose=sys.maxint) tabledict = {} seen = {} for entry in table: print '%s: %s' % (entry[0], format_callshape(entry[1])) tabledict[entry[0]] = entry[1] # find the ";; expected" lines prevline = "" for i, line in enumerate(lines): match = r_expected.match(line) if match: expected = match.group(1) prevmatch = r_globallabel.match(prevline) assert prevmatch, "the computed table is not complete" label = prevmatch.group(1) assert label in tabledict got = tabledict[label] assert format_callshape(got) == expected seen[label] = True if format == 'msvc': expectedlines.insert(i - 2, 'PUBLIC\t%s\n' % (label, )) expectedlines.insert(i - 1, '%s::\n' % (label, )) else: expectedlines.insert(i - 2, '\t.globl\t%s\n' % (label, )) expectedlines.insert( i - 1, '%s=.+%d\n' % (label, tracker.OFFSET_LABELS)) if format == 'msvc' and r_gcroot_constant.match(line): expectedlines[i] = ';' + expectedlines[i] expectedlines[i + 1] = ( expectedlines[i + 1].replace('\timul\t', '\tmov\t') + '\t; GCROOT\n') prevline = line assert len(seen) == len(tabledict), ( "computed table contains unexpected entries:\n%r" % [key for key in tabledict if key not in seen]) print '--------------- got ---------------' print ''.join(lines) print '------------- expected ------------' print ''.join(expectedlines) print '-----------------------------------' assert lines == expectedlines
def test_format_callshape(): expected = ( '{4(%ebp) ' # position of the return address '| 8(%ebp), 12(%ebp), 16(%ebp), 20(%ebp) ' # 4 saved regs '| 24(%ebp), 28(%ebp)}') # GC roots assert format_callshape( (LOC_EBP_BASED + 4, LOC_EBP_BASED + 8, LOC_EBP_BASED + 12, LOC_EBP_BASED + 16, LOC_EBP_BASED + 20, LOC_EBP_BASED + 24, LOC_EBP_BASED + 28)) == expected
def test_format_callshape(): expected = ('{4(%ebp) ' # position of the return address '| 8(%ebp), 12(%ebp), 16(%ebp), 20(%ebp) ' # 4 saved regs '| 24(%ebp), 28(%ebp)}') # GC roots assert format_callshape((LOC_EBP_BASED+4, LOC_EBP_BASED+8, LOC_EBP_BASED+12, LOC_EBP_BASED+16, LOC_EBP_BASED+20, LOC_EBP_BASED+24, LOC_EBP_BASED+28)) == expected