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