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