sw:vec:test_runner: Add instruction count into test runner script

Collect e2e instruction count in the test_runner script so the info can
be collected by dashboard

Change-Id: I61423b345c94ba9c8203cd0f9a22ece3b471c5b9
diff --git a/scripts/test_runner.py b/scripts/test_runner.py
index 383b384..3650cbb 100755
--- a/scripts/test_runner.py
+++ b/scripts/test_runner.py
@@ -45,6 +45,8 @@
             "ReadByte from non existing peripheral",
             "File does not exist"
         ]
+        # stats collected command for renode
+        self.renode_end_command = None
 
     def run(self, timeout=1000):
         """ Run the simulation command and quit the simulation."""
@@ -66,6 +68,9 @@
             exc = pexpect.exceptions.EOF(message)
             exc.__cause__ = None
             raise exc from run_hit_timeout
+        if self.renode_end_command:
+            self.child.send(self.renode_end_command)
+            self.child.expect("(springbok)", timeout=timeout)
         self.child.send("\nq\n")
         self.child.expect(pexpect.EOF, timeout=timeout)
         self.child.close()
@@ -125,6 +130,7 @@
         ]
         self.renode_simulator_cmd = " ".join(self.renode_args)
         super().__init__(self.renode_simulator_cmd)
+        self.renode_end_command = "\nsysbus.cpu2 ExecutedInstructions\n"
 
     def run(self, timeout=120):
         file_desc, script_path = tempfile.mkstemp(suffix=".resc")
@@ -172,10 +178,21 @@
 }
 
 def cleanup_message(message: str) -> str:
-    """ Clean up the message to get rid of the non-ascii code generated by
-    Mono. """
+    """ Clean up the message generated by Mono.
+
+    The non-ascii code generated by Mono.
+
+    Convert the opcode count from hex to decimal.
+    """
     ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
     output = ansi_escape.sub("", message)
+    op_count_out = re.compile(
+        r"(?P<op_count>0x[0-9A-Fa-f]+)\r\r\r\n\(springbok\)")
+    op_count = op_count_out.search(output)
+    if op_count:
+        op_count = int(op_count.group(1), 16)
+        output = op_count_out.sub(
+            f"Renode total instruction count: {op_count}\n", output)
     return output
 
 def main():