xiaoxiang781216 commented on code in PR #15268:
URL: https://github.com/apache/nuttx/pull/15268#discussion_r1890385468


##########
tools/gcov.py:
##########
@@ -18,11 +18,62 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
+import argparse
 import os
-import sys
+import re
 import shutil
-import argparse
 import subprocess
+import sys
+
+
+def parse_gcda_data(input_file):
+    with open(input_file, "r") as file:
+        lines = file.read().strip().splitlines()
+
+    for line in lines:
+        if not line.startswith("gcov start"):
+            continue
+
+        match = re.search(r"filename:(.*?)\s+size:\s*(\d+)Byte", line)
+        if not match:
+            continue
+
+        hex_dump = ""
+        filename = match.group(1)
+        size = int(match.group(2))
+
+        # Read the hex dump until the end of the file
+        next_line_index = lines.index(line) + 1
+        while next_line_index < len(lines) and not 
lines[next_line_index].startswith(
+            "gcov end"
+        ):
+            hex_dump += lines[next_line_index].strip()
+            next_line_index += 1
+
+        if size != len(hex_dump) // 2:
+            print(
+                f"Size mismatch for {filename}: expected {size} bytes, got 
{len(hex_dump) // 2} bytes"
+            )
+
+        checksum_match = (

Review Comment:
   match



##########
tools/gcov.py:
##########
@@ -18,11 +18,62 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
+import argparse
 import os
-import sys
+import re
 import shutil
-import argparse
 import subprocess
+import sys
+
+
+def parse_gcda_data(input_file):
+    with open(input_file, "r") as file:
+        lines = file.read().strip().splitlines()
+
+    for line in lines:
+        if not line.startswith("gcov start"):
+            continue
+
+        match = re.search(r"filename:(.*?)\s+size:\s*(\d+)Byte", line)
+        if not match:
+            continue
+
+        hex_dump = ""
+        filename = match.group(1)
+        size = int(match.group(2))
+
+        # Read the hex dump until the end of the file
+        next_line_index = lines.index(line) + 1
+        while next_line_index < len(lines) and not 
lines[next_line_index].startswith(
+            "gcov end"
+        ):
+            hex_dump += lines[next_line_index].strip()
+            next_line_index += 1
+
+        if size != len(hex_dump) // 2:
+            print(
+                f"Size mismatch for {filename}: expected {size} bytes, got 
{len(hex_dump) // 2} bytes"
+            )
+
+        checksum_match = (
+            re.search(r"checksum:\s*(0x[0-9a-fA-F]+)", lines[next_line_index])
+            if next_line_index < len(lines)
+            else None
+        )
+        if not checksum_match:
+            continue
+
+        checksum = int(checksum_match.group(1), 16)
+        calculated_checksum = sum(bytearray.fromhex(hex_dump)) % 65536
+        if calculated_checksum != checksum:

Review Comment:
   if checksum!= int(checksum_match.group(1), 16):



##########
tools/gcov.py:
##########
@@ -18,11 +18,62 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
+import argparse
 import os
-import sys
+import re
 import shutil
-import argparse
 import subprocess
+import sys
+
+
+def parse_gcda_data(input_file):
+    with open(input_file, "r") as file:
+        lines = file.read().strip().splitlines()
+
+    for line in lines:
+        if not line.startswith("gcov start"):
+            continue
+
+        match = re.search(r"filename:(.*?)\s+size:\s*(\d+)Byte", line)
+        if not match:
+            continue
+
+        hex_dump = ""
+        filename = match.group(1)
+        size = int(match.group(2))
+
+        # Read the hex dump until the end of the file
+        next_line_index = lines.index(line) + 1
+        while next_line_index < len(lines) and not 
lines[next_line_index].startswith(
+            "gcov end"
+        ):
+            hex_dump += lines[next_line_index].strip()
+            next_line_index += 1
+
+        if size != len(hex_dump) // 2:
+            print(
+                f"Size mismatch for {filename}: expected {size} bytes, got 
{len(hex_dump) // 2} bytes"
+            )
+
+        checksum_match = (
+            re.search(r"checksum:\s*(0x[0-9a-fA-F]+)", lines[next_line_index])
+            if next_line_index < len(lines)
+            else None
+        )
+        if not checksum_match:
+            continue
+
+        checksum = int(checksum_match.group(1), 16)
+        calculated_checksum = sum(bytearray.fromhex(hex_dump)) % 65536

Review Comment:
   checksum



##########
tools/gcov.py:
##########
@@ -18,11 +18,62 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
+import argparse
 import os
-import sys
+import re
 import shutil
-import argparse
 import subprocess
+import sys
+
+
+def parse_gcda_data(input_file):

Review Comment:
   filename



##########
tools/gcov.py:
##########
@@ -18,11 +18,62 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
+import argparse
 import os
-import sys
+import re
 import shutil
-import argparse
 import subprocess
+import sys
+
+
+def parse_gcda_data(input_file):
+    with open(input_file, "r") as file:
+        lines = file.read().strip().splitlines()
+
+    for line in lines:
+        if not line.startswith("gcov start"):
+            continue
+
+        match = re.search(r"filename:(.*?)\s+size:\s*(\d+)Byte", line)
+        if not match:
+            continue
+
+        hex_dump = ""

Review Comment:
   dump



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to