Skip to content

Commit

Permalink
Minor updates to debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed Jul 27, 2018
1 parent ce618fd commit a11bab3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions fault/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ def __init__(self, value, N):
self.value = value
self.N = N

def __getitem__(self, index):
return self.value[index]

def __setitem__(self, index, value):
self.value[index] = value

Expand Down
18 changes: 13 additions & 5 deletions fault/verilator_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ def harness(circuit, tests):
}} value_t;
void check(const char* port, int a, value_t b, int i) {{
if (!b.is_x) {{
std::cerr << port << "=" << b.value << ", ";
}}
if (!b.is_x && !(a == b.value)) {{
std::cout << std::endl; // end the current line
std::cerr << \"Got : \" << a << std::endl;
std::cerr << \"Expected : \" << b.value << std::endl;
std::cerr << \"i : \" << i << std::endl;
std::cerr << \"Port : \" << port << std::endl;
exit(1);
}}
}}
Expand Down Expand Up @@ -102,6 +107,8 @@ def to_string(t):
source += '''
for(int i = 0; i < {}; i++) {{
value_t* test = tests[i];
std::cerr << "Inputs: ";
'''.format(len(tests))

i = 0
Expand All @@ -113,22 +120,21 @@ def to_string(t):
for _name in flattened_names(port):
source += f'''\
top->{name}{_name} = test[{i}].value;
std::cout << "top->{name}{_name} = " << test[{i}].value << ", ";
std::cerr << "top->{name}{_name} = " << test[{i}].value << ", ";
'''
i += 1

else:
source += f'''\
top->{name} = test[{i}].value;
std::cout << "top->{name} = " << test[{i}].value << ", ";
std::cerr << "top->{name} = " << test[{i}].value << ", ";
'''
i += 1
else:
if isinstance(port, m.ArrayType) and \
not isinstance(port.T, m._BitType):
for _name in flattened_names(port):
output_str += f'''\
std::cout << "top->{name} = " << test[{i}].value << ", ";
check(\"{name}{_name}\", top->{name}{_name}, test[{i}], i);
'''
i += 1
Expand All @@ -139,10 +145,12 @@ def to_string(t):
i += 1

source += f'''\
std::cout << std::endl;
std::cerr << std::endl;
std::cerr << "Checking Outputs: ";
{output_str}
std::cout << std::endl;
std::cerr << std::endl;
top->eval();
std::cerr << "{"="*80}" << std::endl;
'''
source += '''\
}
Expand Down

0 comments on commit a11bab3

Please sign in to comment.