Created
August 2, 2023 18:40
-
-
Save SciresM/cad1eefed2218aff19fcc2494cfc5e32 to your computer and use it in GitHub Desktop.
Revisions
-
SciresM created this gist
Aug 2, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,113 @@ import sys def is_diff(i_a, i_b): if sorted(i_a.keys()) != sorted(i_b.keys()): return False for k in sorted(i_a.keys()): if k in ['lr', 'vt', 'func']: continue if i_a[k] != i_b[k]: return True return False def get_str(k, v): if k in ['buffer_entry_sizes', 'buffers']: return '[%s]' % ', '.join('0x%X' % x for x in v) elif k in ['inbytes', 'outbytes']: return '0x%X' % v else: return str(v) def summary(cmd): s = '' for k in sorted(cmd.keys()): if k in ['lr', 'vt', 'func']: continue if s: s += ', ' s += k s += ': ' s += get_str(k, cmd[k]) return s def summary_diff(a, b): s = '' assert sorted(a.keys()) == sorted(b.keys()) for k in sorted(a.keys()): if k in ['lr', 'vt', 'func']: continue if a[k] != b[k]: if s: s += ', ' s += k s += ': ' s += get_str(k, a[k]) + ' -> ' + get_str(k, b[k]) s += ' (final state: %s)' % summary(b) return s def diff_p(a, b): a_p = a.keys() b_p = b.keys() a_only = sorted([p for p in a_p if p not in b_p]) b_only = sorted([p for p in b_p if p not in a_p]) both_p = sorted([p for p in set(a_p + b_p) if p in a_p and p in b_p]) for p in a_only: print 'Process Removed: %s' % p for p in b_only: print 'Process Added: %s' % p a_i = {} a_x = {} b_i = {} b_x = {} for p in a_p: p_i = a[p] for n in p_i.keys(): target = a_i if not n.startswith('0x') else a_x #print n assert n not in target or sorted(target[n].keys()) == sorted(p_i[n].keys()) target[n] = p_i[n] for p in b_p: p_i = b[p] for n in p_i.keys(): target = b_i if not n.startswith('0x') else b_x assert n not in target or sorted(target[n].keys()) == sorted(p_i[n].keys()) target[n] = p_i[n] a_only = sorted([p for p in a_i.keys() if p not in b_i.keys()]) b_only = sorted([p for p in b_i.keys() if p not in a_i.keys()]) both_p = sorted([p for p in set(a_i.keys() + b_i.keys()) if p in a_i.keys() and p in b_i.keys()]) for p in a_only: print 'Interface Removed: %s' % p for p in b_only: print 'Interface Added: %s' % p for n in sorted(both_p): i_a = a_i[n] i_b = b_i[n] a_only = sorted([p for p in i_a.keys() if p not in i_b.keys()]) b_only = sorted([p for p in i_b.keys() if p not in i_a.keys()]) both_p = sorted([p for p in set(i_a.keys() + i_b.keys()) if p in i_a.keys() and p in i_b.keys()]) changed = sorted([p for p in both_p if is_diff(i_a[p], i_b[p])]) if len(a_only + b_only + changed) > 0: print 'Interface Changed: %s' % n for c in sorted(set(a_only + b_only + changed)): if c in a_only: print ' Removed: %5d - %s' % (c, summary(i_a[c])) if c in b_only: print ' Added: %5d - %s' % (c, summary(i_b[c])) if c in changed: print ' Changed: %5d - %s' % (c, summary_diff(i_a[c], i_b[c])) def load_intf(fn): with open(fn, 'r') as f: return eval('{'+f.read()+'}') def main(argc, argv): before = load_intf(argv[1]) after = load_intf(argv[2]) diff_p(before, after) return 0 if __name__ == '__main__': sys.exit(main(len(sys.argv), sys.argv)) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,82 @@ import os, shutil, sys IN_NONE, IN_PROC, IN_INTF = range(3) def get_strkey(line): line = line.strip() return line[:line.index("':")].replace("'",'') def is_empty(line): return not line.strip() def is_start_proc(line): return "':" in line and '{' in line and '}' not in line def is_end_proc(line): return line == '},' def is_start_intf(line): return line.startswith(' ') and "':" in line and '{' in line and '}' not in line def is_end_intf(line): return line == ' },' def is_command(line): return line.startswith(' ') and ': ' in line and (line[line.index(':')-1] in '0123456789' or get_strkey(line) == 'default') and '{' in line and '}' in line def get_sortkey(intf): name, lines = intf if name.startswith('0x'): return '__zzz__%s' % name else: return name def sort_info(lines): out_lines = [] state = IN_NONE for line in lines: print line if state == IN_NONE: assert is_empty(line) or is_start_proc(line) if is_start_proc(line): out_lines.append(line) proc_name = get_strkey(line) proc_intfs = [] state = IN_PROC print 'entering proc: %s' % proc_name elif state == IN_PROC: assert is_start_intf(line) or is_end_proc(line) if is_start_intf(line): intf_name = get_strkey(line) #print ' intf: %s' % intf_name cur_intf = [line] state = IN_INTF elif is_end_proc(line): for (i, i_lines) in sorted(proc_intfs, key=get_sortkey): #print ' '+i out_lines += i_lines out_lines.append(line) proc_intfs = None proc_name = None state = IN_NONE elif state == IN_INTF: assert is_command(line) or is_end_intf(line) if is_command(line): cur_intf.append(line) elif is_end_intf(line): cur_intf.append(line) proc_intfs.append((intf_name, cur_intf)) intf_name = None cur_intf = None state = IN_PROC return out_lines def main(argc, argv): with open(argv[1], 'rb') as f: lines = [s.rstrip() for s in f.readlines()] with open(argv[2], 'wb') as f: f.writelines(['%s\n' % s.rstrip() for s in sort_info(lines)]) return 0 if __name__ == '__main__': sys.exit(main(len(sys.argv), sys.argv))