check_test_cases.py: support checking test coverage in compat.sh

Test case description in compat.sh is in format of
    [ogm]->[ogm] TLSmode, VERIFY CIPHERSUITE_NAME

This program calls compat.sh to list all potential test case
descriptions then checks test case duplication.

Signed-off-by: Yanray Wang <yanray.wang@arm.com>
diff --git a/tests/scripts/check_test_cases.py b/tests/scripts/check_test_cases.py
index c9f5e11..86506f5 100755
--- a/tests/scripts/check_test_cases.py
+++ b/tests/scripts/check_test_cases.py
@@ -25,6 +25,7 @@
 import glob
 import os
 import re
+import subprocess
 import sys
 
 class Results:
@@ -111,6 +112,24 @@
                 self.process_test_case(descriptions,
                                        file_name, line_number, description)
 
+    def walk_compat_sh(self, file_name):
+        """Iterate over the test cases compat.sh with a similar format."""
+        descriptions = self.new_per_file_state() # pylint: disable=assignment-from-none
+        compat_cmd = ['sh', file_name, '--list-test-case']
+        result = subprocess.run(compat_cmd,
+                                stdout=subprocess.PIPE,
+                                check=False)
+        if result.returncode != 0:
+            print(*compat_cmd, 'returned', str(result.returncode))
+            return
+        else:
+            # Pattern: g->m dtls12,no TLS_DHE_PSK_WITH_AES_128_CBC_SHA\n
+            m = re.findall(br'[^ogm]*((?:[ogm]->[ogm]\s*\w*.\w*\s\w*)*)\n',
+                           result.stdout)
+            if m:
+                for i in m:
+                    self.process_test_case(descriptions, file_name, 1, i)
+
     @staticmethod
     def collect_test_directories():
         """Get the relative path for the TLS and Crypto test directories."""
@@ -133,6 +152,9 @@
             ssl_opt_sh = os.path.join(directory, 'ssl-opt.sh')
             if os.path.exists(ssl_opt_sh):
                 self.walk_ssl_opt_sh(ssl_opt_sh)
+            compat_sh = os.path.join(directory, 'compat.sh')
+            if os.path.exists(compat_sh):
+                self.walk_compat_sh(compat_sh)
 
 class TestDescriptions(TestDescriptionExplorer):
     """Collect the available test cases."""