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