1*897be3a4Schristos#!/usr/bin/env python 28585484eSchristos# 38585484eSchristos# Post-process the output of test-dumpevents and check it for correctness. 48585484eSchristos# 58585484eSchristos 68585484eSchristosimport math 78585484eSchristosimport re 88585484eSchristosimport sys 98585484eSchristos 108585484eSchristostext = sys.stdin.readlines() 118585484eSchristos 128585484eSchristostry: 138585484eSchristos expect_inserted_pos = text.index("Inserted:\n") 148585484eSchristos expect_active_pos = text.index("Active:\n") 158585484eSchristos got_inserted_pos = text.index("Inserted events:\n") 168585484eSchristos got_active_pos = text.index("Active events:\n") 178585484eSchristosexcept ValueError: 18*897be3a4Schristos sys.stderr.write("Missing expected dividing line in dumpevents output") 198585484eSchristos sys.exit(1) 208585484eSchristos 218585484eSchristosif not (expect_inserted_pos < expect_active_pos < 228585484eSchristos got_inserted_pos < got_active_pos): 23*897be3a4Schristos sys.stderr.write("Sections out of order in dumpevents output") 248585484eSchristos sys.exit(1) 258585484eSchristos 268585484eSchristosnow,T= text[1].split() 278585484eSchristosT = float(T) 288585484eSchristos 298585484eSchristoswant_inserted = set(text[expect_inserted_pos+1:expect_active_pos]) 308585484eSchristoswant_active = set(text[expect_active_pos+1:got_inserted_pos-1]) 318585484eSchristosgot_inserted = set(text[got_inserted_pos+1:got_active_pos]) 328585484eSchristosgot_active = set(text[got_active_pos+1:]) 338585484eSchristos 348585484eSchristospat = re.compile(r'Timeout=([0-9\.]+)') 358585484eSchristosdef replace_time(m): 368585484eSchristos t = float(m.group(1)) 378585484eSchristos if .9 < abs(t-T) < 1.1: 388585484eSchristos return "Timeout=T+1" 398585484eSchristos elif 2.4 < abs(t-T) < 2.6: 408585484eSchristos return "Timeout=T+2.5" 418585484eSchristos else: 428585484eSchristos return m.group(0) 438585484eSchristos 448585484eSchristoscleaned_inserted = set( pat.sub(replace_time, s) for s in got_inserted 458585484eSchristos if "Internal" not in s) 468585484eSchristos 478585484eSchristosif cleaned_inserted != want_inserted: 48*897be3a4Schristos sys.stderr.write("Inserted event lists were not as expected!") 498585484eSchristos sys.exit(1) 508585484eSchristos 518585484eSchristosif set(got_active) != set(want_active): 52*897be3a4Schristos sys.stderr.write("Active event lists were not as expected!") 538585484eSchristos sys.exit(1) 548585484eSchristos 55