check_test_cases: Unify walk_compat_sh and walk_opt_sh into one
walk_compat_sh and walk_opt_sh are basically the same now, so:
* Merge them into one function.
* Use the --list-test-cases option for both of them.
* Rename this merged function as collect_from_script which seems
more appropriate as since it isn't iterating the script but
calling it.
Signed-off-by: Tomás González <tomasagustin.gonzalezorlando@arm.com>
diff --git a/tests/compat.sh b/tests/compat.sh
index 6506e6c..570c8e8 100755
--- a/tests/compat.sh
+++ b/tests/compat.sh
@@ -127,7 +127,7 @@
printf " \tAlso available: GnuTLS (needs v3.2.15 or higher)\n"
printf " -M|--memcheck\tCheck memory leaks and errors.\n"
printf " -v|--verbose\tSet verbose output.\n"
- printf " --list-test-case\tList all potential test cases (No Execution)\n"
+ printf " -l|--list-test-cases\tList all potential test cases (No Execution)\n"
printf " --outcome-file\tFile where test outcomes are written\n"
printf " \t(default: \$MBEDTLS_TEST_OUTCOME_FILE, none if empty)\n"
printf " --preserve-logs\tPreserve logs of successful tests as well\n"
@@ -191,8 +191,8 @@
MEMCHECK=1
;;
# Please check scripts/check_test_cases.py correspondingly
- # if you have to modify option, --list-test-case
- --list-test-case)
+ # if you have to modify option, --list-test-cases
+ --list-test-cases)
list_test_case
exit $?
;;
@@ -869,7 +869,7 @@
}
# uniform_title <CLIENT> <SERVER> <STANDARD_CIPHER_SUITE>
-# $TITLE is considered as test case description for both --list-test-case and
+# $TITLE is considered as test case description for both --list-test-cases and
# MBEDTLS_TEST_OUTCOME_FILE. This function aims to control the format of
# each test case description.
uniform_title() {
diff --git a/tests/scripts/check_test_cases.py b/tests/scripts/check_test_cases.py
index 4301b32..2dddf7a 100755
--- a/tests/scripts/check_test_cases.py
+++ b/tests/scripts/check_test_cases.py
@@ -27,7 +27,6 @@
import re
import subprocess
import sys
-import subprocess
class Results:
@@ -99,26 +98,18 @@
data_file_name, line_number, line)
in_paragraph = True
- def walk_ssl_opt_sh(self, file_name):
- """Iterate over the test cases in ssl-opt.sh or a file with a similar format."""
+ def collect_from_script(self, file_name):
+ """Collect the test cases in a script by calling its listing test cases
+option"""
descriptions = self.new_per_file_state() # pylint: disable=assignment-from-none
- listed = subprocess.check_output([file_name, '-l'])
+ listed = subprocess.check_output(['sh', file_name, '--list-test-cases'])
+ # Assume test file is responsible for printing identical format of
+ # test case description between --list-test-cases and its OUTCOME.CSV
listed = set(map(lambda x: x.rstrip(), listed.splitlines()))
- for description in listed:
- self.process_test_case(descriptions, file_name, None, 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']
- compat_output = subprocess.check_output(compat_cmd)
- # Assume compat.sh is responsible for printing identical format of
- # test case description between --list-test-case and its OUTCOME.CSV
- description = compat_output.strip().split(b'\n')
# idx indicates the number of test case since there is no line number
# in `compat.sh` for each test case.
- for idx, descrip in enumerate(description):
- self.process_test_case(descriptions, file_name, idx, descrip)
+ for idx, description in enumerate(listed):
+ self.process_test_case(descriptions, file_name, idx, description)
@staticmethod
def collect_test_directories():
@@ -139,12 +130,11 @@
for data_file_name in glob.glob(os.path.join(directory, 'suites',
'*.data')):
self.walk_test_suite(data_file_name)
- 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)
+
+ for sh_file in ['ssl-opt.sh', 'compat.sh']:
+ sh_file = os.path.join(directory, sh_file)
+ if os.path.exists(sh_file):
+ self.collect_from_script(sh_file)
class TestDescriptions(TestDescriptionExplorer):
"""Collect the available test cases."""
diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh
index de4c83a..04be26f 100755
--- a/tests/ssl-opt.sh
+++ b/tests/ssl-opt.sh
@@ -141,7 +141,7 @@
printf " -f|--filter\tOnly matching tests are executed (substring or BRE)\n"
printf " -e|--exclude\tMatching tests are excluded (substring or BRE)\n"
printf " -n|--number\tExecute only numbered test (comma-separated, e.g. '245,256')\n"
- printf " -l|--list-tests\tList test names and exit\n"
+ printf " -l|--list-test-cases\tList all potential test cases (No Execution)\n"
printf " -s|--show-numbers\tShow test numbers in front of test names\n"
printf " -p|--preserve-logs\tPreserve logs of successful tests as well\n"
printf " --outcome-file\tFile where test outcomes are written\n"
@@ -169,7 +169,7 @@
-s|--show-numbers)
SHOW_TEST_NUMBER=1
;;
- -l|--list-tests)
+ -l|--list-test-cases)
LIST_TESTS=1
;;
-p|--preserve-logs)