1*c43e99fdSEd Maste#!/usr/bin/python2 2*c43e99fdSEd Maste# 3*c43e99fdSEd Maste# Post-process the output of test-dumpevents and check it for correctness. 4*c43e99fdSEd Maste# 5*c43e99fdSEd Maste 6*c43e99fdSEd Masteimport math 7*c43e99fdSEd Masteimport re 8*c43e99fdSEd Masteimport sys 9*c43e99fdSEd Maste 10*c43e99fdSEd Mastetext = sys.stdin.readlines() 11*c43e99fdSEd Maste 12*c43e99fdSEd Mastetry: 13*c43e99fdSEd Maste expect_inserted_pos = text.index("Inserted:\n") 14*c43e99fdSEd Maste expect_active_pos = text.index("Active:\n") 15*c43e99fdSEd Maste got_inserted_pos = text.index("Inserted events:\n") 16*c43e99fdSEd Maste got_active_pos = text.index("Active events:\n") 17*c43e99fdSEd Masteexcept ValueError: 18*c43e99fdSEd Maste print >>sys.stderr, "Missing expected dividing line in dumpevents output" 19*c43e99fdSEd Maste sys.exit(1) 20*c43e99fdSEd Maste 21*c43e99fdSEd Masteif not (expect_inserted_pos < expect_active_pos < 22*c43e99fdSEd Maste got_inserted_pos < got_active_pos): 23*c43e99fdSEd Maste print >>sys.stderr, "Sections out of order in dumpevents output" 24*c43e99fdSEd Maste sys.exit(1) 25*c43e99fdSEd Maste 26*c43e99fdSEd Mastenow,T= text[1].split() 27*c43e99fdSEd MasteT = float(T) 28*c43e99fdSEd Maste 29*c43e99fdSEd Mastewant_inserted = set(text[expect_inserted_pos+1:expect_active_pos]) 30*c43e99fdSEd Mastewant_active = set(text[expect_active_pos+1:got_inserted_pos-1]) 31*c43e99fdSEd Mastegot_inserted = set(text[got_inserted_pos+1:got_active_pos]) 32*c43e99fdSEd Mastegot_active = set(text[got_active_pos+1:]) 33*c43e99fdSEd Maste 34*c43e99fdSEd Mastepat = re.compile(r'Timeout=([0-9\.]+)') 35*c43e99fdSEd Mastedef replace_time(m): 36*c43e99fdSEd Maste t = float(m.group(1)) 37*c43e99fdSEd Maste if .9 < abs(t-T) < 1.1: 38*c43e99fdSEd Maste return "Timeout=T+1" 39*c43e99fdSEd Maste elif 2.4 < abs(t-T) < 2.6: 40*c43e99fdSEd Maste return "Timeout=T+2.5" 41*c43e99fdSEd Maste else: 42*c43e99fdSEd Maste return m.group(0) 43*c43e99fdSEd Maste 44*c43e99fdSEd Mastecleaned_inserted = set( pat.sub(replace_time, s) for s in got_inserted 45*c43e99fdSEd Maste if "Internal" not in s) 46*c43e99fdSEd Maste 47*c43e99fdSEd Masteif cleaned_inserted != want_inserted: 48*c43e99fdSEd Maste print >>sys.stderr, "Inserted event lists were not as expected!" 49*c43e99fdSEd Maste sys.exit(1) 50*c43e99fdSEd Maste 51*c43e99fdSEd Masteif set(got_active) != set(want_active): 52*c43e99fdSEd Maste print >>sys.stderr, "Active event lists were not as expected!" 53*c43e99fdSEd Maste sys.exit(1) 54*c43e99fdSEd Maste 55