mirror of
https://github.com/yuzu-mirror/mbedtls.git
synced 2026-04-20 22:05:15 +00:00
Merge pull request #6296 from gilles-peskine-arm/test_data_generation-pr_6093_followup
Minor fixes to test_data_generation.py
This commit is contained in:
commit
7cd1ebe0bb
15 changed files with 81 additions and 74 deletions
|
|
@ -16,38 +16,44 @@ endif()
|
|||
# generated .data files will go there
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/suites)
|
||||
|
||||
# Get base names for generated files (starting at "suites/")
|
||||
# Get base names for generated files
|
||||
execute_process(
|
||||
COMMAND
|
||||
${MBEDTLS_PYTHON_EXECUTABLE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../tests/scripts/generate_bignum_tests.py
|
||||
--list-for-cmake
|
||||
--directory suites
|
||||
WORKING_DIRECTORY
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||
OUTPUT_VARIABLE
|
||||
base_bignum_generated_data_files)
|
||||
string(REGEX REPLACE "[^;]*/" ""
|
||||
base_bignum_generated_data_files "${base_bignum_generated_data_files}")
|
||||
|
||||
execute_process(
|
||||
COMMAND
|
||||
${MBEDTLS_PYTHON_EXECUTABLE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../tests/scripts/generate_psa_tests.py
|
||||
--list-for-cmake
|
||||
--directory suites
|
||||
WORKING_DIRECTORY
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||
OUTPUT_VARIABLE
|
||||
base_psa_generated_data_files)
|
||||
string(REGEX REPLACE "[^;]*/" ""
|
||||
base_psa_generated_data_files "${base_psa_generated_data_files}")
|
||||
|
||||
# Derive generated file paths in the build directory
|
||||
set(base_generated_data_files ${base_bignum_generated_data_files} ${base_psa_generated_data_files})
|
||||
# Derive generated file paths in the build directory. The generated data
|
||||
# files go into the suites/ subdirectory.
|
||||
set(base_generated_data_files
|
||||
${base_bignum_generated_data_files} ${base_psa_generated_data_files})
|
||||
string(REGEX REPLACE "([^;]+)" "suites/\\1"
|
||||
all_generated_data_files "${base_generated_data_files}")
|
||||
set(bignum_generated_data_files "")
|
||||
set(psa_generated_data_files "")
|
||||
foreach(file ${base_bignum_generated_data_files})
|
||||
list(APPEND bignum_generated_data_files ${CMAKE_CURRENT_BINARY_DIR}/${file})
|
||||
list(APPEND bignum_generated_data_files ${CMAKE_CURRENT_BINARY_DIR}/suites/${file})
|
||||
endforeach()
|
||||
foreach(file ${base_psa_generated_data_files})
|
||||
list(APPEND psa_generated_data_files ${CMAKE_CURRENT_BINARY_DIR}/${file})
|
||||
list(APPEND psa_generated_data_files ${CMAKE_CURRENT_BINARY_DIR}/suites/${file})
|
||||
endforeach()
|
||||
|
||||
if(GEN_FILES)
|
||||
|
|
@ -63,7 +69,7 @@ if(GEN_FILES)
|
|||
DEPENDS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../tests/scripts/generate_bignum_tests.py
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/mbedtls_dev/test_case.py
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/mbedtls_dev/test_generation.py
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/mbedtls_dev/test_data_generation.py
|
||||
)
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
|
|
@ -80,14 +86,14 @@ if(GEN_FILES)
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/mbedtls_dev/macro_collector.py
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/mbedtls_dev/psa_storage.py
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/mbedtls_dev/test_case.py
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/mbedtls_dev/test_generation.py
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/mbedtls_dev/test_data_generation.py
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_config.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_values.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../include/psa/crypto_extra.h
|
||||
)
|
||||
|
||||
else()
|
||||
foreach(file ${base_generated_data_files})
|
||||
foreach(file ${all_generated_data_files})
|
||||
link_to_source(${file})
|
||||
endforeach()
|
||||
endif()
|
||||
|
|
@ -210,9 +216,9 @@ if(MSVC)
|
|||
endif(MSVC)
|
||||
|
||||
file(GLOB test_suites RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" suites/*.data)
|
||||
list(APPEND test_suites ${base_generated_data_files})
|
||||
list(APPEND test_suites ${all_generated_data_files})
|
||||
# If the generated .data files are present in the source tree, we just added
|
||||
# them twice, both through GLOB and through ${base_generated_data_files}.
|
||||
# them twice, both through GLOB and through ${all_generated_data_files}.
|
||||
list(REMOVE_DUPLICATES test_suites)
|
||||
list(SORT test_suites)
|
||||
foreach(test_suite ${test_suites})
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ generated_files: $(GENERATED_FILES)
|
|||
$(GENERATED_BIGNUM_DATA_FILES): generated_bignum_test_data
|
||||
generated_bignum_test_data: scripts/generate_bignum_tests.py
|
||||
generated_bignum_test_data: ../scripts/mbedtls_dev/test_case.py
|
||||
generated_bignum_test_data: ../scripts/mbedtls_dev/test_generation.py
|
||||
generated_bignum_test_data: ../scripts/mbedtls_dev/test_data_generation.py
|
||||
generated_bignum_test_data:
|
||||
echo " Gen $(GENERATED_BIGNUM_DATA_FILES)"
|
||||
$(PYTHON) scripts/generate_bignum_tests.py
|
||||
|
|
@ -104,7 +104,7 @@ generated_psa_test_data: ../scripts/mbedtls_dev/crypto_knowledge.py
|
|||
generated_psa_test_data: ../scripts/mbedtls_dev/macro_collector.py
|
||||
generated_psa_test_data: ../scripts/mbedtls_dev/psa_storage.py
|
||||
generated_psa_test_data: ../scripts/mbedtls_dev/test_case.py
|
||||
generated_psa_test_data: ../scripts/mbedtls_dev/test_generation.py
|
||||
generated_psa_test_data: ../scripts/mbedtls_dev/test_data_generation.py
|
||||
## The generated file only depends on the options that are present in
|
||||
## crypto_config.h, not on which options are set. To avoid regenerating this
|
||||
## file all the time when switching between configurations, don't declare
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ elif [ "$1" = "--can-mypy" ]; then
|
|||
fi
|
||||
|
||||
echo 'Running pylint ...'
|
||||
$PYTHON -m pylint -j 2 scripts/mbedtls_dev/*.py scripts/*.py tests/scripts/*.py || {
|
||||
$PYTHON -m pylint scripts/mbedtls_dev/*.py scripts/*.py tests/scripts/*.py || {
|
||||
echo >&2 "pylint reported errors"
|
||||
ret=1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,9 @@ try:
|
|||
except ImportError:
|
||||
pass
|
||||
|
||||
import scripts_path # pylint: disable=unused-import
|
||||
from mbedtls_dev import build_tree
|
||||
|
||||
|
||||
class FileIssueTracker:
|
||||
"""Base class for file-wide issue tracking.
|
||||
|
|
@ -338,7 +341,7 @@ class IntegrityChecker:
|
|||
"""Instantiate the sanity checker.
|
||||
Check files under the current directory.
|
||||
Write a report of issues to log_file."""
|
||||
self.check_repo_path()
|
||||
build_tree.check_repo_path()
|
||||
self.logger = None
|
||||
self.setup_logger(log_file)
|
||||
self.issues_to_check = [
|
||||
|
|
@ -353,11 +356,6 @@ class IntegrityChecker:
|
|||
MergeArtifactIssueTracker(),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def check_repo_path():
|
||||
if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
|
||||
raise Exception("Must be run from Mbed TLS root")
|
||||
|
||||
def setup_logger(self, log_file, level=logging.INFO):
|
||||
self.logger = logging.getLogger()
|
||||
self.logger.setLevel(level)
|
||||
|
|
|
|||
|
|
@ -56,6 +56,10 @@ import shutil
|
|||
import subprocess
|
||||
import logging
|
||||
|
||||
import scripts_path # pylint: disable=unused-import
|
||||
from mbedtls_dev import build_tree
|
||||
|
||||
|
||||
# Naming patterns to check against. These are defined outside the NameCheck
|
||||
# class for ease of modification.
|
||||
PUBLIC_MACRO_PATTERN = r"^(MBEDTLS|PSA)_[0-9A-Z_]*[0-9A-Z]$"
|
||||
|
|
@ -219,7 +223,7 @@ class CodeParser():
|
|||
"""
|
||||
def __init__(self, log):
|
||||
self.log = log
|
||||
self.check_repo_path()
|
||||
build_tree.check_repo_path()
|
||||
|
||||
# Memo for storing "glob expression": set(filepaths)
|
||||
self.files = {}
|
||||
|
|
@ -228,15 +232,6 @@ class CodeParser():
|
|||
# Note that "*" can match directory separators in exclude lists.
|
||||
self.excluded_files = ["*/bn_mul", "*/compat-2.x.h"]
|
||||
|
||||
@staticmethod
|
||||
def check_repo_path():
|
||||
"""
|
||||
Check that the current working directory is the project root, and throw
|
||||
an exception if not.
|
||||
"""
|
||||
if not all(os.path.isdir(d) for d in ["include", "library", "tests"]):
|
||||
raise Exception("This script must be run from Mbed TLS root")
|
||||
|
||||
def comprehensive_parse(self):
|
||||
"""
|
||||
Comprehensive ("default") function to call each parsing function and
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ generate only the specified files.
|
|||
|
||||
Class structure:
|
||||
|
||||
Child classes of test_generation.BaseTarget (file targets) represent an output
|
||||
Child classes of test_data_generation.BaseTarget (file targets) represent an output
|
||||
file. These indicate where test cases will be written to, for all subclasses of
|
||||
this target. Multiple file targets should not reuse a `target_basename`.
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ following:
|
|||
call `.create_test_case()` to yield the TestCase.
|
||||
|
||||
Additional details and other attributes/methods are given in the documentation
|
||||
of BaseTarget in test_generation.py.
|
||||
of BaseTarget in test_data_generation.py.
|
||||
"""
|
||||
|
||||
# Copyright The Mbed TLS Contributors
|
||||
|
|
@ -63,7 +63,7 @@ from typing import Iterator, List, Tuple, TypeVar
|
|||
|
||||
import scripts_path # pylint: disable=unused-import
|
||||
from mbedtls_dev import test_case
|
||||
from mbedtls_dev import test_generation
|
||||
from mbedtls_dev import test_data_generation
|
||||
|
||||
T = TypeVar('T') #pylint: disable=invalid-name
|
||||
|
||||
|
|
@ -74,18 +74,16 @@ def quote_str(val) -> str:
|
|||
return "\"{}\"".format(val)
|
||||
|
||||
def combination_pairs(values: List[T]) -> List[Tuple[T, T]]:
|
||||
"""Return all pair combinations from input values.
|
||||
|
||||
The return value is cast, as older versions of mypy are unable to derive
|
||||
the specific type returned by itertools.combinations_with_replacement.
|
||||
"""
|
||||
"""Return all pair combinations from input values."""
|
||||
# The return value is cast, as older versions of mypy are unable to derive
|
||||
# the specific type returned by itertools.combinations_with_replacement.
|
||||
return typing.cast(
|
||||
List[Tuple[T, T]],
|
||||
list(itertools.combinations_with_replacement(values, 2))
|
||||
)
|
||||
|
||||
|
||||
class BignumTarget(test_generation.BaseTarget, metaclass=ABCMeta):
|
||||
class BignumTarget(test_data_generation.BaseTarget, metaclass=ABCMeta):
|
||||
#pylint: disable=abstract-method
|
||||
"""Target for bignum (mpi) test case generation."""
|
||||
target_basename = 'test_suite_mpi.generated'
|
||||
|
|
@ -235,4 +233,4 @@ class BignumAdd(BignumOperation):
|
|||
|
||||
if __name__ == '__main__':
|
||||
# Use the section of the docstring relevant to the CLI as description
|
||||
test_generation.main(sys.argv[1:], "\n".join(__doc__.splitlines()[:4]))
|
||||
test_data_generation.main(sys.argv[1:], "\n".join(__doc__.splitlines()[:4]))
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ from mbedtls_dev import crypto_knowledge
|
|||
from mbedtls_dev import macro_collector
|
||||
from mbedtls_dev import psa_storage
|
||||
from mbedtls_dev import test_case
|
||||
from mbedtls_dev import test_generation
|
||||
from mbedtls_dev import test_data_generation
|
||||
|
||||
|
||||
def psa_want_symbol(name: str) -> str:
|
||||
|
|
@ -892,7 +892,7 @@ class StorageFormatV0(StorageFormat):
|
|||
yield from super().generate_all_keys()
|
||||
yield from self.all_keys_for_implicit_usage()
|
||||
|
||||
class PSATestGenerator(test_generation.TestGenerator):
|
||||
class PSATestGenerator(test_data_generation.TestGenerator):
|
||||
"""Test generator subclass including PSA targets and info."""
|
||||
# Note that targets whose names contain 'test_format' have their content
|
||||
# validated by `abi_check.py`.
|
||||
|
|
@ -917,4 +917,4 @@ class PSATestGenerator(test_generation.TestGenerator):
|
|||
super().generate_target(name, self.info)
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_generation.main(sys.argv[1:], __doc__, PSATestGenerator)
|
||||
test_data_generation.main(sys.argv[1:], __doc__, PSATestGenerator)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue