Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Gilles Peskine | 6100d3c | 2022-06-20 18:51:18 +0200 | [diff] [blame] | 2 | """This script compares the interfaces of two versions of Mbed TLS, looking |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 3 | for backward incompatibilities between two different Git revisions within |
| 4 | an Mbed TLS repository. It must be run from the root of a Git working tree. |
| 5 | |
Gilles Peskine | 228d99b | 2022-06-20 18:51:44 +0200 | [diff] [blame] | 6 | ### How the script works ### |
| 7 | |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 8 | For the source (API) and runtime (ABI) interface compatibility, this script |
| 9 | is a small wrapper around the abi-compliance-checker and abi-dumper tools, |
| 10 | applying them to compare the header and library files. |
| 11 | |
| 12 | For the storage format, this script compares the automatically generated |
Gilles Peskine | ca586a5 | 2022-02-22 19:02:44 +0100 | [diff] [blame] | 13 | storage tests and the manual read tests, and complains if there is a |
Gilles Peskine | 4a9630a | 2022-03-04 19:59:55 +0100 | [diff] [blame] | 14 | reduction in coverage. A change in test data will be signaled as a |
Gilles Peskine | ca586a5 | 2022-02-22 19:02:44 +0100 | [diff] [blame] | 15 | coverage reduction since the old test data is no longer present. A change in |
Gilles Peskine | 4a9630a | 2022-03-04 19:59:55 +0100 | [diff] [blame] | 16 | how test data is presented will be signaled as well; this would be a false |
Gilles Peskine | ca586a5 | 2022-02-22 19:02:44 +0100 | [diff] [blame] | 17 | positive. |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 18 | |
Gilles Peskine | ca586a5 | 2022-02-22 19:02:44 +0100 | [diff] [blame] | 19 | The results of the API/ABI comparison are either formatted as HTML and stored |
| 20 | at a configurable location, or are given as a brief list of problems. |
| 21 | Returns 0 on success, 1 on non-compliance, and 2 if there is an error |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 22 | while running the script. |
Gilles Peskine | 644b3f6 | 2022-03-03 10:23:09 +0100 | [diff] [blame] | 23 | |
Gilles Peskine | 228d99b | 2022-06-20 18:51:44 +0200 | [diff] [blame] | 24 | ### How to interpret non-compliance ### |
| 25 | |
| 26 | This script has relatively common false positives. In many scenarios, it only |
| 27 | reports a pass if there is a strict textual match between the old version and |
| 28 | the new version, and it reports problems where there is a sufficient semantic |
| 29 | match but not a textual match. This section lists some common false positives. |
| 30 | This is not an exhaustive list: in the end what matters is whether we are |
| 31 | breaking a backward compatibility goal. |
| 32 | |
| 33 | **API**: the goal is that if an application works with the old version of the |
| 34 | library, it can be recompiled against the new version and will still work. |
| 35 | This is normally validated by comparing the declarations in `include/*/*.h`. |
| 36 | A failure is a declaration that has disappeared or that now has a different |
| 37 | type. |
| 38 | |
| 39 | * It's ok to change or remove macros and functions that are documented as |
| 40 | for internal use only or as experimental. |
| 41 | * It's ok to rename function or macro parameters as long as the semantics |
| 42 | has not changed. |
| 43 | * It's ok to change or remove structure fields that are documented as |
| 44 | private. |
| 45 | * It's ok to add fields to a structure that already had private fields |
| 46 | or was documented as extensible. |
| 47 | |
| 48 | **ABI**: the goal is that if an application was built against the old version |
| 49 | of the library, the same binary will work when linked against the new version. |
| 50 | This is normally validated by comparing the symbols exported by `libmbed*.so`. |
| 51 | A failure is a symbol that is no longer exported by the same library or that |
| 52 | now has a different type. |
| 53 | |
| 54 | * All ABI changes are acceptable if the library version is bumped |
| 55 | (see `scripts/bump_version.sh`). |
| 56 | * ABI changes that concern functions which are declared only inside the |
| 57 | library directory, and not in `include/*/*.h`, are acceptable only if |
| 58 | the function was only ever used inside the same library (libmbedcrypto, |
| 59 | libmbedx509, libmbedtls). As a counter example, if the old version |
| 60 | of libmbedtls calls mbedtls_foo() from libmbedcrypto, and the new version |
| 61 | of libmbedcrypto no longer has a compatible mbedtls_foo(), this does |
| 62 | require a version bump for libmbedcrypto. |
| 63 | |
| 64 | **Storage format**: the goal is to check that persistent keys stored by the |
| 65 | old version can be read by the new version. This is normally validated by |
| 66 | comparing the `*read*` test cases in `test_suite*storage_format*.data`. |
| 67 | A failure is a storage read test case that is no longer present with the same |
| 68 | function name and parameter list. |
| 69 | |
| 70 | * It's ok if the same test data is present, but its presentation has changed, |
| 71 | for example if a test function is renamed or has different parameters. |
| 72 | * It's ok if redundant tests are removed. |
| 73 | |
| 74 | **Generated test coverage**: the goal is to check that automatically |
| 75 | generated tests have as much coverage as before. This is normally validated |
| 76 | by comparing the test cases that are automatically generated by a script. |
| 77 | A failure is a generated test case that is no longer present with the same |
| 78 | function name and parameter list. |
| 79 | |
| 80 | * It's ok if the same test data is present, but its presentation has changed, |
| 81 | for example if a test function is renamed or has different parameters. |
| 82 | * It's ok if redundant tests are removed. |
| 83 | |
Darryl Green | 7869680 | 2018-04-06 11:23:22 +0100 | [diff] [blame] | 84 | """ |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 85 | |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 86 | # Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 87 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 88 | |
Gilles Peskine | ca586a5 | 2022-02-22 19:02:44 +0100 | [diff] [blame] | 89 | import glob |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 90 | import os |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 91 | import re |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 92 | import sys |
| 93 | import traceback |
| 94 | import shutil |
| 95 | import subprocess |
| 96 | import argparse |
| 97 | import logging |
| 98 | import tempfile |
Darryl Green | 9f357d6 | 2019-02-25 11:35:05 +0000 | [diff] [blame] | 99 | import fnmatch |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 100 | from types import SimpleNamespace |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 101 | |
Darryl Green | e62f9bb | 2019-02-21 13:09:26 +0000 | [diff] [blame] | 102 | import xml.etree.ElementTree as ET |
| 103 | |
David Horstmann | ecd6d01 | 2024-05-10 16:58:31 +0100 | [diff] [blame] | 104 | import framework_scripts_path # pylint: disable=unused-import |
David Horstmann | cd84bb2 | 2024-05-03 14:36:12 +0100 | [diff] [blame] | 105 | from mbedtls_framework import build_tree |
Gilles Peskine | d9071e7 | 2022-09-18 21:17:09 +0200 | [diff] [blame] | 106 | |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 107 | |
Gilles Peskine | 184c096 | 2020-03-24 18:25:17 +0100 | [diff] [blame] | 108 | class AbiChecker: |
Gilles Peskine | 712afa7 | 2019-02-25 20:36:52 +0100 | [diff] [blame] | 109 | """API and ABI checker.""" |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 110 | |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 111 | def __init__(self, old_version, new_version, configuration): |
Gilles Peskine | 712afa7 | 2019-02-25 20:36:52 +0100 | [diff] [blame] | 112 | """Instantiate the API/ABI checker. |
| 113 | |
Darryl Green | 7c1a733 | 2019-03-05 16:25:38 +0000 | [diff] [blame] | 114 | old_version: RepoVersion containing details to compare against |
| 115 | new_version: RepoVersion containing details to check |
Darryl Green | f67e349 | 2019-04-12 15:17:02 +0100 | [diff] [blame] | 116 | configuration.report_dir: directory for output files |
| 117 | configuration.keep_all_reports: if false, delete old reports |
| 118 | configuration.brief: if true, output shorter report to stdout |
Gilles Peskine | 4a9630a | 2022-03-04 19:59:55 +0100 | [diff] [blame] | 119 | configuration.check_abi: if true, compare ABIs |
Gilles Peskine | c76ab85 | 2021-04-23 16:32:32 +0200 | [diff] [blame] | 120 | configuration.check_api: if true, compare APIs |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 121 | configuration.check_storage: if true, compare storage format tests |
Darryl Green | f67e349 | 2019-04-12 15:17:02 +0100 | [diff] [blame] | 122 | configuration.skip_file: path to file containing symbols and types to skip |
Gilles Peskine | 712afa7 | 2019-02-25 20:36:52 +0100 | [diff] [blame] | 123 | """ |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 124 | self.repo_path = "." |
| 125 | self.log = None |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 126 | self.verbose = configuration.verbose |
Darryl Green | 3a5f6c8 | 2019-03-05 16:30:39 +0000 | [diff] [blame] | 127 | self._setup_logger() |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 128 | self.report_dir = os.path.abspath(configuration.report_dir) |
| 129 | self.keep_all_reports = configuration.keep_all_reports |
Darryl Green | 492bc40 | 2019-04-11 15:50:41 +0100 | [diff] [blame] | 130 | self.can_remove_report_dir = not (os.path.exists(self.report_dir) or |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 131 | self.keep_all_reports) |
Darryl Green | 7c1a733 | 2019-03-05 16:25:38 +0000 | [diff] [blame] | 132 | self.old_version = old_version |
| 133 | self.new_version = new_version |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 134 | self.skip_file = configuration.skip_file |
Gilles Peskine | c76ab85 | 2021-04-23 16:32:32 +0200 | [diff] [blame] | 135 | self.check_abi = configuration.check_abi |
| 136 | self.check_api = configuration.check_api |
| 137 | if self.check_abi != self.check_api: |
| 138 | raise Exception('Checking API without ABI or vice versa is not supported') |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 139 | self.check_storage_tests = configuration.check_storage |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 140 | self.brief = configuration.brief |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 141 | self.git_command = "git" |
| 142 | self.make_command = "make" |
| 143 | |
Darryl Green | 3a5f6c8 | 2019-03-05 16:30:39 +0000 | [diff] [blame] | 144 | def _setup_logger(self): |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 145 | self.log = logging.getLogger() |
Darryl Green | 3c3da79 | 2019-03-08 11:30:04 +0000 | [diff] [blame] | 146 | if self.verbose: |
| 147 | self.log.setLevel(logging.DEBUG) |
| 148 | else: |
| 149 | self.log.setLevel(logging.INFO) |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 150 | self.log.addHandler(logging.StreamHandler()) |
| 151 | |
Gilles Peskine | 712afa7 | 2019-02-25 20:36:52 +0100 | [diff] [blame] | 152 | @staticmethod |
| 153 | def check_abi_tools_are_installed(): |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 154 | for command in ["abi-dumper", "abi-compliance-checker"]: |
| 155 | if not shutil.which(command): |
| 156 | raise Exception("{} not installed, aborting".format(command)) |
| 157 | |
Darryl Green | 3a5f6c8 | 2019-03-05 16:30:39 +0000 | [diff] [blame] | 158 | def _get_clean_worktree_for_git_revision(self, version): |
Darryl Green | 7c1a733 | 2019-03-05 16:25:38 +0000 | [diff] [blame] | 159 | """Make a separate worktree with version.revision checked out. |
Gilles Peskine | 712afa7 | 2019-02-25 20:36:52 +0100 | [diff] [blame] | 160 | Do not modify the current worktree.""" |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 161 | git_worktree_path = tempfile.mkdtemp() |
Darryl Green | 7c1a733 | 2019-03-05 16:25:38 +0000 | [diff] [blame] | 162 | if version.repository: |
Darryl Green | 3c3da79 | 2019-03-08 11:30:04 +0000 | [diff] [blame] | 163 | self.log.debug( |
Darryl Green | da84e32 | 2019-02-19 16:59:33 +0000 | [diff] [blame] | 164 | "Checking out git worktree for revision {} from {}".format( |
Darryl Green | 7c1a733 | 2019-03-05 16:25:38 +0000 | [diff] [blame] | 165 | version.revision, version.repository |
Darryl Green | da84e32 | 2019-02-19 16:59:33 +0000 | [diff] [blame] | 166 | ) |
| 167 | ) |
Darryl Green | b2ee0b8 | 2019-04-12 16:24:25 +0100 | [diff] [blame] | 168 | fetch_output = subprocess.check_output( |
Darryl Green | 7c1a733 | 2019-03-05 16:25:38 +0000 | [diff] [blame] | 169 | [self.git_command, "fetch", |
| 170 | version.repository, version.revision], |
Darryl Green | da84e32 | 2019-02-19 16:59:33 +0000 | [diff] [blame] | 171 | cwd=self.repo_path, |
Darryl Green | da84e32 | 2019-02-19 16:59:33 +0000 | [diff] [blame] | 172 | stderr=subprocess.STDOUT |
| 173 | ) |
Darryl Green | 3c3da79 | 2019-03-08 11:30:04 +0000 | [diff] [blame] | 174 | self.log.debug(fetch_output.decode("utf-8")) |
Darryl Green | da84e32 | 2019-02-19 16:59:33 +0000 | [diff] [blame] | 175 | worktree_rev = "FETCH_HEAD" |
| 176 | else: |
Darryl Green | 3c3da79 | 2019-03-08 11:30:04 +0000 | [diff] [blame] | 177 | self.log.debug("Checking out git worktree for revision {}".format( |
Darryl Green | 7c1a733 | 2019-03-05 16:25:38 +0000 | [diff] [blame] | 178 | version.revision |
| 179 | )) |
| 180 | worktree_rev = version.revision |
Darryl Green | b2ee0b8 | 2019-04-12 16:24:25 +0100 | [diff] [blame] | 181 | worktree_output = subprocess.check_output( |
Darryl Green | da84e32 | 2019-02-19 16:59:33 +0000 | [diff] [blame] | 182 | [self.git_command, "worktree", "add", "--detach", |
| 183 | git_worktree_path, worktree_rev], |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 184 | cwd=self.repo_path, |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 185 | stderr=subprocess.STDOUT |
| 186 | ) |
Darryl Green | 3c3da79 | 2019-03-08 11:30:04 +0000 | [diff] [blame] | 187 | self.log.debug(worktree_output.decode("utf-8")) |
Gilles Peskine | 3e2da4a | 2019-07-04 19:01:22 +0200 | [diff] [blame] | 188 | version.commit = subprocess.check_output( |
Darryl Green | 762351b | 2019-07-25 14:33:33 +0100 | [diff] [blame] | 189 | [self.git_command, "rev-parse", "HEAD"], |
Gilles Peskine | 3e2da4a | 2019-07-04 19:01:22 +0200 | [diff] [blame] | 190 | cwd=git_worktree_path, |
| 191 | stderr=subprocess.STDOUT |
| 192 | ).decode("ascii").rstrip() |
| 193 | self.log.debug("Commit is {}".format(version.commit)) |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 194 | return git_worktree_path |
| 195 | |
Darryl Green | 3a5f6c8 | 2019-03-05 16:30:39 +0000 | [diff] [blame] | 196 | def _update_git_submodules(self, git_worktree_path, version): |
Darryl Green | 8184df5 | 2019-04-05 17:06:17 +0100 | [diff] [blame] | 197 | """If the crypto submodule is present, initialize it. |
| 198 | if version.crypto_revision exists, update it to that revision, |
| 199 | otherwise update it to the default revision""" |
Bence Szépkúti | effa534 | 2025-09-25 15:51:07 +0200 | [diff] [blame] | 200 | submodule_output = subprocess.check_output( |
| 201 | [self.git_command, "submodule", "foreach", "--recursive", |
Bence Szépkúti | dc88f6e | 2025-09-26 15:37:42 +0200 | [diff] [blame] | 202 | f'git worktree add --detach "{git_worktree_path}/$displaypath" HEAD'], |
Bence Szépkúti | effa534 | 2025-09-25 15:51:07 +0200 | [diff] [blame] | 203 | cwd=self.repo_path, |
| 204 | stderr=subprocess.STDOUT |
| 205 | ) |
| 206 | self.log.debug(submodule_output.decode("utf-8")) |
Bence Szépkúti | 0f2a4f3 | 2025-09-26 20:10:04 +0200 | [diff] [blame] | 207 | |
| 208 | try: |
| 209 | # Try to update the submodules using local commits |
Bence Szépkúti | 9defedb | 2025-09-29 14:24:25 +0200 | [diff] [blame] | 210 | # (Git will sometimes insist on fetching the remote without --no-fetch |
| 211 | # if the submodules are shallow clones) |
Bence Szépkúti | 0f2a4f3 | 2025-09-26 20:10:04 +0200 | [diff] [blame] | 212 | update_output = subprocess.check_output( |
| 213 | [self.git_command, "submodule", "update", "--init", '--recursive', '--no-fetch'], |
| 214 | cwd=git_worktree_path, |
| 215 | stderr=subprocess.STDOUT |
| 216 | ) |
| 217 | except subprocess.CalledProcessError as err: |
| 218 | self.log.debug(err.stdout.decode("utf-8")) |
| 219 | |
| 220 | # Checkout with --no-fetch failed, falling back to fetching from origin |
| 221 | update_output = subprocess.check_output( |
| 222 | [self.git_command, "submodule", "update", "--init", '--recursive'], |
| 223 | cwd=git_worktree_path, |
| 224 | stderr=subprocess.STDOUT |
| 225 | ) |
Darryl Green | b2ee0b8 | 2019-04-12 16:24:25 +0100 | [diff] [blame] | 226 | self.log.debug(update_output.decode("utf-8")) |
Darryl Green | e29ce70 | 2019-03-05 15:23:25 +0000 | [diff] [blame] | 227 | if not (os.path.exists(os.path.join(git_worktree_path, "crypto")) |
Darryl Green | 7c1a733 | 2019-03-05 16:25:38 +0000 | [diff] [blame] | 228 | and version.crypto_revision): |
Darryl Green | e29ce70 | 2019-03-05 15:23:25 +0000 | [diff] [blame] | 229 | return |
| 230 | |
Darryl Green | 7c1a733 | 2019-03-05 16:25:38 +0000 | [diff] [blame] | 231 | if version.crypto_repository: |
Darryl Green | b2ee0b8 | 2019-04-12 16:24:25 +0100 | [diff] [blame] | 232 | fetch_output = subprocess.check_output( |
Darryl Green | 1d95c53 | 2019-03-08 11:12:19 +0000 | [diff] [blame] | 233 | [self.git_command, "fetch", version.crypto_repository, |
| 234 | version.crypto_revision], |
Darryl Green | e29ce70 | 2019-03-05 15:23:25 +0000 | [diff] [blame] | 235 | cwd=os.path.join(git_worktree_path, "crypto"), |
Darryl Green | e29ce70 | 2019-03-05 15:23:25 +0000 | [diff] [blame] | 236 | stderr=subprocess.STDOUT |
| 237 | ) |
Darryl Green | 3c3da79 | 2019-03-08 11:30:04 +0000 | [diff] [blame] | 238 | self.log.debug(fetch_output.decode("utf-8")) |
Darryl Green | 1d95c53 | 2019-03-08 11:12:19 +0000 | [diff] [blame] | 239 | crypto_rev = "FETCH_HEAD" |
| 240 | else: |
| 241 | crypto_rev = version.crypto_revision |
| 242 | |
Darryl Green | b2ee0b8 | 2019-04-12 16:24:25 +0100 | [diff] [blame] | 243 | checkout_output = subprocess.check_output( |
Darryl Green | 1d95c53 | 2019-03-08 11:12:19 +0000 | [diff] [blame] | 244 | [self.git_command, "checkout", crypto_rev], |
| 245 | cwd=os.path.join(git_worktree_path, "crypto"), |
Darryl Green | 1d95c53 | 2019-03-08 11:12:19 +0000 | [diff] [blame] | 246 | stderr=subprocess.STDOUT |
| 247 | ) |
Darryl Green | 3c3da79 | 2019-03-08 11:30:04 +0000 | [diff] [blame] | 248 | self.log.debug(checkout_output.decode("utf-8")) |
Jaeden Amero | ffeb1b8 | 2018-11-02 16:35:09 +0000 | [diff] [blame] | 249 | |
Darryl Green | 3a5f6c8 | 2019-03-05 16:30:39 +0000 | [diff] [blame] | 250 | def _build_shared_libraries(self, git_worktree_path, version): |
Gilles Peskine | 712afa7 | 2019-02-25 20:36:52 +0100 | [diff] [blame] | 251 | """Build the shared libraries in the specified worktree.""" |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 252 | my_environment = os.environ.copy() |
| 253 | my_environment["CFLAGS"] = "-g -Og" |
| 254 | my_environment["SHARED"] = "1" |
Darryl Green | d2dba36 | 2019-05-09 13:03:05 +0100 | [diff] [blame] | 255 | if os.path.exists(os.path.join(git_worktree_path, "crypto")): |
| 256 | my_environment["USE_CRYPTO_SUBMODULE"] = "1" |
Ronald Cron | bb02ec1 | 2025-08-28 14:43:59 +0200 | [diff] [blame] | 257 | |
| 258 | if os.path.exists(os.path.join(git_worktree_path, "scripts", "legacy.make")): |
| 259 | command = [self.make_command, "-f", "scripts/legacy.make", "lib"] |
| 260 | else: |
| 261 | command = [self.make_command, "lib"] |
| 262 | |
Darryl Green | b2ee0b8 | 2019-04-12 16:24:25 +0100 | [diff] [blame] | 263 | make_output = subprocess.check_output( |
Ronald Cron | bb02ec1 | 2025-08-28 14:43:59 +0200 | [diff] [blame] | 264 | command, |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 265 | env=my_environment, |
| 266 | cwd=git_worktree_path, |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 267 | stderr=subprocess.STDOUT |
| 268 | ) |
Darryl Green | 3c3da79 | 2019-03-08 11:30:04 +0000 | [diff] [blame] | 269 | self.log.debug(make_output.decode("utf-8")) |
Darryl Green | f025d53 | 2019-04-12 15:18:02 +0100 | [diff] [blame] | 270 | for root, _dirs, files in os.walk(git_worktree_path): |
Darryl Green | 9f357d6 | 2019-02-25 11:35:05 +0000 | [diff] [blame] | 271 | for file in fnmatch.filter(files, "*.so"): |
Darryl Green | 7c1a733 | 2019-03-05 16:25:38 +0000 | [diff] [blame] | 272 | version.modules[os.path.splitext(file)[0]] = ( |
Darryl Green | 3e7a980 | 2019-02-27 16:53:40 +0000 | [diff] [blame] | 273 | os.path.join(root, file) |
Darryl Green | 9f357d6 | 2019-02-25 11:35:05 +0000 | [diff] [blame] | 274 | ) |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 275 | |
Gilles Peskine | 3e2da4a | 2019-07-04 19:01:22 +0200 | [diff] [blame] | 276 | @staticmethod |
| 277 | def _pretty_revision(version): |
| 278 | if version.revision == version.commit: |
| 279 | return version.revision |
| 280 | else: |
| 281 | return "{} ({})".format(version.revision, version.commit) |
| 282 | |
Darryl Green | 8184df5 | 2019-04-05 17:06:17 +0100 | [diff] [blame] | 283 | def _get_abi_dumps_from_shared_libraries(self, version): |
Gilles Peskine | 712afa7 | 2019-02-25 20:36:52 +0100 | [diff] [blame] | 284 | """Generate the ABI dumps for the specified git revision. |
Darryl Green | 8184df5 | 2019-04-05 17:06:17 +0100 | [diff] [blame] | 285 | The shared libraries must have been built and the module paths |
| 286 | present in version.modules.""" |
Darryl Green | 7c1a733 | 2019-03-05 16:25:38 +0000 | [diff] [blame] | 287 | for mbed_module, module_path in version.modules.items(): |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 288 | output_path = os.path.join( |
Darryl Green | fe9a675 | 2019-04-04 14:39:33 +0100 | [diff] [blame] | 289 | self.report_dir, "{}-{}-{}.dump".format( |
| 290 | mbed_module, version.revision, version.version |
Darryl Green | 3e7a980 | 2019-02-27 16:53:40 +0000 | [diff] [blame] | 291 | ) |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 292 | ) |
| 293 | abi_dump_command = [ |
| 294 | "abi-dumper", |
Darryl Green | 9f357d6 | 2019-02-25 11:35:05 +0000 | [diff] [blame] | 295 | module_path, |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 296 | "-o", output_path, |
Gilles Peskine | 3e2da4a | 2019-07-04 19:01:22 +0200 | [diff] [blame] | 297 | "-lver", self._pretty_revision(version), |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 298 | ] |
Darryl Green | b2ee0b8 | 2019-04-12 16:24:25 +0100 | [diff] [blame] | 299 | abi_dump_output = subprocess.check_output( |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 300 | abi_dump_command, |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 301 | stderr=subprocess.STDOUT |
| 302 | ) |
Darryl Green | 3c3da79 | 2019-03-08 11:30:04 +0000 | [diff] [blame] | 303 | self.log.debug(abi_dump_output.decode("utf-8")) |
Darryl Green | 7c1a733 | 2019-03-05 16:25:38 +0000 | [diff] [blame] | 304 | version.abi_dumps[mbed_module] = output_path |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 305 | |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 306 | @staticmethod |
| 307 | def _normalize_storage_test_case_data(line): |
| 308 | """Eliminate cosmetic or irrelevant details in storage format test cases.""" |
| 309 | line = re.sub(r'\s+', r'', line) |
| 310 | return line |
| 311 | |
Gilles Peskine | ca586a5 | 2022-02-22 19:02:44 +0100 | [diff] [blame] | 312 | def _read_storage_tests(self, |
| 313 | directory, |
| 314 | filename, |
| 315 | is_generated, |
| 316 | storage_tests): |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 317 | """Record storage tests from the given file. |
| 318 | |
| 319 | Populate the storage_tests dictionary with test cases read from |
| 320 | filename under directory. |
| 321 | """ |
| 322 | at_paragraph_start = True |
| 323 | description = None |
| 324 | full_path = os.path.join(directory, filename) |
Gilles Peskine | dcf2ff5 | 2022-03-04 20:02:00 +0100 | [diff] [blame] | 325 | with open(full_path) as fd: |
| 326 | for line_number, line in enumerate(fd, 1): |
| 327 | line = line.strip() |
| 328 | if not line: |
| 329 | at_paragraph_start = True |
Gilles Peskine | ca586a5 | 2022-02-22 19:02:44 +0100 | [diff] [blame] | 330 | continue |
Gilles Peskine | dcf2ff5 | 2022-03-04 20:02:00 +0100 | [diff] [blame] | 331 | if line.startswith('#'): |
| 332 | continue |
| 333 | if at_paragraph_start: |
| 334 | description = line.strip() |
| 335 | at_paragraph_start = False |
| 336 | continue |
| 337 | if line.startswith('depends_on:'): |
| 338 | continue |
| 339 | # We've reached a test case data line |
| 340 | test_case_data = self._normalize_storage_test_case_data(line) |
| 341 | if not is_generated: |
| 342 | # In manual test data, only look at read tests. |
| 343 | function_name = test_case_data.split(':', 1)[0] |
| 344 | if 'read' not in function_name.split('_'): |
| 345 | continue |
| 346 | metadata = SimpleNamespace( |
| 347 | filename=filename, |
| 348 | line_number=line_number, |
| 349 | description=description |
| 350 | ) |
| 351 | storage_tests[test_case_data] = metadata |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 352 | |
Gilles Peskine | ca586a5 | 2022-02-22 19:02:44 +0100 | [diff] [blame] | 353 | @staticmethod |
| 354 | def _list_generated_test_data_files(git_worktree_path): |
| 355 | """List the generated test data files.""" |
David Horstmann | b8360cf | 2024-05-31 14:38:52 +0100 | [diff] [blame] | 356 | generate_psa_tests = 'framework/scripts/generate_psa_tests.py' |
| 357 | if not os.path.isfile(git_worktree_path + '/' + generate_psa_tests): |
| 358 | # The checked-out revision is from before generate_psa_tests.py |
| 359 | # was moved to the framework submodule. Use the old location. |
| 360 | generate_psa_tests = 'tests/scripts/generate_psa_tests.py' |
| 361 | |
Gilles Peskine | ca586a5 | 2022-02-22 19:02:44 +0100 | [diff] [blame] | 362 | output = subprocess.check_output( |
David Horstmann | b8360cf | 2024-05-31 14:38:52 +0100 | [diff] [blame] | 363 | [generate_psa_tests, '--list'], |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 364 | cwd=git_worktree_path, |
| 365 | ).decode('ascii') |
Gilles Peskine | ca586a5 | 2022-02-22 19:02:44 +0100 | [diff] [blame] | 366 | return [line for line in output.split('\n') if line] |
| 367 | |
| 368 | def _get_storage_format_tests(self, version, git_worktree_path): |
| 369 | """Record the storage format tests for the specified git version. |
| 370 | |
| 371 | The storage format tests are the test suite data files whose name |
| 372 | contains "storage_format". |
| 373 | |
| 374 | The version must be checked out at git_worktree_path. |
| 375 | |
| 376 | This function creates or updates the generated data files. |
| 377 | """ |
| 378 | # Existing test data files. This may be missing some automatically |
| 379 | # generated files if they haven't been generated yet. |
Ronald Cron | 5903be2 | 2024-07-11 19:50:54 +0200 | [diff] [blame] | 380 | if os.path.isdir(os.path.join(git_worktree_path, 'tf-psa-crypto', |
| 381 | 'tests', 'suites')): |
| 382 | storage_data_files = set(glob.glob( |
| 383 | 'tf-psa-crypto/tests/suites/test_suite_*storage_format*.data' |
| 384 | )) |
| 385 | else: |
| 386 | storage_data_files = set(glob.glob( |
| 387 | 'tests/suites/test_suite_*storage_format*.data' |
| 388 | )) |
Gilles Peskine | ca586a5 | 2022-02-22 19:02:44 +0100 | [diff] [blame] | 389 | # Discover and (re)generate automatically generated data files. |
| 390 | to_be_generated = set() |
| 391 | for filename in self._list_generated_test_data_files(git_worktree_path): |
| 392 | if 'storage_format' in filename: |
| 393 | storage_data_files.add(filename) |
| 394 | to_be_generated.add(filename) |
David Horstmann | b8360cf | 2024-05-31 14:38:52 +0100 | [diff] [blame] | 395 | |
| 396 | generate_psa_tests = 'framework/scripts/generate_psa_tests.py' |
| 397 | if not os.path.isfile(git_worktree_path + '/' + generate_psa_tests): |
| 398 | # The checked-out revision is from before generate_psa_tests.py |
| 399 | # was moved to the framework submodule. Use the old location. |
| 400 | generate_psa_tests = 'tests/scripts/generate_psa_tests.py' |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 401 | subprocess.check_call( |
David Horstmann | b8360cf | 2024-05-31 14:38:52 +0100 | [diff] [blame] | 402 | [generate_psa_tests] + sorted(to_be_generated), |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 403 | cwd=git_worktree_path, |
| 404 | ) |
Gilles Peskine | ca586a5 | 2022-02-22 19:02:44 +0100 | [diff] [blame] | 405 | for test_file in sorted(storage_data_files): |
| 406 | self._read_storage_tests(git_worktree_path, |
| 407 | test_file, |
| 408 | test_file in to_be_generated, |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 409 | version.storage_tests) |
| 410 | |
Darryl Green | 3a5f6c8 | 2019-03-05 16:30:39 +0000 | [diff] [blame] | 411 | def _cleanup_worktree(self, git_worktree_path): |
Gilles Peskine | 712afa7 | 2019-02-25 20:36:52 +0100 | [diff] [blame] | 412 | """Remove the specified git worktree.""" |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 413 | shutil.rmtree(git_worktree_path) |
Bence Szépkúti | effa534 | 2025-09-25 15:51:07 +0200 | [diff] [blame] | 414 | submodule_output = subprocess.check_output( |
Bence Szépkúti | 8d95062 | 2025-09-26 15:44:11 +0200 | [diff] [blame] | 415 | [self.git_command, "submodule", "foreach", "--recursive", |
| 416 | f'git worktree remove "{git_worktree_path}/$displaypath"'], |
Bence Szépkúti | effa534 | 2025-09-25 15:51:07 +0200 | [diff] [blame] | 417 | cwd=self.repo_path, |
| 418 | stderr=subprocess.STDOUT |
| 419 | ) |
| 420 | self.log.debug(submodule_output.decode("utf-8")) |
Darryl Green | b2ee0b8 | 2019-04-12 16:24:25 +0100 | [diff] [blame] | 421 | worktree_output = subprocess.check_output( |
Bence Szépkúti | 8d95062 | 2025-09-26 15:44:11 +0200 | [diff] [blame] | 422 | [self.git_command, "worktree", "remove", git_worktree_path], |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 423 | cwd=self.repo_path, |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 424 | stderr=subprocess.STDOUT |
| 425 | ) |
Darryl Green | 3c3da79 | 2019-03-08 11:30:04 +0000 | [diff] [blame] | 426 | self.log.debug(worktree_output.decode("utf-8")) |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 427 | |
Darryl Green | 3a5f6c8 | 2019-03-05 16:30:39 +0000 | [diff] [blame] | 428 | def _get_abi_dump_for_ref(self, version): |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 429 | """Generate the interface information for the specified git revision.""" |
Darryl Green | 3a5f6c8 | 2019-03-05 16:30:39 +0000 | [diff] [blame] | 430 | git_worktree_path = self._get_clean_worktree_for_git_revision(version) |
| 431 | self._update_git_submodules(git_worktree_path, version) |
Gilles Peskine | c76ab85 | 2021-04-23 16:32:32 +0200 | [diff] [blame] | 432 | if self.check_abi: |
| 433 | self._build_shared_libraries(git_worktree_path, version) |
| 434 | self._get_abi_dumps_from_shared_libraries(version) |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 435 | if self.check_storage_tests: |
| 436 | self._get_storage_format_tests(version, git_worktree_path) |
Darryl Green | 3a5f6c8 | 2019-03-05 16:30:39 +0000 | [diff] [blame] | 437 | self._cleanup_worktree(git_worktree_path) |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 438 | |
Darryl Green | 3a5f6c8 | 2019-03-05 16:30:39 +0000 | [diff] [blame] | 439 | def _remove_children_with_tag(self, parent, tag): |
Darryl Green | e62f9bb | 2019-02-21 13:09:26 +0000 | [diff] [blame] | 440 | children = parent.getchildren() |
| 441 | for child in children: |
| 442 | if child.tag == tag: |
| 443 | parent.remove(child) |
| 444 | else: |
Darryl Green | 3a5f6c8 | 2019-03-05 16:30:39 +0000 | [diff] [blame] | 445 | self._remove_children_with_tag(child, tag) |
Darryl Green | e62f9bb | 2019-02-21 13:09:26 +0000 | [diff] [blame] | 446 | |
Darryl Green | 3a5f6c8 | 2019-03-05 16:30:39 +0000 | [diff] [blame] | 447 | def _remove_extra_detail_from_report(self, report_root): |
Darryl Green | e62f9bb | 2019-02-21 13:09:26 +0000 | [diff] [blame] | 448 | for tag in ['test_info', 'test_results', 'problem_summary', |
Darryl Green | c6f874b | 2019-06-05 12:57:50 +0100 | [diff] [blame] | 449 | 'added_symbols', 'affected']: |
Darryl Green | 3a5f6c8 | 2019-03-05 16:30:39 +0000 | [diff] [blame] | 450 | self._remove_children_with_tag(report_root, tag) |
Darryl Green | e62f9bb | 2019-02-21 13:09:26 +0000 | [diff] [blame] | 451 | |
| 452 | for report in report_root: |
| 453 | for problems in report.getchildren()[:]: |
| 454 | if not problems.getchildren(): |
| 455 | report.remove(problems) |
| 456 | |
Gilles Peskine | ada828f | 2019-07-04 19:17:40 +0200 | [diff] [blame] | 457 | def _abi_compliance_command(self, mbed_module, output_path): |
| 458 | """Build the command to run to analyze the library mbed_module. |
| 459 | The report will be placed in output_path.""" |
| 460 | abi_compliance_command = [ |
| 461 | "abi-compliance-checker", |
| 462 | "-l", mbed_module, |
| 463 | "-old", self.old_version.abi_dumps[mbed_module], |
| 464 | "-new", self.new_version.abi_dumps[mbed_module], |
| 465 | "-strict", |
| 466 | "-report-path", output_path, |
| 467 | ] |
| 468 | if self.skip_file: |
| 469 | abi_compliance_command += ["-skip-symbols", self.skip_file, |
| 470 | "-skip-types", self.skip_file] |
| 471 | if self.brief: |
| 472 | abi_compliance_command += ["-report-format", "xml", |
| 473 | "-stdout"] |
| 474 | return abi_compliance_command |
| 475 | |
| 476 | def _is_library_compatible(self, mbed_module, compatibility_report): |
| 477 | """Test if the library mbed_module has remained compatible. |
| 478 | Append a message regarding compatibility to compatibility_report.""" |
| 479 | output_path = os.path.join( |
| 480 | self.report_dir, "{}-{}-{}.html".format( |
| 481 | mbed_module, self.old_version.revision, |
| 482 | self.new_version.revision |
| 483 | ) |
| 484 | ) |
| 485 | try: |
| 486 | subprocess.check_output( |
| 487 | self._abi_compliance_command(mbed_module, output_path), |
| 488 | stderr=subprocess.STDOUT |
| 489 | ) |
| 490 | except subprocess.CalledProcessError as err: |
| 491 | if err.returncode != 1: |
| 492 | raise err |
| 493 | if self.brief: |
| 494 | self.log.info( |
| 495 | "Compatibility issues found for {}".format(mbed_module) |
| 496 | ) |
| 497 | report_root = ET.fromstring(err.output.decode("utf-8")) |
| 498 | self._remove_extra_detail_from_report(report_root) |
| 499 | self.log.info(ET.tostring(report_root).decode("utf-8")) |
| 500 | else: |
| 501 | self.can_remove_report_dir = False |
| 502 | compatibility_report.append( |
| 503 | "Compatibility issues found for {}, " |
| 504 | "for details see {}".format(mbed_module, output_path) |
| 505 | ) |
| 506 | return False |
| 507 | compatibility_report.append( |
| 508 | "No compatibility issues for {}".format(mbed_module) |
| 509 | ) |
| 510 | if not (self.keep_all_reports or self.brief): |
| 511 | os.remove(output_path) |
| 512 | return True |
| 513 | |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 514 | @staticmethod |
| 515 | def _is_storage_format_compatible(old_tests, new_tests, |
| 516 | compatibility_report): |
| 517 | """Check whether all tests present in old_tests are also in new_tests. |
| 518 | |
| 519 | Append a message regarding compatibility to compatibility_report. |
| 520 | """ |
| 521 | missing = frozenset(old_tests.keys()).difference(new_tests.keys()) |
| 522 | for test_data in sorted(missing): |
| 523 | metadata = old_tests[test_data] |
| 524 | compatibility_report.append( |
| 525 | 'Test case from {} line {} "{}" has disappeared: {}'.format( |
| 526 | metadata.filename, metadata.line_number, |
| 527 | metadata.description, test_data |
| 528 | ) |
| 529 | ) |
| 530 | compatibility_report.append( |
| 531 | 'FAIL: {}/{} storage format test cases have changed or disappeared.'.format( |
| 532 | len(missing), len(old_tests) |
| 533 | ) if missing else |
| 534 | 'PASS: All {} storage format test cases are preserved.'.format( |
| 535 | len(old_tests) |
| 536 | ) |
| 537 | ) |
| 538 | compatibility_report.append( |
| 539 | 'Info: number of storage format tests cases: {} -> {}.'.format( |
| 540 | len(old_tests), len(new_tests) |
| 541 | ) |
| 542 | ) |
| 543 | return not missing |
| 544 | |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 545 | def get_abi_compatibility_report(self): |
Gilles Peskine | 712afa7 | 2019-02-25 20:36:52 +0100 | [diff] [blame] | 546 | """Generate a report of the differences between the reference ABI |
Darryl Green | 8184df5 | 2019-04-05 17:06:17 +0100 | [diff] [blame] | 547 | and the new ABI. ABI dumps from self.old_version and self.new_version |
| 548 | must be available.""" |
Gilles Peskine | ada828f | 2019-07-04 19:17:40 +0200 | [diff] [blame] | 549 | compatibility_report = ["Checking evolution from {} to {}".format( |
Gilles Peskine | 3e2da4a | 2019-07-04 19:01:22 +0200 | [diff] [blame] | 550 | self._pretty_revision(self.old_version), |
| 551 | self._pretty_revision(self.new_version) |
Gilles Peskine | ada828f | 2019-07-04 19:17:40 +0200 | [diff] [blame] | 552 | )] |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 553 | compliance_return_code = 0 |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 554 | |
Gilles Peskine | c76ab85 | 2021-04-23 16:32:32 +0200 | [diff] [blame] | 555 | if self.check_abi: |
| 556 | shared_modules = list(set(self.old_version.modules.keys()) & |
| 557 | set(self.new_version.modules.keys())) |
| 558 | for mbed_module in shared_modules: |
| 559 | if not self._is_library_compatible(mbed_module, |
| 560 | compatibility_report): |
| 561 | compliance_return_code = 1 |
| 562 | |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 563 | if self.check_storage_tests: |
| 564 | if not self._is_storage_format_compatible( |
| 565 | self.old_version.storage_tests, |
| 566 | self.new_version.storage_tests, |
| 567 | compatibility_report): |
Gilles Peskine | ada828f | 2019-07-04 19:17:40 +0200 | [diff] [blame] | 568 | compliance_return_code = 1 |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 569 | |
Darryl Green | f2688e2 | 2019-05-29 11:29:08 +0100 | [diff] [blame] | 570 | for version in [self.old_version, self.new_version]: |
| 571 | for mbed_module, mbed_module_dump in version.abi_dumps.items(): |
| 572 | os.remove(mbed_module_dump) |
Darryl Green | 3d3d552 | 2019-02-25 17:01:55 +0000 | [diff] [blame] | 573 | if self.can_remove_report_dir: |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 574 | os.rmdir(self.report_dir) |
Gilles Peskine | ada828f | 2019-07-04 19:17:40 +0200 | [diff] [blame] | 575 | self.log.info("\n".join(compatibility_report)) |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 576 | return compliance_return_code |
| 577 | |
| 578 | def check_for_abi_changes(self): |
Gilles Peskine | 712afa7 | 2019-02-25 20:36:52 +0100 | [diff] [blame] | 579 | """Generate a report of ABI differences |
| 580 | between self.old_rev and self.new_rev.""" |
Gilles Peskine | d9071e7 | 2022-09-18 21:17:09 +0200 | [diff] [blame] | 581 | build_tree.check_repo_path() |
Gilles Peskine | 93c2a42 | 2022-03-03 10:22:36 +0100 | [diff] [blame] | 582 | if self.check_api or self.check_abi: |
| 583 | self.check_abi_tools_are_installed() |
Darryl Green | 3a5f6c8 | 2019-03-05 16:30:39 +0000 | [diff] [blame] | 584 | self._get_abi_dump_for_ref(self.old_version) |
| 585 | self._get_abi_dump_for_ref(self.new_version) |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 586 | return self.get_abi_compatibility_report() |
| 587 | |
| 588 | |
| 589 | def run_main(): |
| 590 | try: |
| 591 | parser = argparse.ArgumentParser( |
Gilles Peskine | 644b3f6 | 2022-03-03 10:23:09 +0100 | [diff] [blame] | 592 | description=__doc__ |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 593 | ) |
| 594 | parser.add_argument( |
Darryl Green | 3c3da79 | 2019-03-08 11:30:04 +0000 | [diff] [blame] | 595 | "-v", "--verbose", action="store_true", |
| 596 | help="set verbosity level", |
| 597 | ) |
| 598 | parser.add_argument( |
Darryl Green | 418527b | 2018-04-16 12:02:29 +0100 | [diff] [blame] | 599 | "-r", "--report-dir", type=str, default="reports", |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 600 | help="directory where reports are stored, default is reports", |
| 601 | ) |
| 602 | parser.add_argument( |
Darryl Green | 418527b | 2018-04-16 12:02:29 +0100 | [diff] [blame] | 603 | "-k", "--keep-all-reports", action="store_true", |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 604 | help="keep all reports, even if there are no compatibility issues", |
| 605 | ) |
| 606 | parser.add_argument( |
Darryl Green | c5132ff | 2019-03-01 09:54:44 +0000 | [diff] [blame] | 607 | "-o", "--old-rev", type=str, help="revision for old version.", |
| 608 | required=True, |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 609 | ) |
| 610 | parser.add_argument( |
Darryl Green | c5132ff | 2019-03-01 09:54:44 +0000 | [diff] [blame] | 611 | "-or", "--old-repo", type=str, help="repository for old version." |
Darryl Green | 9f357d6 | 2019-02-25 11:35:05 +0000 | [diff] [blame] | 612 | ) |
| 613 | parser.add_argument( |
Darryl Green | c5132ff | 2019-03-01 09:54:44 +0000 | [diff] [blame] | 614 | "-oc", "--old-crypto-rev", type=str, |
| 615 | help="revision for old crypto submodule." |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 616 | ) |
Darryl Green | c2883a2 | 2019-02-20 15:01:56 +0000 | [diff] [blame] | 617 | parser.add_argument( |
Darryl Green | c5132ff | 2019-03-01 09:54:44 +0000 | [diff] [blame] | 618 | "-ocr", "--old-crypto-repo", type=str, |
| 619 | help="repository for old crypto submodule." |
| 620 | ) |
| 621 | parser.add_argument( |
| 622 | "-n", "--new-rev", type=str, help="revision for new version", |
| 623 | required=True, |
| 624 | ) |
| 625 | parser.add_argument( |
| 626 | "-nr", "--new-repo", type=str, help="repository for new version." |
| 627 | ) |
| 628 | parser.add_argument( |
| 629 | "-nc", "--new-crypto-rev", type=str, |
| 630 | help="revision for new crypto version" |
| 631 | ) |
| 632 | parser.add_argument( |
| 633 | "-ncr", "--new-crypto-repo", type=str, |
| 634 | help="repository for new crypto submodule." |
Darryl Green | 9f357d6 | 2019-02-25 11:35:05 +0000 | [diff] [blame] | 635 | ) |
| 636 | parser.add_argument( |
Darryl Green | c2883a2 | 2019-02-20 15:01:56 +0000 | [diff] [blame] | 637 | "-s", "--skip-file", type=str, |
Gilles Peskine | b6ce234 | 2019-07-04 19:00:31 +0200 | [diff] [blame] | 638 | help=("path to file containing symbols and types to skip " |
| 639 | "(typically \"-s identifiers\" after running " |
| 640 | "\"tests/scripts/list-identifiers.sh --internal\")") |
Darryl Green | c2883a2 | 2019-02-20 15:01:56 +0000 | [diff] [blame] | 641 | ) |
Darryl Green | e62f9bb | 2019-02-21 13:09:26 +0000 | [diff] [blame] | 642 | parser.add_argument( |
Gilles Peskine | c76ab85 | 2021-04-23 16:32:32 +0200 | [diff] [blame] | 643 | "--check-abi", |
| 644 | action='store_true', default=True, |
| 645 | help="Perform ABI comparison (default: yes)" |
| 646 | ) |
| 647 | parser.add_argument("--no-check-abi", action='store_false', dest='check_abi') |
| 648 | parser.add_argument( |
| 649 | "--check-api", |
| 650 | action='store_true', default=True, |
| 651 | help="Perform API comparison (default: yes)" |
| 652 | ) |
| 653 | parser.add_argument("--no-check-api", action='store_false', dest='check_api') |
| 654 | parser.add_argument( |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 655 | "--check-storage", |
| 656 | action='store_true', default=True, |
| 657 | help="Perform storage tests comparison (default: yes)" |
| 658 | ) |
| 659 | parser.add_argument("--no-check-storage", action='store_false', dest='check_storage') |
| 660 | parser.add_argument( |
Darryl Green | e62f9bb | 2019-02-21 13:09:26 +0000 | [diff] [blame] | 661 | "-b", "--brief", action="store_true", |
| 662 | help="output only the list of issues to stdout, instead of a full report", |
| 663 | ) |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 664 | abi_args = parser.parse_args() |
Darryl Green | 492bc40 | 2019-04-11 15:50:41 +0100 | [diff] [blame] | 665 | if os.path.isfile(abi_args.report_dir): |
| 666 | print("Error: {} is not a directory".format(abi_args.report_dir)) |
| 667 | parser.exit() |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 668 | old_version = SimpleNamespace( |
| 669 | version="old", |
| 670 | repository=abi_args.old_repo, |
| 671 | revision=abi_args.old_rev, |
Gilles Peskine | 3e2da4a | 2019-07-04 19:01:22 +0200 | [diff] [blame] | 672 | commit=None, |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 673 | crypto_repository=abi_args.old_crypto_repo, |
| 674 | crypto_revision=abi_args.old_crypto_rev, |
| 675 | abi_dumps={}, |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 676 | storage_tests={}, |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 677 | modules={} |
Darryl Green | 8184df5 | 2019-04-05 17:06:17 +0100 | [diff] [blame] | 678 | ) |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 679 | new_version = SimpleNamespace( |
| 680 | version="new", |
| 681 | repository=abi_args.new_repo, |
| 682 | revision=abi_args.new_rev, |
Gilles Peskine | 3e2da4a | 2019-07-04 19:01:22 +0200 | [diff] [blame] | 683 | commit=None, |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 684 | crypto_repository=abi_args.new_crypto_repo, |
| 685 | crypto_revision=abi_args.new_crypto_rev, |
| 686 | abi_dumps={}, |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 687 | storage_tests={}, |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 688 | modules={} |
Darryl Green | 8184df5 | 2019-04-05 17:06:17 +0100 | [diff] [blame] | 689 | ) |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 690 | configuration = SimpleNamespace( |
| 691 | verbose=abi_args.verbose, |
| 692 | report_dir=abi_args.report_dir, |
| 693 | keep_all_reports=abi_args.keep_all_reports, |
| 694 | brief=abi_args.brief, |
Gilles Peskine | c76ab85 | 2021-04-23 16:32:32 +0200 | [diff] [blame] | 695 | check_abi=abi_args.check_abi, |
| 696 | check_api=abi_args.check_api, |
Gilles Peskine | 9216536 | 2021-04-23 16:37:12 +0200 | [diff] [blame] | 697 | check_storage=abi_args.check_storage, |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 698 | skip_file=abi_args.skip_file |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 699 | ) |
Darryl Green | 0d1ca51 | 2019-04-09 09:14:17 +0100 | [diff] [blame] | 700 | abi_check = AbiChecker(old_version, new_version, configuration) |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 701 | return_code = abi_check.check_for_abi_changes() |
| 702 | sys.exit(return_code) |
Gilles Peskine | e915d53 | 2019-02-25 21:39:42 +0100 | [diff] [blame] | 703 | except Exception: # pylint: disable=broad-except |
| 704 | # Print the backtrace and exit explicitly so as to exit with |
| 705 | # status 2, not 1. |
Darryl Green | a6f430f | 2018-03-15 10:12:06 +0000 | [diff] [blame] | 706 | traceback.print_exc() |
Darryl Green | 7c2dd58 | 2018-03-01 14:53:49 +0000 | [diff] [blame] | 707 | sys.exit(2) |
| 708 | |
| 709 | |
| 710 | if __name__ == "__main__": |
| 711 | run_main() |