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>
This commit is contained in:
Tomás González 2023-09-01 17:41:16 +01:00
parent 37a8739e4d
commit 4a86da2460
3 changed files with 19 additions and 29 deletions

View file

@ -127,7 +127,7 @@ print_usage() {
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 @@ get_options() {
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 @@ wait_client_done() {
}
# 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() {

View file

@ -27,7 +27,6 @@ import os
import re
import subprocess
import sys
import subprocess
class Results:
@ -99,26 +98,18 @@ state may override this method.
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 @@ state may override this method.
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."""

View file

@ -141,7 +141,7 @@ print_usage() {
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 @@ get_options() {
-s|--show-numbers)
SHOW_TEST_NUMBER=1
;;
-l|--list-tests)
-l|--list-test-cases)
LIST_TESTS=1
;;
-p|--preserve-logs)