Allow internal macros without prefix

Internal macros are not present as symbols, visible or usable outside
the compilation unit and it is safe to allow them to have a name without
namespace prefix.

We also allow them to start with lower case letters as some of our
internal macros already have names like that.

Signed-off-by: Janos Follath <janos.follath@arm.com>
diff --git a/tests/scripts/check_names.py b/tests/scripts/check_names.py
index 96117a2..1d87f26 100755
--- a/tests/scripts/check_names.py
+++ b/tests/scripts/check_names.py
@@ -58,8 +58,9 @@
 
 # Naming patterns to check against. These are defined outside the NameCheck
 # class for ease of modification.
-MACRO_PATTERN = r"^(MBEDTLS|PSA)_[0-9A-Z_]*[0-9A-Z]$"
-CONSTANTS_PATTERN = MACRO_PATTERN
+PUBLIC_MACRO_PATTERN = r"^(MBEDTLS|PSA)_[0-9A-Z_]*[0-9A-Z]$"
+INTERNAL_MACRO_PATTERN = r"^[0-9A-Za-z_]*[0-9A-Z]$"
+CONSTANTS_PATTERN = PUBLIC_MACRO_PATTERN
 IDENTIFIER_PATTERN = r"^(mbedtls|psa)_[0-9a-z_]*[0-9a-z]$"
 
 class Match(): # pylint: disable=too-few-public-methods
@@ -249,14 +250,17 @@
             .format(str(self.excluded_files))
         )
 
-        all_macros = self.parse_macros([
+        all_macros = {"public": [], "internal": []}
+        all_macros["public"] = self.parse_macros([
             "include/mbedtls/*.h",
             "include/psa/*.h",
-            "library/*.h",
-            "tests/include/test/drivers/*.h",
             "3rdparty/everest/include/everest/everest.h",
             "3rdparty/everest/include/everest/x25519.h"
         ])
+        all_macros["internal"] = self.parse_macros([
+            "library/*.h",
+            "tests/include/test/drivers/*.h",
+        ])
         enum_consts = self.parse_enum_consts([
             "include/mbedtls/*.h",
             "library/*.h",
@@ -284,20 +288,25 @@
 
         # Remove identifier macros like mbedtls_printf or mbedtls_calloc
         identifiers_justname = [x.name for x in identifiers]
-        actual_macros = []
-        for macro in all_macros:
-            if macro.name not in identifiers_justname:
-                actual_macros.append(macro)
+        actual_macros = {"public": [], "internal": []}
+        for scope in actual_macros:
+            for macro in all_macros[scope]:
+                if macro.name not in identifiers_justname:
+                    actual_macros[scope].append(macro)
 
         self.log.debug("Found:")
         # Aligns the counts on the assumption that none exceeds 4 digits
-        self.log.debug("  {:4} Total Macros".format(len(all_macros)))
-        self.log.debug("  {:4} Non-identifier Macros".format(len(actual_macros)))
+        for scope in actual_macros:
+            self.log.debug("  {:4} Total {} Macros"
+                            .format(len(all_macros[scope]), scope))
+            self.log.debug("  {:4} {} Non-identifier Macros"
+                            .format(len(actual_macros[scope]), scope))
         self.log.debug("  {:4} Enum Constants".format(len(enum_consts)))
         self.log.debug("  {:4} Identifiers".format(len(identifiers)))
         self.log.debug("  {:4} Exported Symbols".format(len(symbols)))
         return {
-            "macros": actual_macros,
+            "public_macros": actual_macros["public"],
+            "internal_macros": actual_macros["internal"],
             "enum_consts": enum_consts,
             "identifiers": identifiers,
             "symbols": symbols,
@@ -741,7 +750,8 @@
         problems += self.check_symbols_declared_in_header()
 
         pattern_checks = [
-            ("macros", MACRO_PATTERN),
+            ("public_macros", PUBLIC_MACRO_PATTERN),
+            ("internal_macros", INTERNAL_MACRO_PATTERN),
             ("enum_consts", CONSTANTS_PATTERN),
             ("identifiers", IDENTIFIER_PATTERN)
         ]
@@ -825,7 +835,10 @@
         all_caps_names = {
             match.name
             for match
-            in self.parse_result["macros"] + self.parse_result["enum_consts"]}
+            in self.parse_result["public_macros"] +
+               self.parse_result["internal_macros"] +
+               self.parse_result["enum_consts"]
+            }
         typo_exclusion = re.compile(r"XXX|__|_$|^MBEDTLS_.*CONFIG_FILE$|"
                                     r"MBEDTLS_TEST_LIBTESTDRIVER*")