|
| 1 | +# Copyright lowRISC contributors (OpenTitan project). |
| 2 | +# Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +"""Fake Launcher that returns random results.""" |
| 6 | + |
| 7 | +from random import choice, random |
| 8 | +from typing import TYPE_CHECKING |
| 9 | + |
| 10 | +from dvsim.launcher.base import ErrorMessage, Launcher |
| 11 | + |
| 12 | +if TYPE_CHECKING: |
| 13 | + from dvsim.job.deploy import CovReport, Deploy, RunTest |
| 14 | + |
| 15 | + |
| 16 | +def _run_test_handler(deploy: "RunTest") -> str: |
| 17 | + """Handle a RunTest deploy job.""" |
| 18 | + return choice(("P", "F")) |
| 19 | + |
| 20 | + |
| 21 | +def _cov_report_handler(deploy: "CovReport") -> str: |
| 22 | + """Handle a CompileSim deploy job.""" |
| 23 | + keys = [ |
| 24 | + "score", |
| 25 | + "line", |
| 26 | + "cond", |
| 27 | + "toggle", |
| 28 | + "fsm", |
| 29 | + "branch", |
| 30 | + "assert", |
| 31 | + "group", |
| 32 | + ] |
| 33 | + |
| 34 | + deploy.cov_results_dict = {k: f"{random() * 100:.2f} %" for k in keys} |
| 35 | + |
| 36 | + return "P" |
| 37 | + |
| 38 | + |
| 39 | +_DEPLOY_HANDLER = { |
| 40 | + "RunTest": _run_test_handler, |
| 41 | + "CovReport": _cov_report_handler, |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | +class FakeLauncher(Launcher): |
| 46 | + """Launch jobs and return fake results.""" |
| 47 | + |
| 48 | + # Poll job's completion status every this many seconds |
| 49 | + poll_freq = 0 |
| 50 | + |
| 51 | + def __init__(self, deploy: "Deploy") -> None: |
| 52 | + """Initialize common class members.""" |
| 53 | + super().__init__(deploy) |
| 54 | + |
| 55 | + def _do_launch(self) -> None: |
| 56 | + """Do the launch.""" |
| 57 | + |
| 58 | + def poll(self) -> str | None: |
| 59 | + """Check status of the running process.""" |
| 60 | + deploy_cls = self.deploy.__class__.__name__ |
| 61 | + if deploy_cls in _DEPLOY_HANDLER: |
| 62 | + return _DEPLOY_HANDLER[deploy_cls](deploy=self.deploy) |
| 63 | + |
| 64 | + # Default result is Pass |
| 65 | + return "P" |
| 66 | + |
| 67 | + def kill(self) -> None: |
| 68 | + """Kill the running process.""" |
| 69 | + self._post_finish( |
| 70 | + "K", |
| 71 | + ErrorMessage(line_number=None, message="Job killed!", context=[]), |
| 72 | + ) |
0 commit comments