stdlib: Allow passing of func as Exit Event generator

In this case the function is turned into a generator with the
"yield" of the generator the return the function's execution.

Change-Id: I4b06d64c5479638712a11e3c1a2f7bd30f60d188
This commit is contained in:
Bobby R. Bruce
2023-08-17 16:48:33 -07:00
parent fe43e4a3e3
commit c0216dbe48
3 changed files with 98 additions and 25 deletions

View File

@@ -41,8 +41,9 @@ About to exit the simulation for the 3 st/nd/rd/th time
Handling the final exit event. We'll exit now.
```
By default a generator is passed to define the evit_event. A list of functions
can also be passed. This is enabled by passing the `--list-format` flag.
By default a generator is passed to define the exit_event behavior. A list of
functions or a lone function can also be passed. This can be specified by the
`--exit-event-type` parameter.
"""
from gem5.resources.resource import obtain_resource
@@ -63,11 +64,12 @@ parser = argparse.ArgumentParser(
)
parser.add_argument(
"-l",
"--list-format",
action="store_true",
help="Use a list of functions, instead of a generator, for the exit event "
"handler",
"-e",
"--exit-event-type",
type=str,
choices=("generator", "function-list", "function"),
default="generator",
help="Used to specify what exit event format is to be passed.",
)
parser.add_argument(
@@ -106,9 +108,9 @@ binary = obtain_resource(
)
motherboard.set_se_binary_workload(binary)
# Create the exit event handler. Here there are two kinds: either pass a
# generator or a list of functions. In this script they both do the same things
# for testing purposes.
# Create the exit event handler. Here there are three kinds: either pass a
# generator, a list of functions, or a lone function. In this script they all
# do the same thing for testing purposes.
def event_handle() -> bool:
@@ -129,11 +131,24 @@ def generator():
func_list = [event_handle, event_handle, event_handle_final]
i = 0
def lone_function() -> bool:
global i
i += 1
if i < 3:
return event_handle()
return event_handle_final()
exit_event_handler = None
if args.list_format:
if args.exit_event_type == "function-list":
exit_event_handler = func_list
else:
elif args.exit_event_type == "generator":
exit_event_handler = generator()
elif args.exit_event_type == "function":
exit_event_handler = lone_function
assert exit_event_handler is not None

View File

@@ -47,7 +47,7 @@ gem5_verify_config(
"configs",
"simulator_exit_event_run.py",
),
config_args=["-l"],
config_args=["-e", "function-list"],
valid_isas=(constants.all_compiled_tag,),
length=constants.quick_tag,
)
@@ -64,7 +64,24 @@ gem5_verify_config(
"configs",
"simulator_exit_event_run.py",
),
config_args=[],
config_args=["-e", "generator"],
valid_isas=(constants.all_compiled_tag,),
length=constants.quick_tag,
)
gem5_verify_config(
name="simulator-exit-event-handler-with-lone-function",
verifiers=verifiers,
fixtures=(),
config=joinpath(
config.base_dir,
"tests",
"gem5",
"stdlib",
"configs",
"simulator_exit_event_run.py",
),
config_args=["-e", "function"],
valid_isas=(constants.all_compiled_tag,),
length=constants.quick_tag,
)