Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial test case validation using pyucis #23

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
.settings/
Debug/
.pydevproject
venv/
setenv.sh
fir.xml
6 changes: 5 additions & 1 deletion examples/fir/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ main: $(OBJFILES)
obj/%.o: %.cpp
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) $^ -o $@

run:
run: main
$(LDPATH) && ./$(EXEC)

test: run
$(MAKE) -C ../../test/pyucis-fir/ validate_fir

clean:
rm -rf obj $(EXEC)
rm coverage_results.xml
15 changes: 15 additions & 0 deletions examples/fir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Build Instructions

These are the build instructions for using the example

```
# export SYSTEMC_HOME="path to systemC release dir"
$ make clean
$ make
$ make run
```

# Test Instructions *(optional)*
Optionally test the output using the following instructions


2 changes: 1 addition & 1 deletion examples/fir/src/stimulus.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ SC_MODULE(stimulus) {
bin<int>("invalid", 0)
};

cross<int, int, int> reset_valid_cross = cross<int, int, int> (this, "reset valid",
cross<int, int, int> reset_valid_cross = cross<int, int, int> (this, "reset_valid",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the rename necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spaces in the name cause problems with my bash code parser. Its a preference to fix. FWIW, the output does not match the golden coverage report either. ie. foo[1] vs foo_1. I can handle either but spaces cause me to have to tweak the code.

If its a problem I can reverse this one. I was just thinking ahead. I don't know if the pyucis one has a problem with it to be honest. I do know the sample I am looking at has all _ separated names. FWIW the spec says this, but I am not entirely clear about the spec:

4.8.3 Variable names as naming components
Variables and parts of variables are identified by language-appropriate string names with no unnecessary white space.

&reset_cvp,
&input_valid_cvp,
&values_cvp
Expand Down
3 changes: 2 additions & 1 deletion includes/fc4sc_bin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ class bin : public bin_base
stream << "type=\""
<< this->ucis_bin_type
<< "\" "
<< "alias=\"" << this->get_hitcount() << "\""
<< "alias=\"" << this->get_hitcount() << "\" "
<< "key=\"KEY\""
<< ">\n";

// Print each range. Coverpoint writes the header (name etc.)
Expand Down
2 changes: 1 addition & 1 deletion includes/fc4sc_covergroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class covergroup : public cvg_base
<< "\" line=\""
<< "1"
<< "\" inlineCount=\"1\"/>\n";
stream << "<ucis:cgSourceId file=\"" << file_name << "\" "
stream << "<ucis:cgSourceId file=\"1\" "
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look ready to go.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are hardcoded 1's and "KEY" in the code. The sample xml I am looking at has 4625 key="0" in it. It also has 54 entires which look like this

<ucis:cgSourceId file="1" line="1" inlineCount="1"/>

None have a value other than 1.

<< "line=\"" << line << "\""
<< " inlineCount=\"1\"/>\n";
stream << "</ucis:cgId>\n";
Expand Down
2 changes: 1 addition & 1 deletion includes/fc4sc_cross.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class cross : public cvp_base
<< "\" ";
stream << ">\n";

stream << option << "\n";
stream << "<ucis:options />\n";

for (auto &cvp : cvps_vec)
{
Expand Down
2 changes: 1 addition & 1 deletion includes/fc4sc_master.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class global
stream << ">\n";

stream << "<ucis:id ";
stream << "file=\"" << type_it.second.file_name << "\" ";
stream << "file=\"" << 1 << "\" ";
stream << "line=\"" << type_it.second.line << "\" ";
stream << "inlineCount=\""
<< "1"
Expand Down
1 change: 1 addition & 0 deletions test/pyucis-fir/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
5 changes: 5 additions & 0 deletions test/pyucis-fir/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DEFAULT_GOAL := validate_fir


validate_fir:
python3 validate_ucis_xml.py
7 changes: 7 additions & 0 deletions test/pyucis-fir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# test of xml output with pyucis

This directory contains test code to validate the coverage_report.xml
output for the fir example. It requires python3 and the [VENV.md](VENV.md)
file shows how to setup a virtual environment for testing.


22 changes: 22 additions & 0 deletions test/pyucis-fir/VENV.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# venv notes
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are personal notes and don't belong to this project.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it would help with someone who wanted to run the same setup, but sure I can back it out.


# Create and activate the venv

Do this once

```
sudo apt-get install python3-venv
python3 -m venv venv
. venv/bin/activate
python3 -m pip install -r requirements.txt
# test that usis can be imported
python3 -c 'import ucis'
alias bazel='/home/davis/bin/bazel-4.2.1-linux-x86_64'
```


# Activate the venv

```
. venv/bin/activate
```
1 change: 1 addition & 0 deletions test/pyucis-fir/coverage_results.xml
4 changes: 4 additions & 0 deletions test/pyucis-fir/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pyucis==0.0.5.20220416.1
pylint
pyyaml

16 changes: 16 additions & 0 deletions test/pyucis-fir/ucis_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Tests for ucis."""

import unittest
from validate_ucis_xml import validate_ucis



class UcisTest(unittest.TestCase):

def test_validate_ucis_xml(self):
self.assertTrue(validate_ucis('../../examples/fir/coverage_results.xml'))



if __name__ == '__main__':
unittest.main()
44 changes: 44 additions & 0 deletions test/pyucis-fir/validate_ucis_xml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
""" Test script to compare coverage_results.xml with spec

Use pyucis to validate fir example coverage result generated
by FC4SC against specification.
"""

from io import BytesIO
from ucis.xml import validate_ucis_xml



def validate_ucis(file_name):
"""
Validate UCIS function

: arg file_name: The filename to validate
: returns: status of validation. TODO:return
"""
rc = False

try:
with open(file_name, encoding='utf-8') as f:
xml_file = BytesIO(bytes(bytearray(f.read(), encoding='utf-8')))
rc = validate_ucis_xml(xml_file)
except:
print("an exception occured")

return rc


def main() -> None:

rc = validate_ucis('../../examples/fir/coverage_results.xml')
return rc



if __name__ == '__main__':
rc = main()
if rc:
print("validation OK")
else:
print("validation Failure")

1 change: 1 addition & 0 deletions tools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
22 changes: 22 additions & 0 deletions tools/VENV.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# venv notes

# Create and activate the venv

Do this once

```
sudo apt-get install python3-venv
python3 -m venv venv
. venv/bin/activate
python3 -m pip install -r requirements.txt
# test that usis can be imported
python3 -c 'import ucis'
alias bazel='/home/davis/bin/bazel-4.2.1-linux-x86_64'
```


# Activate the venv

```
. venv/bin/activate
```
4 changes: 4 additions & 0 deletions tools/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pyucis==0.0.5.20220416.1
pylint
pyyaml