-
Notifications
You must be signed in to change notification settings - Fork 3
[launcher] Fake launcher to produce random results #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Copyright lowRISC contributors (OpenTitan project). | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
"""Fake Launcher that returns random results.""" | ||
|
||
from random import choice, random | ||
from typing import TYPE_CHECKING | ||
|
||
from dvsim.launcher.base import ErrorMessage, Launcher | ||
|
||
if TYPE_CHECKING: | ||
from dvsim.job.deploy import CovReport, Deploy, RunTest | ||
|
||
|
||
def _run_test_handler(deploy: "RunTest") -> str: | ||
"""Handle a RunTest deploy job.""" | ||
return choice(("P", "F")) | ||
|
||
|
||
def _cov_report_handler(deploy: "CovReport") -> str: | ||
"""Handle a CompileSim deploy job.""" | ||
keys = [ | ||
"score", | ||
"line", | ||
"cond", | ||
"toggle", | ||
"fsm", | ||
"branch", | ||
"assert", | ||
"group", | ||
] | ||
|
||
deploy.cov_results_dict = {k: f"{random() * 100:.2f} %" for k in keys} | ||
|
||
return "P" | ||
|
||
|
||
_DEPLOY_HANDLER = { | ||
"RunTest": _run_test_handler, | ||
"CovReport": _cov_report_handler, | ||
} | ||
|
||
|
||
class FakeLauncher(Launcher): | ||
"""Launch jobs and return fake results.""" | ||
|
||
# Poll job's completion status every this many seconds | ||
poll_freq = 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I presume that this is used elsewhere and that 0 is correctly interpreted as "Don't poll" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used by the scheduler for the sleep duration between polling. It looks like it's used to rate limit the "are you done yet" polling. This is useful where a launcher is submitting a job to a grid engine for example, where polling an external API with no wait period would lock the system up. This fake launcher only returns a job completion status. Setting this to |
||
|
||
def __init__(self, deploy: "Deploy") -> None: | ||
"""Initialize common class members.""" | ||
super().__init__(deploy) | ||
|
||
def _do_launch(self) -> None: | ||
"""Do the launch.""" | ||
|
||
def poll(self) -> str | None: | ||
"""Check status of the running process.""" | ||
deploy_cls = self.deploy.__class__.__name__ | ||
if deploy_cls in _DEPLOY_HANDLER: | ||
return _DEPLOY_HANDLER[deploy_cls](deploy=self.deploy) | ||
|
||
# Default result is Pass | ||
return "P" | ||
|
||
def kill(self) -> None: | ||
"""Kill the running process.""" | ||
self._post_finish( | ||
"K", | ||
ErrorMessage(line_number=None, message="Job killed!", context=[]), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine provided that you never need to recreate a run otherwise the RNG will need seeding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, in this case I don't think we need to reproduce the results. The random side is just to get some fake data for the report templates while working on those. Specifically test the colourisation with different percentages.
In the future if there are other use cases for this we could add more configuration options. One of those might be seeding the randomness, perhaps also setting the type of randomness.