mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-07 12:21:11 +03:00
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:
@ -129,7 +129,7 @@ print_usage() {
|
|||||||
printf " \tAlso available: GnuTLS (needs v3.2.15 or higher)\n"
|
printf " \tAlso available: GnuTLS (needs v3.2.15 or higher)\n"
|
||||||
printf " -M|--memcheck\tCheck memory leaks and errors.\n"
|
printf " -M|--memcheck\tCheck memory leaks and errors.\n"
|
||||||
printf " -v|--verbose\tSet verbose output.\n"
|
printf " -v|--verbose\tSet verbose output.\n"
|
||||||
printf " --list-test-case\tList all potential test cases (No Execution)\n"
|
printf " --list-test-cases\tList all potential test cases (No Execution)\n"
|
||||||
printf " --outcome-file\tFile where test outcomes are written\n"
|
printf " --outcome-file\tFile where test outcomes are written\n"
|
||||||
printf " \t(default: \$MBEDTLS_TEST_OUTCOME_FILE, none if empty)\n"
|
printf " \t(default: \$MBEDTLS_TEST_OUTCOME_FILE, none if empty)\n"
|
||||||
printf " --preserve-logs\tPreserve logs of successful tests as well\n"
|
printf " --preserve-logs\tPreserve logs of successful tests as well\n"
|
||||||
@ -144,7 +144,7 @@ print_test_case() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# list_test_case lists all potential test cases in compat.sh without execution
|
# list_test_case lists all potential test cases in compat.sh without execution
|
||||||
list_test_case() {
|
list_test_cases() {
|
||||||
for MODE in $MODES; do
|
for MODE in $MODES; do
|
||||||
for TYPE in $TYPES; do
|
for TYPE in $TYPES; do
|
||||||
for VERIFY in $VERIFIES; do
|
for VERIFY in $VERIFIES; do
|
||||||
@ -192,9 +192,9 @@ get_options() {
|
|||||||
MEMCHECK=1
|
MEMCHECK=1
|
||||||
;;
|
;;
|
||||||
# Please check scripts/check_test_cases.py correspondingly
|
# Please check scripts/check_test_cases.py correspondingly
|
||||||
# if you have to modify option, --list-test-case
|
# if you have to modify option, --list-test-cases
|
||||||
--list-test-case)
|
--list-test-cases)
|
||||||
list_test_case
|
list_test_cases
|
||||||
exit $?
|
exit $?
|
||||||
;;
|
;;
|
||||||
--outcome-file)
|
--outcome-file)
|
||||||
@ -1254,7 +1254,7 @@ report_fail() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# uniform_title <CLIENT> <SERVER> <STANDARD_CIPHER_SUITE>
|
# 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
|
# MBEDTLS_TEST_OUTCOME_FILE. This function aims to control the format of
|
||||||
# each test case description.
|
# each test case description.
|
||||||
uniform_title() {
|
uniform_title() {
|
||||||
|
@ -28,6 +28,7 @@ import re
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class Results:
|
class Results:
|
||||||
"""Store file and line information about errors or warnings in test suites."""
|
"""Store file and line information about errors or warnings in test suites."""
|
||||||
|
|
||||||
@ -97,33 +98,21 @@ state may override this method.
|
|||||||
data_file_name, line_number, line)
|
data_file_name, line_number, line)
|
||||||
in_paragraph = True
|
in_paragraph = True
|
||||||
|
|
||||||
def walk_ssl_opt_sh(self, file_name):
|
def collect_from_script(self, file_name):
|
||||||
"""Iterate over the test cases in ssl-opt.sh or a file with a similar format."""
|
"""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
|
descriptions = self.new_per_file_state() # pylint: disable=assignment-from-none
|
||||||
with open(file_name, 'rb') as file_contents:
|
listed = subprocess.check_output(['sh', file_name, '--list-test-cases'])
|
||||||
for line_number, line in enumerate(file_contents, 1):
|
# Assume test file is responsible for printing identical format of
|
||||||
# Assume that all run_test calls have the same simple form
|
# test case description between --list-test-cases and its OUTCOME.CSV
|
||||||
# with the test description entirely on the same line as the
|
#
|
||||||
# function name.
|
|
||||||
m = re.match(br'\s*run_test\s+"((?:[^\\"]|\\.)*)"', line)
|
|
||||||
if not m:
|
|
||||||
continue
|
|
||||||
description = m.group(1)
|
|
||||||
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']
|
|
||||||
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
|
# idx indicates the number of test case since there is no line number
|
||||||
# in `compat.sh` for each test case.
|
# in `compat.sh` for each test case.
|
||||||
for idx, descrip in enumerate(description):
|
for idx, description in enumerate(listed.splitlines()):
|
||||||
self.process_test_case(descriptions, file_name, idx, descrip)
|
self.process_test_case(descriptions,
|
||||||
|
file_name,
|
||||||
|
idx,
|
||||||
|
description.rstrip())
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def collect_test_directories():
|
def collect_test_directories():
|
||||||
@ -144,12 +133,11 @@ state may override this method.
|
|||||||
for data_file_name in glob.glob(os.path.join(directory, 'suites',
|
for data_file_name in glob.glob(os.path.join(directory, 'suites',
|
||||||
'*.data')):
|
'*.data')):
|
||||||
self.walk_test_suite(data_file_name)
|
self.walk_test_suite(data_file_name)
|
||||||
ssl_opt_sh = os.path.join(directory, 'ssl-opt.sh')
|
|
||||||
if os.path.exists(ssl_opt_sh):
|
for sh_file in ['ssl-opt.sh', 'compat.sh']:
|
||||||
self.walk_ssl_opt_sh(ssl_opt_sh)
|
sh_file = os.path.join(directory, sh_file)
|
||||||
compat_sh = os.path.join(directory, 'compat.sh')
|
if os.path.exists(sh_file):
|
||||||
if os.path.exists(compat_sh):
|
self.collect_from_script(sh_file)
|
||||||
self.walk_compat_sh(compat_sh)
|
|
||||||
|
|
||||||
class TestDescriptions(TestDescriptionExplorer):
|
class TestDescriptions(TestDescriptionExplorer):
|
||||||
"""Collect the available test cases."""
|
"""Collect the available test cases."""
|
||||||
|
Reference in New Issue
Block a user