-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogVerify.py
64 lines (53 loc) · 1.32 KB
/
logVerify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def checkAND(opA, opB, aluout):
expected = opA & opB
if aluout==expected:
return True
return False
def checkADD(opA, opB, aluout, cout):
expected = opA + opB
# cout for overflow
if aluout + 16*cout == expected:
return True
return False
def checkOR(opA, opB, aluout):
expected = opA | opB
if aluout==expected:
return True
return False
correct=0
testcases=0
file = open('log/test.txt', "r")
lines = file.readlines()
#reading the log file
for i in range(0, len(lines), 2):
log = lines[i].split()
# read data from file
op = (int(log[1][3:], 2))
B = (int(log[2][2:], 2))
A = (int(log[3][2:], 2))
cout = (int(log[4][6], 2))
out = 0
if op != 3:
out = (int(log[5][4:], 2))
else:
out = -100
if op==0:
flag=checkOR(A, B, out)
elif op==1:
flag=checkAND(A, B, out)
elif op==2:
flag=checkADD(A, B, out, cout)
else:
if log[5][4:] == 'XXXX':
flag = True
else:
flag = False
if flag:
correct+=1
else:
print("The following inputs are causing unexpected behaviour-")
print(f"\tA: {A}, B: {B}, op:{op}")
testcases+=1
accuracy = (correct*100.0)/testcases
print(f"Accuracy of simulation: {accuracy}%\n")
file.close()