1275970Scy#!/usr/bin/python2
2275970Scy#
3275970Scy# Post-process the output of test-dumpevents and check it for correctness.
4275970Scy#
5275970Scy
6275970Scyimport math
7275970Scyimport re
8275970Scyimport sys
9275970Scy
10275970Scytext = sys.stdin.readlines()
11275970Scy
12275970Scytry:
13275970Scy    expect_inserted_pos = text.index("Inserted:\n")
14275970Scy    expect_active_pos = text.index("Active:\n")
15275970Scy    got_inserted_pos = text.index("Inserted events:\n")
16275970Scy    got_active_pos = text.index("Active events:\n")
17275970Scyexcept ValueError:
18275970Scy    print >>sys.stderr, "Missing expected dividing line in dumpevents output"
19275970Scy    sys.exit(1)
20275970Scy
21275970Scyif not (expect_inserted_pos < expect_active_pos <
22275970Scy        got_inserted_pos < got_active_pos):
23275970Scy    print >>sys.stderr, "Sections out of order in dumpevents output"
24275970Scy    sys.exit(1)
25275970Scy
26275970Scynow,T= text[1].split()
27275970ScyT = float(T)
28275970Scy
29275970Scywant_inserted = set(text[expect_inserted_pos+1:expect_active_pos])
30275970Scywant_active = set(text[expect_active_pos+1:got_inserted_pos-1])
31275970Scygot_inserted = set(text[got_inserted_pos+1:got_active_pos])
32275970Scygot_active = set(text[got_active_pos+1:])
33275970Scy
34275970Scypat = re.compile(r'Timeout=([0-9\.]+)')
35275970Scydef replace_time(m):
36275970Scy    t = float(m.group(1))
37275970Scy    if .9 < abs(t-T) < 1.1:
38275970Scy        return "Timeout=T+1"
39275970Scy    elif 2.4 < abs(t-T) < 2.6:
40275970Scy        return "Timeout=T+2.5"
41275970Scy    else:
42275970Scy        return m.group(0)
43275970Scy
44275970Scycleaned_inserted = set( pat.sub(replace_time, s) for s in got_inserted
45275970Scy                        if "Internal" not in s)
46275970Scy
47275970Scyif cleaned_inserted != want_inserted:
48275970Scy    print >>sys.stderr, "Inserted event lists were not as expected!"
49275970Scy    sys.exit(1)
50275970Scy
51275970Scyif set(got_active) != set(want_active):
52275970Scy    print >>sys.stderr, "Active event lists were not as expected!"
53275970Scy    sys.exit(1)
54275970Scy
55