Merge pull request #7937 from yanrayw/code_size_compare_improvement
code_size_compare.py: preparation work to show code size changes in PR comment
This commit is contained in:
commit
505dffd5e3
3 changed files with 838 additions and 315 deletions
File diff suppressed because it is too large
Load diff
57
scripts/mbedtls_dev/logging_util.py
Normal file
57
scripts/mbedtls_dev/logging_util.py
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
"""Auxiliary functions used for logging module.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Copyright The Mbed TLS Contributors
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def configure_logger(
|
||||||
|
logger: logging.Logger,
|
||||||
|
log_format="[%(levelname)s]: %(message)s",
|
||||||
|
split_level=logging.WARNING
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Configure the logging.Logger instance so that:
|
||||||
|
- Format is set to any log_format.
|
||||||
|
Default: "[%(levelname)s]: %(message)s"
|
||||||
|
- loglevel >= split_level are printed to stderr.
|
||||||
|
- loglevel < split_level are printed to stdout.
|
||||||
|
Default: logging.WARNING
|
||||||
|
"""
|
||||||
|
class MaxLevelFilter(logging.Filter):
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
|
def __init__(self, max_level, name=''):
|
||||||
|
super().__init__(name)
|
||||||
|
self.max_level = max_level
|
||||||
|
|
||||||
|
def filter(self, record: logging.LogRecord) -> bool:
|
||||||
|
return record.levelno <= self.max_level
|
||||||
|
|
||||||
|
log_formatter = logging.Formatter(log_format)
|
||||||
|
|
||||||
|
# set loglevel >= split_level to be printed to stderr
|
||||||
|
stderr_hdlr = logging.StreamHandler(sys.stderr)
|
||||||
|
stderr_hdlr.setLevel(split_level)
|
||||||
|
stderr_hdlr.setFormatter(log_formatter)
|
||||||
|
|
||||||
|
# set loglevel < split_level to be printed to stdout
|
||||||
|
stdout_hdlr = logging.StreamHandler(sys.stdout)
|
||||||
|
stdout_hdlr.addFilter(MaxLevelFilter(split_level - 1))
|
||||||
|
stdout_hdlr.setFormatter(log_formatter)
|
||||||
|
|
||||||
|
logger.addHandler(stderr_hdlr)
|
||||||
|
logger.addHandler(stdout_hdlr)
|
|
@ -24,7 +24,6 @@ from tests/data_files/ and tests/suites/*.data files by default.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import re
|
import re
|
||||||
import typing
|
import typing
|
||||||
import argparse
|
import argparse
|
||||||
|
@ -43,6 +42,7 @@ from generate_test_code import FileWrapper
|
||||||
|
|
||||||
import scripts_path # pylint: disable=unused-import
|
import scripts_path # pylint: disable=unused-import
|
||||||
from mbedtls_dev import build_tree
|
from mbedtls_dev import build_tree
|
||||||
|
from mbedtls_dev import logging_util
|
||||||
|
|
||||||
def check_cryptography_version():
|
def check_cryptography_version():
|
||||||
match = re.match(r'^[0-9]+', cryptography.__version__)
|
match = re.match(r'^[0-9]+', cryptography.__version__)
|
||||||
|
@ -393,38 +393,6 @@ def list_all(audit_data: AuditData):
|
||||||
loc))
|
loc))
|
||||||
|
|
||||||
|
|
||||||
def configure_logger(logger: logging.Logger) -> None:
|
|
||||||
"""
|
|
||||||
Configure the logging.Logger instance so that:
|
|
||||||
- Format is set to "[%(levelname)s]: %(message)s".
|
|
||||||
- loglevel >= WARNING are printed to stderr.
|
|
||||||
- loglevel < WARNING are printed to stdout.
|
|
||||||
"""
|
|
||||||
class MaxLevelFilter(logging.Filter):
|
|
||||||
# pylint: disable=too-few-public-methods
|
|
||||||
def __init__(self, max_level, name=''):
|
|
||||||
super().__init__(name)
|
|
||||||
self.max_level = max_level
|
|
||||||
|
|
||||||
def filter(self, record: logging.LogRecord) -> bool:
|
|
||||||
return record.levelno <= self.max_level
|
|
||||||
|
|
||||||
log_formatter = logging.Formatter("[%(levelname)s]: %(message)s")
|
|
||||||
|
|
||||||
# set loglevel >= WARNING to be printed to stderr
|
|
||||||
stderr_hdlr = logging.StreamHandler(sys.stderr)
|
|
||||||
stderr_hdlr.setLevel(logging.WARNING)
|
|
||||||
stderr_hdlr.setFormatter(log_formatter)
|
|
||||||
|
|
||||||
# set loglevel <= INFO to be printed to stdout
|
|
||||||
stdout_hdlr = logging.StreamHandler(sys.stdout)
|
|
||||||
stdout_hdlr.addFilter(MaxLevelFilter(logging.INFO))
|
|
||||||
stdout_hdlr.setFormatter(log_formatter)
|
|
||||||
|
|
||||||
logger.addHandler(stderr_hdlr)
|
|
||||||
logger.addHandler(stdout_hdlr)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""
|
"""
|
||||||
Perform argument parsing.
|
Perform argument parsing.
|
||||||
|
@ -457,7 +425,7 @@ def main():
|
||||||
# start main routine
|
# start main routine
|
||||||
# setup logger
|
# setup logger
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
configure_logger(logger)
|
logging_util.configure_logger(logger)
|
||||||
logger.setLevel(logging.DEBUG if args.verbose else logging.ERROR)
|
logger.setLevel(logging.DEBUG if args.verbose else logging.ERROR)
|
||||||
|
|
||||||
td_auditor = TestDataAuditor(logger)
|
td_auditor = TestDataAuditor(logger)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue