Implement bash script for testing

Added formatting functions to translate_ciphersuite.py to take a string
of multiple ciphersuite names, in the current compat.sh and output the
translated ciphersuite names in the same format

Created test_translate.sh which uses samples from compat.sh to compare
against the translated versions to ensure the translations are produced
in the correct format

Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
diff --git a/test_translate.py b/test_translate.py
old mode 100644
new mode 100755
diff --git a/test_translate.sh b/test_translate.sh
new file mode 100755
index 0000000..43b7ff4
--- /dev/null
+++ b/test_translate.sh
@@ -0,0 +1,113 @@
+#!/bin/sh
+
+# Ciphers that will use translate_ciphers.py
+M_CIPHERS=""
+O_CIPHERS=""
+G_CIPHERS=""
+
+# Ciphers taken directly from compat.sh
+Mt_CIPHERS=""
+Ot_CIPHERS=""
+Gt_CIPHERS=""
+
+# Initial list to be split into 3
+CIPHERS="TLS-ECDHE-ECDSA-WITH-NULL-SHA      \
+    TLS-ECDHE-ECDSA-WITH-3DES-EDE-CBC-SHA   \
+    TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA    \
+    TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA    \
+    "
+
+M_CIPHERS="$M_CIPHERS                       \
+           $CIPHERS"
+                
+G=`python3 translate_ciphers.py g "$CIPHERS"`
+G_CIPHERS="$G_CIPHERS                       \
+           $G"
+
+O=`python3 translate_ciphers.py o "$CIPHERS"`
+O_CIPHERS="$O_CIPHERS                       \
+           $O"
+
+Mt_CIPHERS="$Mt_CIPHERS                       \
+    TLS-ECDHE-ECDSA-WITH-NULL-SHA           \
+    TLS-ECDHE-ECDSA-WITH-3DES-EDE-CBC-SHA   \
+    TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA    \
+    TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA    \
+    "
+Gt_CIPHERS="$Gt_CIPHERS                       \
+    +ECDHE-ECDSA:+NULL:+SHA1                \
+    +ECDHE-ECDSA:+3DES-CBC:+SHA1            \
+    +ECDHE-ECDSA:+AES-128-CBC:+SHA1         \
+    +ECDHE-ECDSA:+AES-256-CBC:+SHA1         \
+    "
+Ot_CIPHERS="$Ot_CIPHERS               \
+    ECDHE-ECDSA-NULL-SHA            \
+    ECDHE-ECDSA-DES-CBC3-SHA        \
+    ECDHE-ECDSA-AES128-SHA          \
+    ECDHE-ECDSA-AES256-SHA          \
+    "
+
+
+# Initial list to be split into 3
+CIPHERS="TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256         \
+          TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384         \
+          TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256         \
+          TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384         \
+         "
+
+M_CIPHERS="$M_CIPHERS                       \
+           $CIPHERS"
+
+G=`python3 translate_ciphers.py g "$CIPHERS"`
+G_CIPHERS="$G_CIPHERS                       \
+           $G"
+
+O=`python3 translate_ciphers.py o "$CIPHERS"`
+O_CIPHERS="$O_CIPHERS                       \
+           $O"
+
+Mt_CIPHERS="$Mt_CIPHERS                               \
+    TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256         \
+    TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384         \
+    TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256         \
+    TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384         \
+    "
+Gt_CIPHERS="$Gt_CIPHERS                               \
+    +ECDHE-ECDSA:+AES-128-CBC:+SHA256               \
+    +ECDHE-ECDSA:+AES-256-CBC:+SHA384               \
+    +ECDHE-ECDSA:+AES-128-GCM:+AEAD                 \
+    +ECDHE-ECDSA:+AES-256-GCM:+AEAD                 \
+    "
+Ot_CIPHERS="$Ot_CIPHERS               \
+    ECDHE-ECDSA-AES128-SHA256       \
+    ECDHE-ECDSA-AES256-SHA384       \
+    ECDHE-ECDSA-AES128-GCM-SHA256   \
+    ECDHE-ECDSA-AES256-GCM-SHA384   \
+    "
+
+# Normalise spacing
+M_CIPHERS=$( echo "$M_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//')
+G_CIPHERS=$( echo "$G_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//')
+O_CIPHERS=$( echo "$O_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//')
+
+Mt_CIPHERS=$( echo "$Mt_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//')
+Gt_CIPHERS=$( echo "$Gt_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//')
+Ot_CIPHERS=$( echo "$Ot_CIPHERS" | sed -e 's/[[:space:]][[:space:]]*/ /g' -e 's/^ //' -e 's/ $//')
+
+# Compare the compat.sh names with the translated names
+# Upon fail, print them to view the differences
+if [ "$Mt_CIPHERS" != "$M_CIPHERS" ]
+then
+    echo "MBED Translated:   $M_CIPHERS"
+    echo "MBED Original:     $Mt_CIPHERS"
+fi
+if [ "$Gt_CIPHERS" != "$G_CIPHERS" ]
+then
+    echo "GNU Translated:    $G_CIPHERS"
+    echo "GNU Original:      $Gt_CIPHERS"
+fi
+if [ "$Ot_CIPHERS" != "$O_CIPHERS" ]
+then
+    echo "OpenSSL Translated: $O_CIPHERS"
+    echo "OpenSSL Original:   $Ot_CIPHERS"
+fi
\ No newline at end of file
diff --git a/translate_ciphers.py b/translate_ciphers.py
old mode 100644
new mode 100755
index e17d41c..b9a2d53
--- a/translate_ciphers.py
+++ b/translate_ciphers.py
@@ -1,4 +1,5 @@
 import re
+import sys
 
 def translate_gnu(m_cipher):
     # Remove "TLS-"
@@ -64,3 +65,34 @@
         m_cipher = m_cipher.replace("DHE", "EDH")
 
     return m_cipher
+
+def format_g(m_ciphers):
+    #ciphers = (re.findall(r"TLS-.+\s*\\", m_ciphers))
+    m_ciphers = m_ciphers.split()
+    g_ciphers = []
+    for i in m_ciphers:
+        g_ciphers.append(translate_gnu(i))
+    return " ".join(g_ciphers)
+
+def format_o(m_ciphers):
+    m_ciphers = m_ciphers.split()
+    o_ciphers = []
+    for i in m_ciphers:
+        o_ciphers.append(translate_ossl(i))
+    return " ".join(o_ciphers)
+
+def main():
+    # print command line arguments
+    if len(sys.argv) <= 2:
+        exit(1)
+    if sys.argv[1] == "g":
+        print(format_g(sys.argv[2]))
+        exit(0)
+    elif sys.argv[1] == "o":
+        print(format_o(sys.argv[2]))
+        exit(0)
+    else: 
+        exit(1)
+
+if __name__ == "__main__":
+    main()
\ No newline at end of file