[rtems-central commit] testoutputparser: Support gcov info hash

Sebastian Huber sebh at rtems.org
Tue Nov 28 13:05:16 UTC 2023


Module:    rtems-central
Branch:    master
Commit:    15f04b0d3c63eaf86594e8aa36ce8da8d35aabac
Changeset: http://git.rtems.org/rtems-central/commit/?id=15f04b0d3c63eaf86594e8aa36ce8da8d35aabac

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Nov 27 14:50:59 2023 +0100

testoutputparser: Support gcov info hash

---

 rtemsspec/testoutputparser.py            | 32 +++++++++++++++++++++++++++-----
 rtemsspec/tests/test_testoutputparser.py |  7 ++++++-
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/rtemsspec/testoutputparser.py b/rtemsspec/testoutputparser.py
index aca35505..c18fa9c8 100644
--- a/rtemsspec/testoutputparser.py
+++ b/rtemsspec/testoutputparser.py
@@ -71,6 +71,7 @@ _M_D = re.compile(r"M:D:(.+)")
 
 _GCOV_BEGIN = "*** BEGIN OF GCOV INFO BASE64 ***"
 _GCOV_END = "*** END OF GCOV INFO BASE64 ***"
+_GCOV_HASH = re.compile(r"\*\*\* GCOV INFO SHA256 (.*) \*\*\*")
 
 _RECORDS_BEGIN = "*** BEGIN OF RECORDS BASE64 ***"
 _RECORDS_END = "*** END OF RECORDS BASE64 ***"
@@ -117,6 +118,16 @@ class TestOutputParser:
     def _hash_sha256(self, line: str) -> None:
         self._hash_state.update(f"{line}\n".encode("ascii"))
 
+    def _hash_sha256_skip_one(self, line: str) -> None:
+        # pylint: disable=unused-argument
+        self.hash_line = self._hash_sha256
+
+    def _hash_finalize(self) -> str:
+        self.hash_line = self._hash_none
+        digest = base64.urlsafe_b64encode(
+            self._hash_state.digest()).decode("ascii")
+        return digest
+
     def _test_begin(self, index: int, line: str) -> bool:
         mobj = _TEST_BEGIN.match(line)
         if mobj:
@@ -201,6 +212,7 @@ class TestOutputParser:
                 "test-cases": []
             }
             self.consume = self._test_suite_platform
+            self._hash_state = hashlib.sha256()
             self.hash_line = self._hash_sha256
             return True
         return self._extra(index, line)
@@ -503,14 +515,11 @@ class TestOutputParser:
     def _report_hash(self, index: int, line: str) -> bool:
         mobj = _TS_REPORT_HASH.match(line)
         if mobj:
-            digest = base64.urlsafe_b64encode(
-                self._hash_state.digest()).decode("ascii")
-            self._hash_state = hashlib.sha256()
-            self.data["test-suite"]["report-hash-calculated"] = digest
+            self.data["test-suite"][
+                "report-hash-calculated"] = self._hash_finalize()
             self.data["test-suite"]["report-hash"] = mobj.group(1)
             self.data["test-suite"]["line-report-hash"] = index
             self.consume = self._test_body
-            self.hash_line = self._hash_none
             return True
         return self._extra(index, line)
 
@@ -519,12 +528,15 @@ class TestOutputParser:
             self.level += 1
             self.data["line-gcov-info-base64-begin"] = index
             self.consume = self._gcov_end
+            self._hash_state = hashlib.sha256()
+            self.hash_line = self._hash_sha256_skip_one
             return True
         return False
 
     def _gcov_end(self, index: int, line: str) -> bool:
         if line in _GCOV_END:
             self.level -= 1
+            self.data["gcov-info-hash-calculated"] = self._hash_finalize()
             self.data["line-gcov-info-base64-end"] = index
             self.data["data-ranges"].append(
                 (self.data["line-gcov-info-base64-begin"] + 1, index))
@@ -532,6 +544,14 @@ class TestOutputParser:
             return True
         return False
 
+    def _gcov_hash(self, index: int, line: str) -> bool:
+        mobj = _GCOV_HASH.match(line)
+        if mobj:
+            self.data["gcov-info-hash"] = mobj.group(1)
+            self.data["line-gcov-info-hash"] = index
+            return True
+        return False
+
     def _records_begin(self, index: int, line: str) -> bool:
         if line in _RECORDS_BEGIN:
             self.level += 1
@@ -571,6 +591,8 @@ class TestOutputParser:
     def _extra(self, index: int, line: str) -> bool:
         if self._gcov_begin(index, line):
             return True
+        if self._gcov_hash(index, line):
+            return True
         if self._records_begin(index, line):
             return True
         if self._records_zlib_begin(index, line):
diff --git a/rtemsspec/tests/test_testoutputparser.py b/rtemsspec/tests/test_testoutputparser.py
index 0ac7ea85..d867c61a 100644
--- a/rtemsspec/tests/test_testoutputparser.py
+++ b/rtemsspec/tests/test_testoutputparser.py
@@ -59,7 +59,8 @@ _OUTPUT = [
     "", "*** BEGIN OF RECORDS BASE64 ZLIB ***",
     "bmZjZ1I0MEKUAAAAL29wdC9ydGVtcy9ydGVtcy02LXNhZmVzdC0xL2J1aWxkL2JzcC1xdWFsLW9u",
     "AAAAOi+8CuS72SFYlu6BAAChAcD///8AAAAA",
-    "*** END OF RECORDS BASE64 ZLIB ***"
+    "*** END OF RECORDS BASE64 ZLIB ***", "",
+    "*** GCOV INFO SHA256 y-0n6RjPnOwLUxXEKlPzx_g92tNGWHSzta_WYyGe5-g= ***"
 ]
 
 _INCOMPLETE_TEST_SUITE = {
@@ -294,9 +295,13 @@ def _report(t_begin: int = 0,
             error: int = -1) -> None:
     report = {
         "data-ranges": _data_ranges(data_begin + 1),
+        "gcov-info-hash": "y-0n6RjPnOwLUxXEKlPzx_g92tNGWHSzta_WYyGe5-g=",
+        "gcov-info-hash-calculated":
+        "y-0n6RjPnOwLUxXEKlPzx_g92tNGWHSzta_WYyGe5-g=",
         "info": _info(t_begin, t_end),
         "line-gcov-info-base64-begin": data_begin,
         "line-gcov-info-base64-end": data_begin + 3,
+        "line-gcov-info-hash": data_begin + 13,
         "line-records-base64-begin": data_begin + 4,
         "line-records-base64-end": data_begin + 7,
         "line-records-base64-zlib-begin": data_begin + 8,



More information about the vc mailing list