Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 1 | # Copyright lowRISC contributors. |
| 2 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 4 | |
| 5 | import logging as log |
| 6 | import pprint |
Srikrishna Iyer | 7cf7cad | 2020-01-08 11:32:53 -0800 | [diff] [blame] | 7 | import random |
Srikrishna Iyer | 37b0c99 | 2021-03-23 16:27:26 -0700 | [diff] [blame] | 8 | import shlex |
Srikrishna Iyer | 956b3f8 | 2021-04-15 15:14:56 -0700 | [diff] [blame] | 9 | from pathlib import Path |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 10 | |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 11 | from LauncherFactory import get_launcher |
Rupert Swarbrick | 6cc2011 | 2020-04-24 09:44:35 +0100 | [diff] [blame] | 12 | from sim_utils import get_cov_summary_table |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 13 | from tabulate import tabulate |
Srikrishna Iyer | caa0d89 | 2021-03-01 13:15:52 -0800 | [diff] [blame] | 14 | from utils import (VERBOSE, clean_odirs, find_and_substitute_wildcards, |
| 15 | rm_path, subst_wildcards) |
Rupert Swarbrick | a2892a5 | 2020-10-12 08:50:08 +0100 | [diff] [blame] | 16 | |
| 17 | |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 18 | class Deploy(): |
| 19 | """ |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 20 | Abstraction to create and maintain a runnable job (builds, runs, etc.). |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 21 | """ |
| 22 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 23 | # Indicate the target for each sub-class. |
| 24 | target = None |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 25 | |
Srikrishna Iyer | 6c531b0 | 2020-11-23 18:41:16 -0800 | [diff] [blame] | 26 | # List of variable names that are to be treated as "list of commands". |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 27 | # This tells '_construct_cmd' that these vars are lists that need to |
Srikrishna Iyer | 6c531b0 | 2020-11-23 18:41:16 -0800 | [diff] [blame] | 28 | # be joined with '&&' instead of a space. |
| 29 | cmds_list_vars = [] |
| 30 | |
Srikrishna Iyer | 1d2899f | 2021-02-11 18:23:15 -0800 | [diff] [blame] | 31 | # Represents the weight with which a job of this target is scheduled. These |
| 32 | # initial weights set for each of the targets below are roughly inversely |
| 33 | # proportional to their average runtimes. These are subject to change in |
| 34 | # future. Lower the runtime, the higher chance the it gets scheduled. It is |
| 35 | # useful to customize this only in case of targets that may coexist at a |
| 36 | # time. |
| 37 | # TODO: Allow these to be set in the HJson. |
| 38 | weight = 1 |
| 39 | |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 40 | def __str__(self): |
Rupert Swarbrick | 381770d | 2020-10-12 08:50:08 +0100 | [diff] [blame] | 41 | return (pprint.pformat(self.__dict__) |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 42 | if log.getLogger().isEnabledFor(VERBOSE) else self.full_name) |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 43 | |
Srikrishna Iyer | 7cf7cad | 2020-01-08 11:32:53 -0800 | [diff] [blame] | 44 | def __init__(self, sim_cfg): |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 45 | assert self.target is not None |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 46 | |
Srikrishna Iyer | 7cf7cad | 2020-01-08 11:32:53 -0800 | [diff] [blame] | 47 | # Cross ref the whole cfg object for ease. |
| 48 | self.sim_cfg = sim_cfg |
| 49 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 50 | # A list of jobs on which this job depends. |
Rupert Swarbrick | 381770d | 2020-10-12 08:50:08 +0100 | [diff] [blame] | 51 | self.dependencies = [] |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 52 | |
Cindy Chen | 924c606 | 2021-01-27 14:27:50 -0800 | [diff] [blame] | 53 | # Indicates whether running this job requires all dependencies to pass. |
| 54 | # If this flag is set to False, any passing dependency will trigger |
| 55 | # this current job to run |
| 56 | self.needs_all_dependencies_passing = True |
| 57 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 58 | # Declare attributes that need to be extracted from the HJSon cfg. |
| 59 | self._define_attrs() |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 60 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 61 | # Set class instance attributes. |
| 62 | self._set_attrs() |
| 63 | |
| 64 | # Check if all attributes that are needed are set. |
| 65 | self._check_attrs() |
| 66 | |
| 67 | # Do variable substitutions. |
| 68 | self._subst_vars() |
| 69 | |
| 70 | # List of vars required to be exported to sub-shell, as a dict. |
| 71 | self.exports = self._process_exports() |
| 72 | |
| 73 | # Construct the job's command. |
| 74 | self.cmd = self._construct_cmd() |
| 75 | |
| 76 | # Create the launcher object. Launcher retains the handle to self for |
| 77 | # lookup & callbacks. |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 78 | self.launcher = get_launcher(self) |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 79 | |
| 80 | def _define_attrs(self): |
| 81 | """Defines the attributes this instance needs to have. |
| 82 | |
| 83 | These attributes are extracted from the Mode object / HJson config with |
| 84 | which this instance is created. There are two types of attributes - |
| 85 | one contributes to the generation of the command directly; the other |
| 86 | provides supplementary information pertaining to the job, such as |
| 87 | patterns that determine whether it passed or failed. These are |
| 88 | represented as dicts, whose values indicate in boolean whether the |
| 89 | extraction was successful. |
| 90 | """ |
| 91 | # These attributes are explicitly used to construct the job command. |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 92 | self.mandatory_cmd_attrs = {} |
| 93 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 94 | # These attributes may indirectly contribute to the construction of the |
| 95 | # command (through substitution vars) or other things such as pass / |
| 96 | # fail patterns. |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 97 | self.mandatory_misc_attrs = { |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 98 | "name": False, |
| 99 | "build_mode": False, |
| 100 | "flow_makefile": False, |
| 101 | "exports": False, |
| 102 | "dry_run": False |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 103 | } |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 104 | |
Srikrishna Iyer | 7cf7cad | 2020-01-08 11:32:53 -0800 | [diff] [blame] | 105 | # Function to parse a dict and extract the mandatory cmd and misc attrs. |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 106 | def _extract_attrs(self, ddict): |
| 107 | """Extracts the attributes from the supplied dict. |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 108 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 109 | 'ddict' is typically either the Mode object or the entire config |
| 110 | object's dict. It is used to retrieve the instance attributes defined |
| 111 | in 'mandatory_cmd_attrs' and 'mandatory_misc_attrs'. |
| 112 | """ |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 113 | ddict_keys = ddict.keys() |
| 114 | for key in self.mandatory_cmd_attrs.keys(): |
Rupert Swarbrick | 6cc2011 | 2020-04-24 09:44:35 +0100 | [diff] [blame] | 115 | if self.mandatory_cmd_attrs[key] is False: |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 116 | if key in ddict_keys: |
| 117 | setattr(self, key, ddict[key]) |
| 118 | self.mandatory_cmd_attrs[key] = True |
| 119 | |
| 120 | for key in self.mandatory_misc_attrs.keys(): |
Rupert Swarbrick | 6cc2011 | 2020-04-24 09:44:35 +0100 | [diff] [blame] | 121 | if self.mandatory_misc_attrs[key] is False: |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 122 | if key in ddict_keys: |
| 123 | setattr(self, key, ddict[key]) |
| 124 | self.mandatory_misc_attrs[key] = True |
| 125 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 126 | def _set_attrs(self): |
| 127 | """Sets additional attributes. |
| 128 | |
| 129 | Invokes '_extract_attrs()' to read in all the necessary instance |
| 130 | attributes. Based on those, some additional instance attributes may |
| 131 | be derived. Those are set by this method. |
| 132 | """ |
| 133 | self._extract_attrs(self.sim_cfg.__dict__) |
| 134 | |
| 135 | # Output directory where the artifacts go (used by the launcher). |
| 136 | self.odir = getattr(self, self.target + "_dir") |
| 137 | |
| 138 | # Qualified name disambiguates the instance name with other instances |
| 139 | # of the same class (example: 'uart_smoke' reseeded multiple times |
| 140 | # needs to be disambiguated using the index -> '0.uart_smoke'. |
| 141 | self.qual_name = self.name |
| 142 | |
| 143 | # Full name disambiguates across multiple cfg being run (example: |
| 144 | # 'aes:default', 'uart:default' builds. |
| 145 | self.full_name = self.sim_cfg.name + ":" + self.qual_name |
| 146 | |
Srikrishna Iyer | 956b3f8 | 2021-04-15 15:14:56 -0700 | [diff] [blame] | 147 | # Job name is used to group the job by cfg and target. The scratch path |
| 148 | # directory name is assumed to be uniquified, in case there are more |
| 149 | # than one sim_cfgs with the same name. |
| 150 | self.job_name = "{}_{}".format( |
| 151 | Path(self.sim_cfg.scratch_path).name, self.target) |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 152 | |
Srikrishna Iyer | 37b0c99 | 2021-03-23 16:27:26 -0700 | [diff] [blame] | 153 | # Input directories (other than self) this job depends on. |
| 154 | self.input_dirs = [] |
| 155 | |
| 156 | # Directories touched by this job. These directories are marked |
| 157 | # becuase they are used by dependent jobs as input. |
| 158 | self.output_dirs = [self.odir] |
| 159 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 160 | # Pass and fail patterns. |
| 161 | self.pass_patterns = [] |
| 162 | self.fail_patterns = [] |
| 163 | |
| 164 | def _check_attrs(self): |
| 165 | """Checks if all required class attributes are set. |
| 166 | |
| 167 | Invoked in __init__() after all attributes are extracted and set. |
| 168 | """ |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 169 | for attr in self.mandatory_cmd_attrs.keys(): |
| 170 | if self.mandatory_cmd_attrs[attr] is False: |
Srikrishna Iyer | 08ccc23 | 2021-03-31 00:01:54 -0700 | [diff] [blame] | 171 | raise AttributeError("Attribute {!r} not found for " |
| 172 | "{!r}.".format(attr, self.name)) |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 173 | |
| 174 | for attr in self.mandatory_misc_attrs.keys(): |
| 175 | if self.mandatory_misc_attrs[attr] is False: |
Srikrishna Iyer | 08ccc23 | 2021-03-31 00:01:54 -0700 | [diff] [blame] | 176 | raise AttributeError("Attribute {!r} not found for " |
| 177 | "{!r}.".format(attr, self.name)) |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 178 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 179 | def _subst_vars(self, ignored_subst_vars=[]): |
| 180 | """Recursively search and replace substitution variables. |
| 181 | |
| 182 | First pass: search within self dict. We ignore errors since some |
| 183 | substitions may be available in the second pass. Second pass: search |
| 184 | the entire sim_cfg object.""" |
| 185 | |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 186 | self.__dict__ = find_and_substitute_wildcards(self.__dict__, |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 187 | self.__dict__, |
| 188 | ignored_subst_vars, True) |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 189 | self.__dict__ = find_and_substitute_wildcards(self.__dict__, |
| 190 | self.sim_cfg.__dict__, |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 191 | ignored_subst_vars, |
| 192 | False) |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 193 | |
Srikrishna Iyer | 6333b7c | 2020-10-17 21:14:25 -0700 | [diff] [blame] | 194 | def _process_exports(self): |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 195 | """Convert 'exports' as a list of dicts in the HJson to a dict. |
Srikrishna Iyer | 6333b7c | 2020-10-17 21:14:25 -0700 | [diff] [blame] | 196 | |
| 197 | Exports is a list of key-value pairs that are to be exported to the |
| 198 | subprocess' environment so that the tools can lookup those options. |
| 199 | DVSim limits how the data is presented in the HJson (the value of a |
| 200 | HJson member cannot be an object). This method converts a list of dicts |
| 201 | into a dict variable, which makes it easy to merge the list of exports |
| 202 | with the subprocess' env where the ASIC tool is invoked. |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 203 | """ |
Srikrishna Iyer | 6333b7c | 2020-10-17 21:14:25 -0700 | [diff] [blame] | 204 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 205 | return {k: str(v) for item in self.exports for k, v in item.items()} |
| 206 | |
| 207 | def _construct_cmd(self): |
| 208 | """Construct the command that will eventually be launched.""" |
| 209 | |
Srikrishna Iyer | 9bff8ea | 2021-04-02 15:14:04 -0700 | [diff] [blame] | 210 | cmd = "make -f {} {}".format(self.flow_makefile, self.target) |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 211 | if self.dry_run is True: |
Srikrishna Iyer | 9bff8ea | 2021-04-02 15:14:04 -0700 | [diff] [blame] | 212 | cmd += " -n" |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 213 | for attr in sorted(self.mandatory_cmd_attrs.keys()): |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 214 | value = getattr(self, attr) |
| 215 | if type(value) is list: |
Srikrishna Iyer | 6c531b0 | 2020-11-23 18:41:16 -0800 | [diff] [blame] | 216 | # Join attributes that are list of commands with '&&' to chain |
| 217 | # them together when executed as a Make target's recipe. |
| 218 | separator = " && " if attr in self.cmds_list_vars else " " |
Srikrishna Iyer | 08ccc23 | 2021-03-31 00:01:54 -0700 | [diff] [blame] | 219 | value = separator.join(item.strip() for item in value) |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 220 | if type(value) is bool: |
| 221 | value = int(value) |
| 222 | if type(value) is str: |
| 223 | value = value.strip() |
Srikrishna Iyer | 9bff8ea | 2021-04-02 15:14:04 -0700 | [diff] [blame] | 224 | cmd += " {}={}".format(attr, shlex.quote(value)) |
| 225 | return cmd |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 226 | |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 227 | def is_equivalent_job(self, item): |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 228 | """Checks if job that would be dispatched with 'item' is equivalent to |
| 229 | 'self'. |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 230 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 231 | Determines if 'item' and 'self' would behave exactly the same way when |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 232 | deployed. If so, then there is no point in keeping both. The caller can |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 233 | choose to discard 'item' and pick 'self' instead. To do so, we check |
| 234 | the final resolved 'cmd' & the exports. The 'name' field will be unique |
| 235 | to 'item' and 'self', so we take that out of the comparison. |
| 236 | """ |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 237 | if type(self) != type(item): |
| 238 | return False |
| 239 | |
| 240 | # Check if the cmd field is identical. |
| 241 | item_cmd = item.cmd.replace(item.name, self.name) |
| 242 | if self.cmd != item_cmd: |
| 243 | return False |
| 244 | |
| 245 | # Check if exports have identical set of keys. |
| 246 | if self.exports.keys() != item.exports.keys(): |
| 247 | return False |
| 248 | |
| 249 | # Check if exports have identical values. |
| 250 | for key, val in self.exports.items(): |
| 251 | item_val = item.exports[key] |
| 252 | if type(item_val) is str: |
| 253 | item_val = item_val.replace(item.name, self.name) |
| 254 | if val != item_val: |
| 255 | return False |
| 256 | |
| 257 | log.log(VERBOSE, "Deploy job \"%s\" is equivalent to \"%s\"", |
| 258 | item.name, self.name) |
| 259 | return True |
| 260 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 261 | def pre_launch(self): |
| 262 | """Callback to perform additional pre-launch activities. |
Srikrishna Iyer | 6333b7c | 2020-10-17 21:14:25 -0700 | [diff] [blame] | 263 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 264 | This is invoked by launcher::_pre_launch(). |
Srikrishna Iyer | 2d15119 | 2021-02-10 16:56:16 -0800 | [diff] [blame] | 265 | """ |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 266 | pass |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 267 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 268 | def post_finish(self, status): |
| 269 | """Callback to perform additional post-finish activities. |
Srikrishna Iyer | 2d15119 | 2021-02-10 16:56:16 -0800 | [diff] [blame] | 270 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 271 | This is invoked by launcher::_post_finish(). |
Srikrishna Iyer | 2d15119 | 2021-02-10 16:56:16 -0800 | [diff] [blame] | 272 | """ |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 273 | pass |
Srikrishna Iyer | 2d15119 | 2021-02-10 16:56:16 -0800 | [diff] [blame] | 274 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 275 | def get_log_path(self): |
| 276 | """Returns the log file path.""" |
Srikrishna Iyer | 2d15119 | 2021-02-10 16:56:16 -0800 | [diff] [blame] | 277 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 278 | return "{}/{}.log".format(self.odir, self.target) |
Weicai Yang | fc2ff3b | 2020-03-19 18:05:14 -0700 | [diff] [blame] | 279 | |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 280 | |
| 281 | class CompileSim(Deploy): |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 282 | """Abstraction for building the simulation executable.""" |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 283 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 284 | target = "build" |
Srikrishna Iyer | 6c531b0 | 2020-11-23 18:41:16 -0800 | [diff] [blame] | 285 | cmds_list_vars = ["pre_build_cmds", "post_build_cmds"] |
Srikrishna Iyer | 1d2899f | 2021-02-11 18:23:15 -0800 | [diff] [blame] | 286 | weight = 5 |
Srikrishna Iyer | 6c531b0 | 2020-11-23 18:41:16 -0800 | [diff] [blame] | 287 | |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 288 | def __init__(self, build_mode, sim_cfg): |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 289 | self.build_mode_obj = build_mode |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 290 | super().__init__(sim_cfg) |
| 291 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 292 | def _define_attrs(self): |
| 293 | super()._define_attrs() |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 294 | self.mandatory_cmd_attrs.update({ |
Srikrishna Iyer | 8ce80d0 | 2020-02-05 10:53:19 -0800 | [diff] [blame] | 295 | # tool srcs |
Srikrishna Iyer | 981c36b | 2020-12-12 12:20:35 -0800 | [diff] [blame] | 296 | "proj_root": False, |
Srikrishna Iyer | 8ce80d0 | 2020-02-05 10:53:19 -0800 | [diff] [blame] | 297 | |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 298 | # Flist gen |
| 299 | "sv_flist_gen_cmd": False, |
| 300 | "sv_flist_gen_dir": False, |
| 301 | "sv_flist_gen_opts": False, |
| 302 | |
| 303 | # Build |
| 304 | "build_dir": False, |
Srikrishna Iyer | 6c531b0 | 2020-11-23 18:41:16 -0800 | [diff] [blame] | 305 | "pre_build_cmds": False, |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 306 | "build_cmd": False, |
Srikrishna Iyer | 6c531b0 | 2020-11-23 18:41:16 -0800 | [diff] [blame] | 307 | "build_opts": False, |
| 308 | "post_build_cmds": False, |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 309 | }) |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 310 | |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 311 | self.mandatory_misc_attrs.update({ |
Weicai Yang | 31029d2 | 2020-03-24 11:14:56 -0700 | [diff] [blame] | 312 | "cov_db_dir": False, |
| 313 | "build_pass_patterns": False, |
| 314 | "build_fail_patterns": False |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 315 | }) |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 316 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 317 | def _set_attrs(self): |
| 318 | super()._extract_attrs(self.build_mode_obj.__dict__) |
| 319 | super()._set_attrs() |
| 320 | |
| 321 | # 'build_mode' is used as a substitution variable in the HJson. |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 322 | self.build_mode = self.name |
Srikrishna Iyer | 956b3f8 | 2021-04-15 15:14:56 -0700 | [diff] [blame] | 323 | self.job_name += f"_{self.build_mode}" |
Srikrishna Iyer | 08ccc23 | 2021-03-31 00:01:54 -0700 | [diff] [blame] | 324 | if self.sim_cfg.cov: |
| 325 | self.output_dirs += [self.cov_db_dir] |
Weicai Yang | 31029d2 | 2020-03-24 11:14:56 -0700 | [diff] [blame] | 326 | self.pass_patterns = self.build_pass_patterns |
| 327 | self.fail_patterns = self.build_fail_patterns |
Srikrishna Iyer | 4f0b090 | 2020-01-25 02:28:47 -0800 | [diff] [blame] | 328 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 329 | def pre_launch(self): |
Srikrishna Iyer | 2d15119 | 2021-02-10 16:56:16 -0800 | [diff] [blame] | 330 | # Delete old coverage database directories before building again. We |
Srikrishna Iyer | 08ccc23 | 2021-03-31 00:01:54 -0700 | [diff] [blame] | 331 | # need to do this because the build directory is not 'renewed'. |
Srikrishna Iyer | 2d15119 | 2021-02-10 16:56:16 -0800 | [diff] [blame] | 332 | rm_path(self.cov_db_dir) |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 333 | |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 334 | |
Michael Schaffner | 8ac6c4c | 2020-03-03 15:00:20 -0800 | [diff] [blame] | 335 | class CompileOneShot(Deploy): |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 336 | """Abstraction for building the design (used by non-DV flows).""" |
Michael Schaffner | 8ac6c4c | 2020-03-03 15:00:20 -0800 | [diff] [blame] | 337 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 338 | target = "build" |
Michael Schaffner | 8ac6c4c | 2020-03-03 15:00:20 -0800 | [diff] [blame] | 339 | |
| 340 | def __init__(self, build_mode, sim_cfg): |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 341 | self.build_mode_obj = build_mode |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 342 | super().__init__(sim_cfg) |
| 343 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 344 | def _define_attrs(self): |
| 345 | super()._define_attrs() |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 346 | self.mandatory_cmd_attrs.update({ |
Michael Schaffner | 8ac6c4c | 2020-03-03 15:00:20 -0800 | [diff] [blame] | 347 | # tool srcs |
Srikrishna Iyer | 981c36b | 2020-12-12 12:20:35 -0800 | [diff] [blame] | 348 | "proj_root": False, |
Michael Schaffner | 8ac6c4c | 2020-03-03 15:00:20 -0800 | [diff] [blame] | 349 | |
Michael Schaffner | 3d16099 | 2020-03-31 18:37:53 -0700 | [diff] [blame] | 350 | # Flist gen |
| 351 | "sv_flist_gen_cmd": False, |
| 352 | "sv_flist_gen_dir": False, |
| 353 | "sv_flist_gen_opts": False, |
| 354 | |
Michael Schaffner | 8ac6c4c | 2020-03-03 15:00:20 -0800 | [diff] [blame] | 355 | # Build |
| 356 | "build_dir": False, |
Srikrishna Iyer | 981c36b | 2020-12-12 12:20:35 -0800 | [diff] [blame] | 357 | "pre_build_cmds": False, |
Michael Schaffner | 8ac6c4c | 2020-03-03 15:00:20 -0800 | [diff] [blame] | 358 | "build_cmd": False, |
| 359 | "build_opts": False, |
Srikrishna Iyer | 981c36b | 2020-12-12 12:20:35 -0800 | [diff] [blame] | 360 | "post_build_cmds": False, |
Michael Schaffner | 3d16099 | 2020-03-31 18:37:53 -0700 | [diff] [blame] | 361 | "build_log": False, |
Michael Schaffner | 8ac6c4c | 2020-03-03 15:00:20 -0800 | [diff] [blame] | 362 | |
| 363 | # Report processing |
| 364 | "report_cmd": False, |
| 365 | "report_opts": False |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 366 | }) |
Michael Schaffner | 8ac6c4c | 2020-03-03 15:00:20 -0800 | [diff] [blame] | 367 | |
Srikrishna Iyer | 9bff8ea | 2021-04-02 15:14:04 -0700 | [diff] [blame] | 368 | self.mandatory_misc_attrs.update({"build_fail_patterns": False}) |
Srikrishna Iyer | 5b6f9d6 | 2021-04-02 02:12:49 -0700 | [diff] [blame] | 369 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 370 | def _set_attrs(self): |
| 371 | super()._extract_attrs(self.build_mode_obj.__dict__) |
| 372 | super()._set_attrs() |
| 373 | |
| 374 | # 'build_mode' is used as a substitution variable in the HJson. |
Michael Schaffner | 8ac6c4c | 2020-03-03 15:00:20 -0800 | [diff] [blame] | 375 | self.build_mode = self.name |
Srikrishna Iyer | 956b3f8 | 2021-04-15 15:14:56 -0700 | [diff] [blame] | 376 | self.job_name += f"_{self.build_mode}" |
Srikrishna Iyer | 5b6f9d6 | 2021-04-02 02:12:49 -0700 | [diff] [blame] | 377 | self.fail_patterns = self.build_fail_patterns |
Michael Schaffner | 8ac6c4c | 2020-03-03 15:00:20 -0800 | [diff] [blame] | 378 | |
| 379 | |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 380 | class RunTest(Deploy): |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 381 | """Abstraction for running tests. This is one per seed for each test.""" |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 382 | |
Srikrishna Iyer | 7cf7cad | 2020-01-08 11:32:53 -0800 | [diff] [blame] | 383 | # Initial seed values when running tests (if available). |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 384 | target = "run" |
Srikrishna Iyer | 7cf7cad | 2020-01-08 11:32:53 -0800 | [diff] [blame] | 385 | seeds = [] |
Srikrishna Iyer | 96e5410 | 2020-03-12 22:46:50 -0700 | [diff] [blame] | 386 | fixed_seed = None |
Srikrishna Iyer | 6c531b0 | 2020-11-23 18:41:16 -0800 | [diff] [blame] | 387 | cmds_list_vars = ["pre_run_cmds", "post_run_cmds"] |
| 388 | |
Rupert Swarbrick | 381770d | 2020-10-12 08:50:08 +0100 | [diff] [blame] | 389 | def __init__(self, index, test, build_job, sim_cfg): |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 390 | self.test_obj = test |
| 391 | self.index = index |
| 392 | self.seed = RunTest.get_seed() |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 393 | super().__init__(sim_cfg) |
| 394 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 395 | if build_job is not None: |
| 396 | self.dependencies.append(build_job) |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 397 | |
Srikrishna Iyer | 9d9d86f | 2021-03-02 00:15:51 -0800 | [diff] [blame] | 398 | # We did something wrong if build_mode is not the same as the build_job |
| 399 | # arg's name. |
| 400 | assert self.build_mode == build_job.name |
| 401 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 402 | self.launcher.renew_odir = True |
| 403 | |
| 404 | def _define_attrs(self): |
| 405 | super()._define_attrs() |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 406 | self.mandatory_cmd_attrs.update({ |
Srikrishna Iyer | e9879ca | 2020-11-17 01:34:49 -0800 | [diff] [blame] | 407 | # tool srcs |
Srikrishna Iyer | 42d032f | 2020-03-04 23:55:44 -0800 | [diff] [blame] | 408 | "proj_root": False, |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 409 | "uvm_test": False, |
| 410 | "uvm_test_seq": False, |
Srikrishna Iyer | de5efa0 | 2020-11-20 23:17:11 -0800 | [diff] [blame] | 411 | "sw_images": False, |
Srikrishna Iyer | 7702be5 | 2020-03-07 01:00:28 -0800 | [diff] [blame] | 412 | "sw_build_device": False, |
| 413 | "sw_build_dir": False, |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 414 | "run_dir": False, |
Srikrishna Iyer | 6c531b0 | 2020-11-23 18:41:16 -0800 | [diff] [blame] | 415 | "pre_run_cmds": False, |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 416 | "run_cmd": False, |
Srikrishna Iyer | 6c531b0 | 2020-11-23 18:41:16 -0800 | [diff] [blame] | 417 | "run_opts": False, |
| 418 | "post_run_cmds": False, |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 419 | }) |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 420 | |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 421 | self.mandatory_misc_attrs.update({ |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 422 | "run_dir_name": False, |
Srikrishna Iyer | 1f5fae9 | 2021-02-18 21:57:25 -0800 | [diff] [blame] | 423 | "cov_db_dir": False, |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 424 | "cov_db_test_dir": False, |
Weicai Yang | 31029d2 | 2020-03-24 11:14:56 -0700 | [diff] [blame] | 425 | "run_pass_patterns": False, |
| 426 | "run_fail_patterns": False |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 427 | }) |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 428 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 429 | def _set_attrs(self): |
| 430 | super()._extract_attrs(self.test_obj.__dict__) |
| 431 | super()._set_attrs() |
Rupert Swarbrick | 381770d | 2020-10-12 08:50:08 +0100 | [diff] [blame] | 432 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 433 | # 'test' is used as a substitution variable in the HJson. |
Srikrishna Iyer | 09a81e9 | 2019-12-30 10:47:57 -0800 | [diff] [blame] | 434 | self.test = self.name |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 435 | self.build_mode = self.test_obj.build_mode.name |
| 436 | self.qual_name = self.run_dir_name + "." + str(self.seed) |
| 437 | self.full_name = self.sim_cfg.name + ":" + self.qual_name |
Srikrishna Iyer | 956b3f8 | 2021-04-15 15:14:56 -0700 | [diff] [blame] | 438 | self.job_name += f"_{self.build_mode}" |
Srikrishna Iyer | 08ccc23 | 2021-03-31 00:01:54 -0700 | [diff] [blame] | 439 | if self.sim_cfg.cov: |
Cindy Chen | d597758 | 2021-06-05 12:49:10 -0700 | [diff] [blame] | 440 | self.output_dirs += [self.cov_db_dir] |
Srikrishna Iyer | d37d10d | 2021-03-25 18:35:36 -0700 | [diff] [blame] | 441 | |
| 442 | # In GUI mode, the log file is not updated; hence, nothing to check. |
| 443 | if not self.sim_cfg.gui: |
| 444 | self.pass_patterns = self.run_pass_patterns |
| 445 | self.fail_patterns = self.run_fail_patterns |
Srikrishna Iyer | 4f0b090 | 2020-01-25 02:28:47 -0800 | [diff] [blame] | 446 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 447 | def post_finish(self, status): |
Rupert Swarbrick | a2892a5 | 2020-10-12 08:50:08 +0100 | [diff] [blame] | 448 | if status != 'P': |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 449 | # Delete the coverage data if available. |
Srikrishna Iyer | 2d15119 | 2021-02-10 16:56:16 -0800 | [diff] [blame] | 450 | rm_path(self.cov_db_test_dir) |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 451 | |
Srikrishna Iyer | 7cf7cad | 2020-01-08 11:32:53 -0800 | [diff] [blame] | 452 | @staticmethod |
| 453 | def get_seed(): |
Srikrishna Iyer | 96e5410 | 2020-03-12 22:46:50 -0700 | [diff] [blame] | 454 | # If --seeds option is passed, then those custom seeds are consumed |
| 455 | # first. If --fixed-seed <val> is also passed, the subsequent tests |
| 456 | # (once the custom seeds are consumed) will be run with the fixed seed. |
Philipp Wagner | 9a52178 | 2020-02-25 11:49:53 +0000 | [diff] [blame] | 457 | if not RunTest.seeds: |
Rupert Swarbrick | 6cc2011 | 2020-04-24 09:44:35 +0100 | [diff] [blame] | 458 | if RunTest.fixed_seed: |
| 459 | return RunTest.fixed_seed |
Srikrishna Iyer | a821bbc | 2020-01-31 00:28:02 -0800 | [diff] [blame] | 460 | for i in range(1000): |
Philipp Wagner | 75fd6c7 | 2020-02-25 11:47:41 +0000 | [diff] [blame] | 461 | seed = random.getrandbits(32) |
Srikrishna Iyer | a821bbc | 2020-01-31 00:28:02 -0800 | [diff] [blame] | 462 | RunTest.seeds.append(seed) |
Srikrishna Iyer | 7cf7cad | 2020-01-08 11:32:53 -0800 | [diff] [blame] | 463 | return RunTest.seeds.pop(0) |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 464 | |
| 465 | |
Weicai Yang | 080632d | 2020-10-16 17:52:14 -0700 | [diff] [blame] | 466 | class CovUnr(Deploy): |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 467 | """Abstraction for coverage UNR flow.""" |
Weicai Yang | 080632d | 2020-10-16 17:52:14 -0700 | [diff] [blame] | 468 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 469 | target = "cov_unr" |
Weicai Yang | 080632d | 2020-10-16 17:52:14 -0700 | [diff] [blame] | 470 | |
| 471 | def __init__(self, sim_cfg): |
Weicai Yang | 080632d | 2020-10-16 17:52:14 -0700 | [diff] [blame] | 472 | super().__init__(sim_cfg) |
| 473 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 474 | def _define_attrs(self): |
| 475 | super()._define_attrs() |
Weicai Yang | 080632d | 2020-10-16 17:52:14 -0700 | [diff] [blame] | 476 | self.mandatory_cmd_attrs.update({ |
| 477 | # tool srcs |
Srikrishna Iyer | 981c36b | 2020-12-12 12:20:35 -0800 | [diff] [blame] | 478 | "proj_root": False, |
Weicai Yang | 080632d | 2020-10-16 17:52:14 -0700 | [diff] [blame] | 479 | |
| 480 | # Need to generate filelist based on build mode |
| 481 | "sv_flist_gen_cmd": False, |
| 482 | "sv_flist_gen_dir": False, |
| 483 | "sv_flist_gen_opts": False, |
| 484 | "build_dir": False, |
| 485 | "cov_unr_build_cmd": False, |
| 486 | "cov_unr_build_opts": False, |
| 487 | "cov_unr_run_cmd": False, |
| 488 | "cov_unr_run_opts": False |
| 489 | }) |
| 490 | |
| 491 | self.mandatory_misc_attrs.update({ |
| 492 | "cov_unr_dir": False, |
Srikrishna Iyer | 8e21e51 | 2021-04-02 01:55:47 -0700 | [diff] [blame] | 493 | "cov_merge_db_dir": False, |
Weicai Yang | 080632d | 2020-10-16 17:52:14 -0700 | [diff] [blame] | 494 | "build_fail_patterns": False |
| 495 | }) |
| 496 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 497 | def _set_attrs(self): |
| 498 | super()._set_attrs() |
| 499 | self.qual_name = self.target |
| 500 | self.full_name = self.sim_cfg.name + ":" + self.qual_name |
Srikrishna Iyer | 8e21e51 | 2021-04-02 01:55:47 -0700 | [diff] [blame] | 501 | self.input_dirs += [self.cov_merge_db_dir] |
Weicai Yang | 080632d | 2020-10-16 17:52:14 -0700 | [diff] [blame] | 502 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 503 | # Reuse the build_fail_patterns set in the HJson. |
Weicai Yang | 080632d | 2020-10-16 17:52:14 -0700 | [diff] [blame] | 504 | self.fail_patterns = self.build_fail_patterns |
| 505 | |
Weicai Yang | 080632d | 2020-10-16 17:52:14 -0700 | [diff] [blame] | 506 | |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 507 | class CovMerge(Deploy): |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 508 | """Abstraction for merging coverage databases.""" |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 509 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 510 | target = "cov_merge" |
Srikrishna Iyer | 1d2899f | 2021-02-11 18:23:15 -0800 | [diff] [blame] | 511 | weight = 10 |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 512 | |
Rupert Swarbrick | f2bf370 | 2020-10-12 17:04:46 +0100 | [diff] [blame] | 513 | def __init__(self, run_items, sim_cfg): |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 514 | # Construct the cov_db_dirs right away from the run_items. This is a |
| 515 | # special variable used in the HJson. |
| 516 | self.cov_db_dirs = [] |
| 517 | for run in run_items: |
| 518 | if run.cov_db_dir not in self.cov_db_dirs: |
| 519 | self.cov_db_dirs.append(run.cov_db_dir) |
| 520 | |
Srikrishna Iyer | caa0d89 | 2021-03-01 13:15:52 -0800 | [diff] [blame] | 521 | # Early lookup the cov_merge_db_dir, which is a mandatory misc |
| 522 | # attribute anyway. We need it to compute additional cov db dirs. |
| 523 | self.cov_merge_db_dir = subst_wildcards("{cov_merge_db_dir}", |
| 524 | sim_cfg.__dict__) |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 525 | |
Srikrishna Iyer | caa0d89 | 2021-03-01 13:15:52 -0800 | [diff] [blame] | 526 | # Prune previous merged cov directories, keeping past 7 dbs. |
| 527 | prev_cov_db_dirs = clean_odirs(odir=self.cov_merge_db_dir, max_odirs=7) |
| 528 | |
| 529 | # If the --cov-merge-previous command line switch is passed, then |
| 530 | # merge coverage with the previous runs. |
| 531 | if sim_cfg.cov_merge_previous: |
| 532 | self.cov_db_dirs += [str(item) for item in prev_cov_db_dirs] |
| 533 | |
| 534 | super().__init__(sim_cfg) |
Rupert Swarbrick | f2bf370 | 2020-10-12 17:04:46 +0100 | [diff] [blame] | 535 | self.dependencies += run_items |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 536 | # Run coverage merge even if one test passes. |
Cindy Chen | 924c606 | 2021-01-27 14:27:50 -0800 | [diff] [blame] | 537 | self.needs_all_dependencies_passing = False |
Rupert Swarbrick | f2bf370 | 2020-10-12 17:04:46 +0100 | [diff] [blame] | 538 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 539 | # Append cov_db_dirs to the list of exports. |
Srikrishna Iyer | 37b0c99 | 2021-03-23 16:27:26 -0700 | [diff] [blame] | 540 | self.exports["cov_db_dirs"] = shlex.quote(" ".join(self.cov_db_dirs)) |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 541 | |
| 542 | def _define_attrs(self): |
| 543 | super()._define_attrs() |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 544 | self.mandatory_cmd_attrs.update({ |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 545 | "cov_merge_cmd": False, |
| 546 | "cov_merge_opts": False |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 547 | }) |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 548 | |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 549 | self.mandatory_misc_attrs.update({ |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 550 | "cov_merge_dir": False, |
| 551 | "cov_merge_db_dir": False |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 552 | }) |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 553 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 554 | def _set_attrs(self): |
| 555 | super()._set_attrs() |
| 556 | self.qual_name = self.target |
| 557 | self.full_name = self.sim_cfg.name + ":" + self.qual_name |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 558 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 559 | # For merging coverage db, the precise output dir is set in the HJson. |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 560 | self.odir = self.cov_merge_db_dir |
Srikrishna Iyer | 37b0c99 | 2021-03-23 16:27:26 -0700 | [diff] [blame] | 561 | self.input_dirs += self.cov_db_dirs |
Srikrishna Iyer | 08ccc23 | 2021-03-31 00:01:54 -0700 | [diff] [blame] | 562 | self.output_dirs = [self.odir] |
Srikrishna Iyer | 37b0c99 | 2021-03-23 16:27:26 -0700 | [diff] [blame] | 563 | |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 564 | |
| 565 | class CovReport(Deploy): |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 566 | """Abstraction for coverage report generation. """ |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 567 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 568 | target = "cov_report" |
Srikrishna Iyer | 1d2899f | 2021-02-11 18:23:15 -0800 | [diff] [blame] | 569 | weight = 10 |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 570 | |
Rupert Swarbrick | 381770d | 2020-10-12 08:50:08 +0100 | [diff] [blame] | 571 | def __init__(self, merge_job, sim_cfg): |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 572 | super().__init__(sim_cfg) |
Rupert Swarbrick | 381770d | 2020-10-12 08:50:08 +0100 | [diff] [blame] | 573 | self.dependencies.append(merge_job) |
| 574 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 575 | def _define_attrs(self): |
| 576 | super()._define_attrs() |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 577 | self.mandatory_cmd_attrs.update({ |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 578 | "cov_report_cmd": False, |
| 579 | "cov_report_opts": False |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 580 | }) |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 581 | |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 582 | self.mandatory_misc_attrs.update({ |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 583 | "cov_report_dir": False, |
| 584 | "cov_merge_db_dir": False, |
Srikrishna Iyer | 39ffebd | 2020-03-30 11:53:12 -0700 | [diff] [blame] | 585 | "cov_report_txt": False |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 586 | }) |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 587 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 588 | def _set_attrs(self): |
| 589 | super()._set_attrs() |
| 590 | self.qual_name = self.target |
| 591 | self.full_name = self.sim_cfg.name + ":" + self.qual_name |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 592 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 593 | # Keep track of coverage results, once the job is finished. |
| 594 | self.cov_total = "" |
| 595 | self.cov_results = "" |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 596 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 597 | def post_finish(self, status): |
| 598 | """Extract the coverage results summary for the dashboard. |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 599 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 600 | If that fails for some reason, report the job as a failure. |
| 601 | """ |
| 602 | |
| 603 | if self.dry_run or status != 'P': |
| 604 | return |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 605 | |
Rupert Swarbrick | a2892a5 | 2020-10-12 08:50:08 +0100 | [diff] [blame] | 606 | results, self.cov_total, ex_msg = get_cov_summary_table( |
| 607 | self.cov_report_txt, self.sim_cfg.tool) |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 608 | |
Rupert Swarbrick | a2892a5 | 2020-10-12 08:50:08 +0100 | [diff] [blame] | 609 | if ex_msg: |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 610 | self.launcher.fail_msg += ex_msg |
Rupert Swarbrick | a2892a5 | 2020-10-12 08:50:08 +0100 | [diff] [blame] | 611 | log.error(ex_msg) |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 612 | return |
Rupert Swarbrick | a2892a5 | 2020-10-12 08:50:08 +0100 | [diff] [blame] | 613 | |
| 614 | # Succeeded in obtaining the coverage data. |
| 615 | colalign = (("center", ) * len(results[0])) |
| 616 | self.cov_results = tabulate(results, |
| 617 | headers="firstrow", |
| 618 | tablefmt="pipe", |
| 619 | colalign=colalign) |
| 620 | |
| 621 | # Delete the cov report - not needed. |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 622 | rm_path(self.get_log_path()) |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 623 | |
| 624 | |
| 625 | class CovAnalyze(Deploy): |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 626 | """Abstraction for running the coverage analysis tool.""" |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 627 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 628 | target = "cov_analyze" |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 629 | |
| 630 | def __init__(self, sim_cfg): |
Srikrishna Iyer | 8e21e51 | 2021-04-02 01:55:47 -0700 | [diff] [blame] | 631 | # Enforce GUI mode for coverage analysis. |
| 632 | sim_cfg.gui = True |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 633 | super().__init__(sim_cfg) |
| 634 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 635 | def _define_attrs(self): |
| 636 | super()._define_attrs() |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 637 | self.mandatory_cmd_attrs.update({ |
Srikrishna Iyer | 39ffebd | 2020-03-30 11:53:12 -0700 | [diff] [blame] | 638 | # tool srcs |
Srikrishna Iyer | 981c36b | 2020-12-12 12:20:35 -0800 | [diff] [blame] | 639 | "proj_root": False, |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 640 | "cov_analyze_cmd": False, |
| 641 | "cov_analyze_opts": False |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 642 | }) |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 643 | |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 644 | self.mandatory_misc_attrs.update({ |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 645 | "cov_analyze_dir": False, |
| 646 | "cov_merge_db_dir": False |
Srikrishna Iyer | e4662af | 2020-08-10 13:19:42 -0700 | [diff] [blame] | 647 | }) |
Srikrishna Iyer | 2a710a4 | 2020-02-10 10:39:15 -0800 | [diff] [blame] | 648 | |
Srikrishna Iyer | 6578374 | 2021-02-10 21:42:12 -0800 | [diff] [blame] | 649 | def _set_attrs(self): |
| 650 | super()._set_attrs() |
| 651 | self.qual_name = self.target |
| 652 | self.full_name = self.sim_cfg.name + ":" + self.qual_name |
Srikrishna Iyer | 8e21e51 | 2021-04-02 01:55:47 -0700 | [diff] [blame] | 653 | self.input_dirs += [self.cov_merge_db_dir] |