-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_inliner.py
More file actions
148 lines (137 loc) · 6.22 KB
/
test_inliner.py
File metadata and controls
148 lines (137 loc) · 6.22 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import unittest
from inline import *
import tokenizer
class TestInliner(unittest.TestCase):
def setUp(self,config_path,input_path):
self.input = input_path
self.config = config_path
self.inliner = Inliner(config_path,input_path)
def test_preservation_after_indexing(self, outpath):
self.inliner._index()
with open(f"unit_testing_output/{outpath}", 'w') as f:
f.write(f"Preservation After Indexing Test of Inliner Class\n\
Input path: \"{self.input}\" \n \
Config path: \"{self.config}\" \n")
for k in self.inliner.modules:
h = "".join( list( map(lambda x : x.to_string(), self.inliner.modules[k].header)))
b = "".join( list( map(lambda x : x.to_string(), self.inliner.modules[k].body)))
with open(f"unit_testing_output/{outpath}", 'a') as f:
f.write(h)
f.write(b)
f.write('\n')
def test_ports(self, outpath):
self.inliner._index()
with open(f"unit_testing_output/{outpath}", 'w') as f:
f.write(f"Port Recording Test of Inliner Class Method _index() \nInput path: \"{self.input}\" \nConfig path: \"{self.config}\" \n")
for k in self.inliner.modules:
with open(f"unit_testing_output/{outpath}", 'a') as f:
f.write(f"Module \"{k}\" Ports:\n")
for p in self.inliner.modules[k].ports:
f.write(p)
f.write('\n')
def test_named_param_list_parser(self, named_param_list_str, module_name):
self.inliner._index()
t = Tokenizer(self.config)
params = t.tokenize(named_param_list_str)
try:
out = self.inliner._parse_named_param_list(params,module_name)
print("No exceptions thrown")
print( "Parameter : Value")
for k, v in out.items():
print(f"{k} : {v}")
except ValueError as e:
print("Test of function Inliner._parse_named_param_list failed due to the following error, possibly expected")
raise
except Exception as e:
print("Test of function Inliner._parse_named_param_list failed due to unexpected error.")
raise
def test_positional_param_list_parser(self, pos_param_list_str, module_name):
self.inliner._index()
t = Tokenizer(self.config)
params = t.tokenize(pos_param_list_str)
try:
out = self.inliner._parse_positional_param_list(params,module_name)
print("No exceptions thrown")
print( "Parameter : Value")
for k, v in out.items():
print(f"{k} : {v}")
except ValueError as e:
print("Test of function Inliner._parse_named_param_list failed due to the following error, possibly expected")
raise
except Exception as e:
print("Test of function Inliner._parse_named_param_list failed due to unexpected error.")
raise
def test_named_port_list_parser(self, named_port_list_str, module_name):
self.inliner._index()
t = Tokenizer(self.config)
ports = t.tokenize(named_port_list_str)
try:
out = self.inliner._parse_named_port_list(ports,module_name)
print("No exceptions thrown")
print( "Parameter : Value")
for k, v in out.items():
print(f"{k} : {v}")
except ValueError as e:
print("Test of function Inliner._parse_named_port_list failed due to the following error, possibly expected")
raise
except Exception as e:
print("Test of function Inliner._parse_named_port_list failed due to unexpected error.")
raise
def test_positional_port_list_parser(self, pos_port_list_str, module_name):
self.inliner._index()
t = Tokenizer(self.config)
ports = t.tokenize(pos_port_list_str)
try:
out = self.inliner._parse_positional_port_list(ports,module_name)
print("No exceptions thrown")
print( "Parameter : Value")
for k, v in out.items():
print(f"{k} : {v}")
except ValueError as e:
print("Test of function Inliner._parse_named_port_list failed due to the following error, possibly expected")
raise
except Exception as e:
print("Test of function Inliner._parse_named_port_list failed due to unexpected error.")
raise
def test_instantiation_to_inlined_body(self, instantiation_stmt):
''' Params: instantiation_stmt (str), a string in verilog syntax instantiating a module found
in input file
'''
t = Tokenizer(self.config)
self.inliner._index()
toks = t.tokenize(instantiation_stmt)
try:
out = self.inliner._instantation_to_inlined_body(toks)
print("No exceptions thrown")
print("Output")
strings = [x.to_string() for x in out]
print("".join(strings))
except Exception as e:
print("Test of function Inliner._parse_named_port_list failed due to the following error:")
raise
def test_generate_reference_tree(self):
''' Test of the Inline._generate_reference_tree function '''
self.inliner._index()
self.inliner._generate_reference_tree()
print(self.inliner.reference_tree)
# STOPPED HERE
def test_inline_function(self):
''' Test of the Inline._inline() function which creates the class's
inlined_modules dictionary
'''
self.inliner._index()
self.inliner._generate_reference_tree()
print("Testing Inline._inline():\n")
try:
self.inliner._inline()
for name, mod in self.inliner._inlined_modules.items():
print(f"Module: {name}")
print("Inlined Version")
h = "".join( list( map(lambda x : x.to_string(), mod.header)))
b = "".join( list( map(lambda x : x.to_string(), mod.body)))
print(h)
print(b)
print("\n")
except:
print("Error encountered or unexpected exception raised:")
raise