From 3aa967bc3bf070ddbe8448e25e2be3d54f3366a6 Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Mon, 16 May 2022 15:49:01 -0400 Subject: [PATCH 01/15] initial test code for ucis compliance --- .gitignore | 3 +++ examples/fir/README.md | 9 +++++++++ test/pyucis-fir/VENV.md | 22 ++++++++++++++++++++++ test/pyucis-fir/requirements.txt | 2 ++ test/pyucis-fir/test_ucis_xml.py | 18 ++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 examples/fir/README.md create mode 100644 test/pyucis-fir/VENV.md create mode 100644 test/pyucis-fir/requirements.txt create mode 100644 test/pyucis-fir/test_ucis_xml.py diff --git a/.gitignore b/.gitignore index c3306c0..f4edf83 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ .settings/ Debug/ .pydevproject +venv/ +setenv.sh +fir.xml diff --git a/examples/fir/README.md b/examples/fir/README.md new file mode 100644 index 0000000..63fa46a --- /dev/null +++ b/examples/fir/README.md @@ -0,0 +1,9 @@ +# Build Instructions + +``` +# export SYSTEMC_HOME="path to systemC release dir" +$ make clean +$ make +$ make run +``` + diff --git a/test/pyucis-fir/VENV.md b/test/pyucis-fir/VENV.md new file mode 100644 index 0000000..c5b5671 --- /dev/null +++ b/test/pyucis-fir/VENV.md @@ -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 +``` diff --git a/test/pyucis-fir/requirements.txt b/test/pyucis-fir/requirements.txt new file mode 100644 index 0000000..fcfbeb7 --- /dev/null +++ b/test/pyucis-fir/requirements.txt @@ -0,0 +1,2 @@ +pyucis==0.0.5.20220416.1 + diff --git a/test/pyucis-fir/test_ucis_xml.py b/test/pyucis-fir/test_ucis_xml.py new file mode 100644 index 0000000..1788cf3 --- /dev/null +++ b/test/pyucis-fir/test_ucis_xml.py @@ -0,0 +1,18 @@ +"""TODO(davjohn): DO NOT SUBMIT without one-line documentation for test_ucis_xml. + +TODO(davjohn): DO NOT SUBMIT without a detailed description of test_ucis_xml. +""" + + +from io import BytesIO +import os +from ucis.xml import validate_ucis_xml + + + + +with open('fir.xml') as f: + xml_file = BytesIO(bytes(bytearray(f.read(), encoding='utf-8'))) + validate_ucis_xml(xml_file) + + From 44b298dcfe02dc96a77a398c18981516969e33d0 Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Mon, 16 May 2022 15:50:47 -0400 Subject: [PATCH 02/15] wip --- test/pyucis-fir/test_ucis_xml.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/pyucis-fir/test_ucis_xml.py b/test/pyucis-fir/test_ucis_xml.py index 1788cf3..e2423c8 100644 --- a/test/pyucis-fir/test_ucis_xml.py +++ b/test/pyucis-fir/test_ucis_xml.py @@ -1,8 +1,3 @@ -"""TODO(davjohn): DO NOT SUBMIT without one-line documentation for test_ucis_xml. - -TODO(davjohn): DO NOT SUBMIT without a detailed description of test_ucis_xml. -""" - from io import BytesIO import os From 32f39e43271e028a49b8158569343fde14d2fc85 Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Mon, 16 May 2022 15:53:21 -0400 Subject: [PATCH 03/15] wip --- test/pyucis-fir/test_ucis_xml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pyucis-fir/test_ucis_xml.py b/test/pyucis-fir/test_ucis_xml.py index e2423c8..3629fee 100644 --- a/test/pyucis-fir/test_ucis_xml.py +++ b/test/pyucis-fir/test_ucis_xml.py @@ -6,7 +6,7 @@ -with open('fir.xml') as f: +with open('../../examples/fir/coverage_results.xml') as f: xml_file = BytesIO(bytes(bytearray(f.read(), encoding='utf-8'))) validate_ucis_xml(xml_file) From d9e477f8ff5f25434fa8e15b9e3d7282bdca6502 Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Tue, 17 May 2022 12:26:14 -0400 Subject: [PATCH 04/15] final to get pyucis validation to pass for fir example --- examples/fir/src/stimulus.h | 2 +- includes/fc4sc_bin.hpp | 3 ++- includes/fc4sc_covergroup.hpp | 2 +- includes/fc4sc_cross.hpp | 2 +- includes/fc4sc_master.hpp | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/fir/src/stimulus.h b/examples/fir/src/stimulus.h index 624a553..85d31ad 100644 --- a/examples/fir/src/stimulus.h +++ b/examples/fir/src/stimulus.h @@ -103,7 +103,7 @@ SC_MODULE(stimulus) { bin("invalid", 0) }; - cross reset_valid_cross = cross (this, "reset valid", + cross reset_valid_cross = cross (this, "reset_valid", &reset_cvp, &input_valid_cvp, &values_cvp diff --git a/includes/fc4sc_bin.hpp b/includes/fc4sc_bin.hpp index 34f593c..1ab49ff 100644 --- a/includes/fc4sc_bin.hpp +++ b/includes/fc4sc_bin.hpp @@ -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.) diff --git a/includes/fc4sc_covergroup.hpp b/includes/fc4sc_covergroup.hpp index 1cc5510..4599b9d 100644 --- a/includes/fc4sc_covergroup.hpp +++ b/includes/fc4sc_covergroup.hpp @@ -246,7 +246,7 @@ class covergroup : public cvg_base << "\" line=\"" << "1" << "\" inlineCount=\"1\"/>\n"; - stream << "\n"; stream << "\n"; diff --git a/includes/fc4sc_cross.hpp b/includes/fc4sc_cross.hpp index 665c55f..41b11a2 100644 --- a/includes/fc4sc_cross.hpp +++ b/includes/fc4sc_cross.hpp @@ -265,7 +265,7 @@ class cross : public cvp_base << "\" "; stream << ">\n"; - stream << option << "\n"; + stream << "\n"; for (auto &cvp : cvps_vec) { diff --git a/includes/fc4sc_master.hpp b/includes/fc4sc_master.hpp index 4deeffa..125864e 100644 --- a/includes/fc4sc_master.hpp +++ b/includes/fc4sc_master.hpp @@ -273,7 +273,7 @@ class global stream << ">\n"; stream << " Date: Tue, 17 May 2022 14:08:14 -0400 Subject: [PATCH 05/15] redo per suggestions --- test/pyucis-fir/requirements.txt | 1 + test/pyucis-fir/test_ucis_xml.py | 13 ------------- test/pyucis-fir/validate_ucis_xml.py | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 13 deletions(-) delete mode 100644 test/pyucis-fir/test_ucis_xml.py create mode 100644 test/pyucis-fir/validate_ucis_xml.py diff --git a/test/pyucis-fir/requirements.txt b/test/pyucis-fir/requirements.txt index fcfbeb7..681040a 100644 --- a/test/pyucis-fir/requirements.txt +++ b/test/pyucis-fir/requirements.txt @@ -1,2 +1,3 @@ pyucis==0.0.5.20220416.1 +pylint diff --git a/test/pyucis-fir/test_ucis_xml.py b/test/pyucis-fir/test_ucis_xml.py deleted file mode 100644 index 3629fee..0000000 --- a/test/pyucis-fir/test_ucis_xml.py +++ /dev/null @@ -1,13 +0,0 @@ - -from io import BytesIO -import os -from ucis.xml import validate_ucis_xml - - - - -with open('../../examples/fir/coverage_results.xml') as f: - xml_file = BytesIO(bytes(bytearray(f.read(), encoding='utf-8'))) - validate_ucis_xml(xml_file) - - diff --git a/test/pyucis-fir/validate_ucis_xml.py b/test/pyucis-fir/validate_ucis_xml.py new file mode 100644 index 0000000..724a4a9 --- /dev/null +++ b/test/pyucis-fir/validate_ucis_xml.py @@ -0,0 +1,15 @@ +""" 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 + + + + +with open('../../examples/fir/coverage_results.xml', encoding='utf-8') as f: + xml_file = BytesIO(bytes(bytearray(f.read(), encoding='utf-8'))) + validate_ucis_xml(xml_file) From b02bfea77c72fe78540693dd737006f9412217d9 Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Tue, 17 May 2022 14:42:00 -0400 Subject: [PATCH 06/15] adding makefile stub in prep for test conversion --- examples/fir/Makefile | 3 +++ test/pyucis-fir/Makefile | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 test/pyucis-fir/Makefile diff --git a/examples/fir/Makefile b/examples/fir/Makefile index 06e3378..32e97fe 100644 --- a/examples/fir/Makefile +++ b/examples/fir/Makefile @@ -50,5 +50,8 @@ obj/%.o: %.cpp run: $(LDPATH) && ./$(EXEC) +test: + $(MAKE) -C ../../test/pyucis-fir/ validate_fir + clean: rm -rf obj $(EXEC) diff --git a/test/pyucis-fir/Makefile b/test/pyucis-fir/Makefile new file mode 100644 index 0000000..c6ffd0d --- /dev/null +++ b/test/pyucis-fir/Makefile @@ -0,0 +1,5 @@ +.DEFAULT_GOAL := validate_fir + + +validate_fir: + python3 validate_ucis_xml.py From 15b8e1720a4bb44505b6f20fadbc5942632447a7 Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Tue, 17 May 2022 17:45:27 -0400 Subject: [PATCH 07/15] unit test initial release --- test/pyucis-fir/ucis_test.py | 20 ++++++++++++++++ test/pyucis-fir/validate_ucis_xml.py | 34 +++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 test/pyucis-fir/ucis_test.py diff --git a/test/pyucis-fir/ucis_test.py b/test/pyucis-fir/ucis_test.py new file mode 100644 index 0000000..5b68e5f --- /dev/null +++ b/test/pyucis-fir/ucis_test.py @@ -0,0 +1,20 @@ +"""Tests for ucis.""" + +import unittest +from validate_ucis_xml import validate_ucis + +#from usr.local.google.home.davjohn.progs.fc4sc.test.pyucis-fir import ucis +#from google3.testing.pybase import googletest + + +#class UcisTest(googletest.TestCase): +class UcisTest(unittest.TestCase): + + def test_validate_ucis_xml(self): + self.assertTrue(validate_ucis('../../examples/fir/coverage_results.xml')) + + + +if __name__ == '__main__': + #googletest.main() + unittest.main() diff --git a/test/pyucis-fir/validate_ucis_xml.py b/test/pyucis-fir/validate_ucis_xml.py index 724a4a9..eeba497 100644 --- a/test/pyucis-fir/validate_ucis_xml.py +++ b/test/pyucis-fir/validate_ucis_xml.py @@ -9,7 +9,35 @@ +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 # TODO: fixme + + +#def main(argv: Sequence[str]) -> None: +def main() -> None: + #if len(argv) > 1: + # raise app.UsageError('Too many command-line arguments.') + + validate_ucis('../../examples/fir/coverage_results.xml') + + + +if __name__ == '__main__': +# app.run(main) + main() -with open('../../examples/fir/coverage_results.xml', encoding='utf-8') as f: - xml_file = BytesIO(bytes(bytearray(f.read(), encoding='utf-8'))) - validate_ucis_xml(xml_file) From 4f76a32be2c09e4d6bc43113b17a5ab1d3ab5734 Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Thu, 26 May 2022 11:01:18 -0400 Subject: [PATCH 08/15] wip --- examples/fir/README.md | 6 ++++++ test/pyucis-fir/.gitignore | 1 + test/pyucis-fir/ucis_test.py | 4 ---- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 test/pyucis-fir/.gitignore diff --git a/examples/fir/README.md b/examples/fir/README.md index 63fa46a..26da1bb 100644 --- a/examples/fir/README.md +++ b/examples/fir/README.md @@ -1,5 +1,7 @@ # Build Instructions +These are the build instructions for using the example + ``` # export SYSTEMC_HOME="path to systemC release dir" $ make clean @@ -7,3 +9,7 @@ $ make $ make run ``` +# Test Instructions **(optional)** +Optionally test the output using the following instructions + + diff --git a/test/pyucis-fir/.gitignore b/test/pyucis-fir/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/test/pyucis-fir/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/test/pyucis-fir/ucis_test.py b/test/pyucis-fir/ucis_test.py index 5b68e5f..d9ee971 100644 --- a/test/pyucis-fir/ucis_test.py +++ b/test/pyucis-fir/ucis_test.py @@ -3,11 +3,8 @@ import unittest from validate_ucis_xml import validate_ucis -#from usr.local.google.home.davjohn.progs.fc4sc.test.pyucis-fir import ucis -#from google3.testing.pybase import googletest -#class UcisTest(googletest.TestCase): class UcisTest(unittest.TestCase): def test_validate_ucis_xml(self): @@ -16,5 +13,4 @@ def test_validate_ucis_xml(self): if __name__ == '__main__': - #googletest.main() unittest.main() From d4d82e3889752ff89aebe05b7094b4c0e13d9bd6 Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Thu, 26 May 2022 11:01:51 -0400 Subject: [PATCH 09/15] wip --- examples/fir/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/fir/README.md b/examples/fir/README.md index 26da1bb..e6180de 100644 --- a/examples/fir/README.md +++ b/examples/fir/README.md @@ -9,7 +9,7 @@ $ make $ make run ``` -# Test Instructions **(optional)** +# Test Instructions *(optional)* Optionally test the output using the following instructions From 637e879c8df1c3aad7847fa5ba403e46e8f27667 Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Thu, 26 May 2022 11:05:27 -0400 Subject: [PATCH 10/15] wip --- test/pyucis-fir/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 test/pyucis-fir/README.md diff --git a/test/pyucis-fir/README.md b/test/pyucis-fir/README.md new file mode 100644 index 0000000..bbd58d9 --- /dev/null +++ b/test/pyucis-fir/README.md @@ -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. + + From 41976e32ac9832931f36c34a4888ff59d8b81570 Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Thu, 26 May 2022 11:11:19 -0400 Subject: [PATCH 11/15] wip --- test/pyucis-fir/coverage_results.xml | 1 + test/pyucis-fir/validate_ucis_xml.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) create mode 120000 test/pyucis-fir/coverage_results.xml diff --git a/test/pyucis-fir/coverage_results.xml b/test/pyucis-fir/coverage_results.xml new file mode 120000 index 0000000..aa2dfab --- /dev/null +++ b/test/pyucis-fir/coverage_results.xml @@ -0,0 +1 @@ +../../examples/fir/coverage_results.xml \ No newline at end of file diff --git a/test/pyucis-fir/validate_ucis_xml.py b/test/pyucis-fir/validate_ucis_xml.py index eeba497..0727bf1 100644 --- a/test/pyucis-fir/validate_ucis_xml.py +++ b/test/pyucis-fir/validate_ucis_xml.py @@ -25,19 +25,20 @@ def validate_ucis(file_name): except: print("an exception occured") - return rc # TODO: fixme + return rc -#def main(argv: Sequence[str]) -> None: def main() -> None: - #if len(argv) > 1: - # raise app.UsageError('Too many command-line arguments.') - validate_ucis('../../examples/fir/coverage_results.xml') + rc = validate_ucis('../../examples/fir/coverage_results.xml') + return rc if __name__ == '__main__': -# app.run(main) - main() + rc = main() + if rc: + print("validation OK") + else: + print("validation Failure") From 6200e0374dab3dddfc336e479cb7d7c0bfeebdd7 Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Thu, 26 May 2022 11:11:19 -0400 Subject: [PATCH 12/15] adding makefile for test --- test/pyucis-fir/coverage_results.xml | 1 + test/pyucis-fir/validate_ucis_xml.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) create mode 120000 test/pyucis-fir/coverage_results.xml diff --git a/test/pyucis-fir/coverage_results.xml b/test/pyucis-fir/coverage_results.xml new file mode 120000 index 0000000..aa2dfab --- /dev/null +++ b/test/pyucis-fir/coverage_results.xml @@ -0,0 +1 @@ +../../examples/fir/coverage_results.xml \ No newline at end of file diff --git a/test/pyucis-fir/validate_ucis_xml.py b/test/pyucis-fir/validate_ucis_xml.py index eeba497..0727bf1 100644 --- a/test/pyucis-fir/validate_ucis_xml.py +++ b/test/pyucis-fir/validate_ucis_xml.py @@ -25,19 +25,20 @@ def validate_ucis(file_name): except: print("an exception occured") - return rc # TODO: fixme + return rc -#def main(argv: Sequence[str]) -> None: def main() -> None: - #if len(argv) > 1: - # raise app.UsageError('Too many command-line arguments.') - validate_ucis('../../examples/fir/coverage_results.xml') + rc = validate_ucis('../../examples/fir/coverage_results.xml') + return rc if __name__ == '__main__': -# app.run(main) - main() + rc = main() + if rc: + print("validation OK") + else: + print("validation Failure") From 9d0523fcf074d2af48c9a230a67771f3ad75cc1c Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Thu, 26 May 2022 11:57:43 -0400 Subject: [PATCH 13/15] complete makefile for test --- examples/fir/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/fir/Makefile b/examples/fir/Makefile index 32e97fe..b6995a9 100644 --- a/examples/fir/Makefile +++ b/examples/fir/Makefile @@ -47,11 +47,12 @@ main: $(OBJFILES) obj/%.o: %.cpp $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) $^ -o $@ -run: +run: main $(LDPATH) && ./$(EXEC) -test: +test: run $(MAKE) -C ../../test/pyucis-fir/ validate_fir clean: rm -rf obj $(EXEC) + rm coverage_results.xml From cea7a5b0eb6998a56df99c16c7e48e6c7463bde6 Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Fri, 17 Jun 2022 15:59:12 -0400 Subject: [PATCH 14/15] wip --- test/pyucis-fir/requirements.txt | 1 + tools/.gitignore | 1 + tools/VENV.md | 22 ++++++++++++++++++++++ tools/requirements.txt | 4 ++++ 4 files changed, 28 insertions(+) create mode 100644 tools/.gitignore create mode 100644 tools/VENV.md create mode 100644 tools/requirements.txt diff --git a/test/pyucis-fir/requirements.txt b/test/pyucis-fir/requirements.txt index 681040a..7a103cd 100644 --- a/test/pyucis-fir/requirements.txt +++ b/test/pyucis-fir/requirements.txt @@ -1,3 +1,4 @@ pyucis==0.0.5.20220416.1 pylint +pyyaml diff --git a/tools/.gitignore b/tools/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/tools/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/tools/VENV.md b/tools/VENV.md new file mode 100644 index 0000000..c5b5671 --- /dev/null +++ b/tools/VENV.md @@ -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 +``` diff --git a/tools/requirements.txt b/tools/requirements.txt new file mode 100644 index 0000000..7a103cd --- /dev/null +++ b/tools/requirements.txt @@ -0,0 +1,4 @@ +pyucis==0.0.5.20220416.1 +pylint +pyyaml + From 7dac8459ba63875e106733160a52848145dec94c Mon Sep 17 00:00:00 2001 From: "John F. Davis" Date: Tue, 28 Jun 2022 12:19:16 -0400 Subject: [PATCH 15/15] fix for coverpointbin type=ignore --- tools/coverage_report/.gitignore | 1 + tools/coverage_report/README.md | 6 +++ tools/coverage_report/report.py | 25 ++++++++----- tools/ucis_parser.py | 64 ++++++++++++++++++++++++-------- 4 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 tools/coverage_report/.gitignore create mode 100644 tools/coverage_report/README.md diff --git a/tools/coverage_report/.gitignore b/tools/coverage_report/.gitignore new file mode 100644 index 0000000..4264d97 --- /dev/null +++ b/tools/coverage_report/.gitignore @@ -0,0 +1 @@ +JFD/* diff --git a/tools/coverage_report/README.md b/tools/coverage_report/README.md new file mode 100644 index 0000000..a9075cc --- /dev/null +++ b/tools/coverage_report/README.md @@ -0,0 +1,6 @@ +# Usage + +``` +python3 report.py --xml_report foo.xml --yaml_out foo.yml +``` + diff --git a/tools/coverage_report/report.py b/tools/coverage_report/report.py index 7d950c1..c7a923e 100644 --- a/tools/coverage_report/report.py +++ b/tools/coverage_report/report.py @@ -4,7 +4,7 @@ import argparse import xml.etree.ElementTree as ET -sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +sys.path.append(os.path.join(os.path.dirname(__file__), '../')) from ucis_parser import UCIS_DB_Parser @@ -53,7 +53,9 @@ def get_covergroup_report_data(self, covergroupCoverage, module_data): def get_coverpoint_report_data(self, cgInstance, cg_cp_bin_map, cg_data): for coverpoint in self.findall_ucis_children(cgInstance, "coverpoint"): + print("coverpoint is ", coverpoint) options = self.find_ucis_element(coverpoint, 'options') + print("JFD options is ", options) cp_name = coverpoint.get('name') cp_data = { 'item_type' : 'point', @@ -78,7 +80,11 @@ def get_coverpoint_report_data(self, cgInstance, cg_cp_bin_map, cg_data): else: cp_data['bin_misses'] += 1 cp_data['misses'].append(bin_name) - cp_data['pct_cov'] = 100 * ((cp_data['bin_count'] - cp_data['bin_misses']) / float(cp_data['bin_count'])) + if cp_data['bin_count'] == 0: + print('should not happen. get_coverpoint_report_data() cp_data["bin_count"] is zero') + print('skip') + else: + cp_data['pct_cov'] = 100 * ((cp_data['bin_count'] - cp_data['bin_misses']) / float(cp_data['bin_count'])) def collect_cross_bins(self, exprs, cg_cp_bin_map, parrent_bins): expr_name = exprs[0].text @@ -95,7 +101,6 @@ def get_cross_bin_name_from_tuple(self, cg_cp_bin_map, exprs, bin_tuple): names = [] for expr_idx, bin_idx in enumerate(bin_tuple): expr_name = exprs[expr_idx].text - #expr_bin_name = "%s(%s)" % (expr_name, cg_cp_bin_map[expr_name][bin_idx]) expr_bin_name = cg_cp_bin_map[expr_name][bin_idx] names.append(expr_bin_name) names.reverse() @@ -126,7 +131,6 @@ def get_cross_report_data(self, cgInstance, cg_cp_bin_map, cg_data): for cbin in all_cross_bins: bin_hits[cbin] = 0 - # for bin_idx, bin in enumerate(self.findall_ucis_children(cross, "crossBin")): bin_name = bin.get('name') cg_cp_bin_map[cr_name][bin_idx] = bin_name @@ -144,7 +148,10 @@ def get_cross_report_data(self, cgInstance, cg_cp_bin_map, cg_data): else: cr_data['bin_misses'] += 1 cr_data['misses'].append(self.get_cross_bin_name_from_tuple(cg_cp_bin_map, exprs, bin_tuple)) - cr_data['pct_cov'] = 100 * ((cr_data['bin_count'] - cr_data['bin_misses']) / float(cr_data['bin_count'])) + if cr_data['bin_count'] == 0: + print('JFD in get_cross_report_data() cr_data["bin_count"] is zero') + else: + cr_data['pct_cov'] = 100 * ((cr_data['bin_count'] - cr_data['bin_misses']) / float(cr_data['bin_count'])) args = {} @@ -201,12 +208,12 @@ def reduce_to_cg_inst_summary(db): args = parser.parse_args() parser = UCIS_DB_Reporter() - + if not args.xml_report: raise ValueError("No input XML provided!") if not args.yaml_out: raise ValueError("No output YAML name provided!") - + try: d = parser.get_report_data(args.xml_report) except IOError as e: @@ -224,9 +231,9 @@ def reduce_to_cg_inst_summary(db): if not args.quiet: print(""" Overall Summary: - + Total Coverage: %6.2f - + Module Summary: """ % (yaml_db['pct_cov'])) diff --git a/tools/ucis_parser.py b/tools/ucis_parser.py index 6b58b40..a3f8310 100644 --- a/tools/ucis_parser.py +++ b/tools/ucis_parser.py @@ -22,27 +22,27 @@ | | from : start value of the interval | | to : end value of the interval | | - | -> contents + | -> contents | | coverageCount : the number of hits registered in this interval | 0 - | + | -> cross [0:n] | name : name of the cross | -> crossBin [0:n] | name : name of the cross bin - | + | + -> index -> index - -> index . . Number of indexes = number of crossed coverpoints . - -> index - | - -> contents + -> index + | + -> contents | coverageCount : the number of hits registered in this cross bin - 0 - + 0 + Note that this only contains the elements which are relevant for merging! """ class UCIS_DB_Parser: @@ -70,13 +70,45 @@ def __init__(self): # the master ucis DB which will be "merged" into when parsing additional DBs self.mergeDBtree = None self.mergeDBroot = None - + def find_ucis_element(self, element, subElementName): - return element.find('{0}:{1}'.format(self.ucis_ns, subElementName), self.ns_map) - + e = element.find('{0}:{1}'.format(self.ucis_ns, subElementName), self.ns_map) + if "coverpointBin" in e.tag: + if e.attrib['type'] == 'default' or e.attrib['type'] == 'illegal': + # its valid + return e + else: + # its not. Its 'ignore'. Ignore it. + return None + else: + # its something other than a coverpointBin + return e + + def findall_ucis_children(self, element, subElementName): - return element.findall('{0}:{1}'.format(self.ucis_ns, subElementName), self.ns_map) - + # instead of returning all, use the iterator form, check for the ones + # which are of tag type "coverpointBin", then examine the attribute + # to see if its default. If it is, include in results, otherwise + # ignore. + an_iter = element.iterfind('{0}:{1}'.format(self.ucis_ns, subElementName), self.ns_map) + a_filtered_list = [] + for e in an_iter: + if "coverpointBin" in e.tag: + # this element is a coverpointBin, which can be of type: Default, + # Ignore, or Illegal. Only return elements which are of type + # Default or illegal?. + if e.attrib['type'] == 'default' or e.attrib['type'] == 'illegal': + # its valid + a_filtered_list.append(e) + else: + # its not. Its 'ignore'. Ignore it. + print('\t{} is not of type="default", ignoring.'.format(e.attrib['name'])) + else: + # its something other than a coverpointBin + a_filtered_list.append(e) + + return a_filtered_list + # formats an XPath ElementTree query to search for a specified element name # and an optional attribute name together with a certain attribute value def format_et_query(self, elementName, attribName = None, attribValue = None): @@ -84,8 +116,8 @@ def format_et_query(self, elementName, attribName = None, attribValue = None): if attribName is not None and attribValue is not None: query += "[@{0}='{1}']".format(attribName, attribValue) return query - + # searches and returns the first match of the XPath query in the mergeDBtree def find_merge_element_by_query(self, xpath_query): return self.mergeDBtree.find(xpath_query, self.ns_map) - \ No newline at end of file +