xref: /aosp_15_r20/external/libevent/test/check-dumpevents.py (revision 663afb9b963571284e0f0a60f257164ab54f64bf)
1*663afb9bSAndroid Build Coastguard Worker#!/usr/bin/env python
2*663afb9bSAndroid Build Coastguard Worker#
3*663afb9bSAndroid Build Coastguard Worker# Post-process the output of test-dumpevents and check it for correctness.
4*663afb9bSAndroid Build Coastguard Worker#
5*663afb9bSAndroid Build Coastguard Worker
6*663afb9bSAndroid Build Coastguard Workerimport math
7*663afb9bSAndroid Build Coastguard Workerimport re
8*663afb9bSAndroid Build Coastguard Workerimport sys
9*663afb9bSAndroid Build Coastguard Worker
10*663afb9bSAndroid Build Coastguard Workertext = sys.stdin.readlines()
11*663afb9bSAndroid Build Coastguard Worker
12*663afb9bSAndroid Build Coastguard Workertry:
13*663afb9bSAndroid Build Coastguard Worker    expect_inserted_pos = text.index("Inserted:\n")
14*663afb9bSAndroid Build Coastguard Worker    expect_active_pos = text.index("Active:\n")
15*663afb9bSAndroid Build Coastguard Worker    got_inserted_pos = text.index("Inserted events:\n")
16*663afb9bSAndroid Build Coastguard Worker    got_active_pos = text.index("Active events:\n")
17*663afb9bSAndroid Build Coastguard Workerexcept ValueError:
18*663afb9bSAndroid Build Coastguard Worker    sys.stderr.write("Missing expected dividing line in dumpevents output")
19*663afb9bSAndroid Build Coastguard Worker    sys.exit(1)
20*663afb9bSAndroid Build Coastguard Worker
21*663afb9bSAndroid Build Coastguard Workerif not (expect_inserted_pos < expect_active_pos <
22*663afb9bSAndroid Build Coastguard Worker        got_inserted_pos < got_active_pos):
23*663afb9bSAndroid Build Coastguard Worker    sys.stderr.write("Sections out of order in dumpevents output")
24*663afb9bSAndroid Build Coastguard Worker    sys.exit(1)
25*663afb9bSAndroid Build Coastguard Worker
26*663afb9bSAndroid Build Coastguard Workernow,T= text[1].split()
27*663afb9bSAndroid Build Coastguard WorkerT = float(T)
28*663afb9bSAndroid Build Coastguard Worker
29*663afb9bSAndroid Build Coastguard Workerwant_inserted = set(text[expect_inserted_pos+1:expect_active_pos])
30*663afb9bSAndroid Build Coastguard Workerwant_active = set(text[expect_active_pos+1:got_inserted_pos-1])
31*663afb9bSAndroid Build Coastguard Workergot_inserted = set(text[got_inserted_pos+1:got_active_pos])
32*663afb9bSAndroid Build Coastguard Workergot_active = set(text[got_active_pos+1:])
33*663afb9bSAndroid Build Coastguard Worker
34*663afb9bSAndroid Build Coastguard Workerpat = re.compile(r'Timeout=([0-9\.]+)')
35*663afb9bSAndroid Build Coastguard Workerdef replace_time(m):
36*663afb9bSAndroid Build Coastguard Worker    t = float(m.group(1))
37*663afb9bSAndroid Build Coastguard Worker    if .9 < abs(t-T) < 1.1:
38*663afb9bSAndroid Build Coastguard Worker        return "Timeout=T+1"
39*663afb9bSAndroid Build Coastguard Worker    elif 2.4 < abs(t-T) < 2.6:
40*663afb9bSAndroid Build Coastguard Worker        return "Timeout=T+2.5"
41*663afb9bSAndroid Build Coastguard Worker    else:
42*663afb9bSAndroid Build Coastguard Worker        return m.group(0)
43*663afb9bSAndroid Build Coastguard Worker
44*663afb9bSAndroid Build Coastguard Workercleaned_inserted = set( pat.sub(replace_time, s) for s in got_inserted
45*663afb9bSAndroid Build Coastguard Worker                        if "Internal" not in s)
46*663afb9bSAndroid Build Coastguard Worker
47*663afb9bSAndroid Build Coastguard Workerif cleaned_inserted != want_inserted:
48*663afb9bSAndroid Build Coastguard Worker    sys.stderr.write("Inserted event lists were not as expected!")
49*663afb9bSAndroid Build Coastguard Worker    sys.exit(1)
50*663afb9bSAndroid Build Coastguard Worker
51*663afb9bSAndroid Build Coastguard Workerif set(got_active) != set(want_active):
52*663afb9bSAndroid Build Coastguard Worker    sys.stderr.write("Active event lists were not as expected!")
53*663afb9bSAndroid Build Coastguard Worker    sys.exit(1)
54*663afb9bSAndroid Build Coastguard Worker
55