gem5-dev@gem5.org

The gem5 Developer List

View all threads

[M] Change in gem5/gem5[develop]: stdlib,tests: Add Simulator Exit Event handler tests

BB
Bobby Bruce (Gerrit)
Mon, Jul 10, 2023 10:56 PM

Bobby Bruce has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/62751?usp=email )

(

10 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the
submitted one.
)Change subject: stdlib,tests: Add Simulator Exit Event handler tests
......................................................................

stdlib,tests: Add Simulator Exit Event handler tests

Change-Id: Ib5f119730299c0f201a14a9e9bb933d23d65ac62
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/62751
Reviewed-by: Melissa Jost mkjost@ucdavis.edu
Tested-by: kokoro noreply+kokoro@google.com
Maintainer: Bobby Bruce bbruce@ucdavis.edu
Reviewed-by: Jason Lowe-Power power.jg@gmail.com

A tests/gem5/configs/simulator_exit_event_run.py
A tests/gem5/stdlib/simulator/ref/simout
A tests/gem5/stdlib/simulator/test_event_event.py
3 files changed, 223 insertions(+), 0 deletions(-)

Approvals:
kokoro: Regressions pass
Melissa Jost: Looks good to me, approved
Bobby Bruce: Looks good to me, approved
Jason Lowe-Power: Looks good to me, approved

diff --git a/tests/gem5/configs/simulator_exit_event_run.py
b/tests/gem5/configs/simulator_exit_event_run.py
new file mode 100644
index 0000000..f4e8ab9
--- /dev/null
+++ b/tests/gem5/configs/simulator_exit_event_run.py
@@ -0,0 +1,147 @@
+# Copyright (c) 2022 The Regents of the University of California
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""
+This script is used for testing the event_event handler of the Simulator
+module. If the handler is working correctly the following output will be
+received:
+
+ +The program has started! +About to exit the simulation for the 1 st/nd/rd/th time +Handled exit event. +build/X86/sim/simulate.cc:194: info: Entering event queue @ 780559326. Starting simulation... +About to exit the simulation for the 2 st/nd/rd/th time +Handled exit event. +build/X86/sim/simulate.cc:194: info: Entering event queue @ 854152659. Starting simulation... +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.
+"""
+
+from gem5.resources.resource import Resource
+from gem5.components.memory import SingleChannelDDR3_1600
+from gem5.components.boards.simple_board import SimpleBoard
+from gem5.components.cachehierarchies.classic.no_cache import NoCache
+from gem5.components.processors.cpu_types import CPUTypes
+from gem5.components.processors.simple_processor import SimpleProcessor
+from gem5.components.boards.simple_board import SimpleBoard
+from gem5.simulate.simulator import Simulator
+from gem5.simulate.exit_event import ExitEvent
+from gem5.isas import ISA
+
+import argparse
+
+parser = argparse.ArgumentParser(

  • description="A gem5 script for running simple binaries in SE mode."
    +)

+parser.add_argument(

  • "-l",
  • "--list-format",
  • action="store_true",
  • help="Use a list of functions, instead of a generator, for the exit
    event "
  • "handler",
    +)

+parser.add_argument(

  • "-r",
  • "--resource-directory",
  • type=str,
  • required=False,
  • help="The directory in which resources will be downloaded or exist.",
    +)

+args = parser.parse_args()
+
+# Setup the system.
+cache_hierarchy = NoCache()
+memory = SingleChannelDDR3_1600()
+
+processor = SimpleProcessor(

  • cpu_type=CPUTypes.TIMING,
  • isa=ISA.X86,
  • num_cores=1,
    +)

+motherboard = SimpleBoard(

  • clk_freq="3GHz",
  • processor=processor,
  • memory=memory,
  • cache_hierarchy=cache_hierarchy,
    +)

+# Set the workload
+# Note: Here we're using the "x86-m5-exit-repeat" resource. This calls an
+# m5_exit(0) command in an infinite while-loop.
+binary = Resource(

  • "x86-m5-exit-repeat", resource_directory=args.resource_directory
    +)
    +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.
+
+
+def event_handle() -> bool:

  • print("Handled exit event.")
  • return False

+def event_handle_final() -> bool:

  • print("Handling the final exit event. We'll exit now.")
  • return True

+def generator():

  • yield event_handle()
  • yield event_handle()
  • yield event_handle_final()

+func_list = [event_handle, event_handle, event_handle_final]
+
+exit_event_handler = None
+if args.list_format:

  • exit_event_handler = func_list
    +else:
  • exit_event_handler = generator()

+assert exit_event_handler is not None
+
+# Run the simulation
+simulator = Simulator(

  • board=motherboard,
  • on_exit_event={
  •    ExitEvent.EXIT: exit_event_handler,
    
  • },
    +)
    +simulator.run()
    diff --git a/tests/gem5/stdlib/simulator/ref/simout
    b/tests/gem5/stdlib/simulator/ref/simout
    new file mode 100644
    index 0000000..a58d513
    --- /dev/null
    +++ b/tests/gem5/stdlib/simulator/ref/simout
    @@ -0,0 +1,8 @@
    +Global frequency set at 1000000000000 ticks per second
    +The program has started!
    +About to exit the simulation for the 1 st/nd/rd/th time
    +Handled exit event.
    +About to exit the simulation for the 2 st/nd/rd/th time
    +Handled exit event.
    +About to exit the simulation for the 3 st/nd/rd/th time
    +Handling the final exit event. We'll exit now.
    diff --git a/tests/gem5/stdlib/simulator/test_event_event.py
    b/tests/gem5/stdlib/simulator/test_event_event.py
    new file mode 100644
    index 0000000..cb70a5d
    --- /dev/null
    +++ b/tests/gem5/stdlib/simulator/test_event_event.py
    @@ -0,0 +1,68 @@
    +# Copyright (c) 2022 The Regents of the University of California
    +# All rights reserved.
    +#
    +# Redistribution and use in source and binary forms, with or without
    +# modification, are permitted provided that the following conditions are
    +# met: redistributions of source code must retain the above copyright
    +# notice, this list of conditions and the following disclaimer;
    +# redistributions in binary form must reproduce the above copyright
    +# notice, this list of conditions and the following disclaimer in the
    +# documentation and/or other materials provided with the distribution;
    +# neither the name of the copyright holders nor the names of its
    +# contributors may be used to endorse or promote products derived from
    +# this software without specific prior written permission.
    +#
    +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+from testlib import *
+
+"""
+These tests are designed to test the BaseCPUProcessor. It utilizes the
+tests/gem5/configs/simple_binary_run.py to run a simple SE-mode simualation
+with different configurations of the BaseCPUProcessor.
+"""
+
+verifiers =
(verifier.MatchStdoutNoPerf(joinpath(getcwd(), "ref", "simout")),)
+
+
+gem5_verify_config(

  • name="simulator-exit-event-handler-with-function-list",
  • verifiers=verifiers,
  • fixtures=(),
  • config=joinpath(
  •    config.base_dir,
    
  •    "tests",
    
  •    "gem5",
    
  •    "configs",
    
  •    "simulator_exit_event_run.py",
    
  • ),
  • config_args=["-l"],
  • valid_isas=(constants.all_compiled_tag,),
  • length=constants.quick_tag,
    +)

+gem5_verify_config(

  • name="simulator-exit-event-handler-with-generator",
  • verifiers=verifiers,
  • fixtures=(),
  • config=joinpath(
  •    config.base_dir,
    
  •    "tests",
    
  •    "gem5",
    
  •    "configs",
    
  •    "simulator_exit_event_run.py",
    
  • ),
  • config_args=[],
  • valid_isas=(constants.all_compiled_tag,),
  • length=constants.quick_tag,
    +)

--
To view, visit
https://gem5-review.googlesource.com/c/public/gem5/+/62751?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ib5f119730299c0f201a14a9e9bb933d23d65ac62
Gerrit-Change-Number: 62751
Gerrit-PatchSet: 14
Gerrit-Owner: Bobby Bruce bbruce@ucdavis.edu
Gerrit-Reviewer: Bobby Bruce bbruce@ucdavis.edu
Gerrit-Reviewer: Jason Lowe-Power power.jg@gmail.com
Gerrit-Reviewer: Melissa Jost mkjost@ucdavis.edu
Gerrit-Reviewer: kokoro noreply+kokoro@google.com

Bobby Bruce has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/62751?usp=email ) ( 10 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: stdlib,tests: Add Simulator Exit Event handler tests ...................................................................... stdlib,tests: Add Simulator Exit Event handler tests Change-Id: Ib5f119730299c0f201a14a9e9bb933d23d65ac62 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/62751 Reviewed-by: Melissa Jost <mkjost@ucdavis.edu> Tested-by: kokoro <noreply+kokoro@google.com> Maintainer: Bobby Bruce <bbruce@ucdavis.edu> Reviewed-by: Jason Lowe-Power <power.jg@gmail.com> --- A tests/gem5/configs/simulator_exit_event_run.py A tests/gem5/stdlib/simulator/ref/simout A tests/gem5/stdlib/simulator/test_event_event.py 3 files changed, 223 insertions(+), 0 deletions(-) Approvals: kokoro: Regressions pass Melissa Jost: Looks good to me, approved Bobby Bruce: Looks good to me, approved Jason Lowe-Power: Looks good to me, approved diff --git a/tests/gem5/configs/simulator_exit_event_run.py b/tests/gem5/configs/simulator_exit_event_run.py new file mode 100644 index 0000000..f4e8ab9 --- /dev/null +++ b/tests/gem5/configs/simulator_exit_event_run.py @@ -0,0 +1,147 @@ +# Copyright (c) 2022 The Regents of the University of California +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer; +# redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution; +# neither the name of the copyright holders nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +""" +This script is used for testing the event_event handler of the Simulator +module. If the handler is working correctly the following output will be +received: + +``` +The program has started! +About to exit the simulation for the 1 st/nd/rd/th time +Handled exit event. +build/X86/sim/simulate.cc:194: info: Entering event queue @ 780559326. Starting simulation... +About to exit the simulation for the 2 st/nd/rd/th time +Handled exit event. +build/X86/sim/simulate.cc:194: info: Entering event queue @ 854152659. Starting simulation... +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. +""" + +from gem5.resources.resource import Resource +from gem5.components.memory import SingleChannelDDR3_1600 +from gem5.components.boards.simple_board import SimpleBoard +from gem5.components.cachehierarchies.classic.no_cache import NoCache +from gem5.components.processors.cpu_types import CPUTypes +from gem5.components.processors.simple_processor import SimpleProcessor +from gem5.components.boards.simple_board import SimpleBoard +from gem5.simulate.simulator import Simulator +from gem5.simulate.exit_event import ExitEvent +from gem5.isas import ISA + +import argparse + +parser = argparse.ArgumentParser( + description="A gem5 script for running simple binaries in SE mode." +) + +parser.add_argument( + "-l", + "--list-format", + action="store_true", + help="Use a list of functions, instead of a generator, for the exit event " + "handler", +) + +parser.add_argument( + "-r", + "--resource-directory", + type=str, + required=False, + help="The directory in which resources will be downloaded or exist.", +) + + +args = parser.parse_args() + +# Setup the system. +cache_hierarchy = NoCache() +memory = SingleChannelDDR3_1600() + +processor = SimpleProcessor( + cpu_type=CPUTypes.TIMING, + isa=ISA.X86, + num_cores=1, +) + +motherboard = SimpleBoard( + clk_freq="3GHz", + processor=processor, + memory=memory, + cache_hierarchy=cache_hierarchy, +) + +# Set the workload +# Note: Here we're using the "x86-m5-exit-repeat" resource. This calls an +# `m5_exit(0)` command in an infinite while-loop. +binary = Resource( + "x86-m5-exit-repeat", resource_directory=args.resource_directory +) +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. + + +def event_handle() -> bool: + print("Handled exit event.") + return False + + +def event_handle_final() -> bool: + print("Handling the final exit event. We'll exit now.") + return True + + +def generator(): + yield event_handle() + yield event_handle() + yield event_handle_final() + + +func_list = [event_handle, event_handle, event_handle_final] + +exit_event_handler = None +if args.list_format: + exit_event_handler = func_list +else: + exit_event_handler = generator() + +assert exit_event_handler is not None + +# Run the simulation +simulator = Simulator( + board=motherboard, + on_exit_event={ + ExitEvent.EXIT: exit_event_handler, + }, +) +simulator.run() diff --git a/tests/gem5/stdlib/simulator/ref/simout b/tests/gem5/stdlib/simulator/ref/simout new file mode 100644 index 0000000..a58d513 --- /dev/null +++ b/tests/gem5/stdlib/simulator/ref/simout @@ -0,0 +1,8 @@ +Global frequency set at 1000000000000 ticks per second +The program has started! +About to exit the simulation for the 1 st/nd/rd/th time +Handled exit event. +About to exit the simulation for the 2 st/nd/rd/th time +Handled exit event. +About to exit the simulation for the 3 st/nd/rd/th time +Handling the final exit event. We'll exit now. diff --git a/tests/gem5/stdlib/simulator/test_event_event.py b/tests/gem5/stdlib/simulator/test_event_event.py new file mode 100644 index 0000000..cb70a5d --- /dev/null +++ b/tests/gem5/stdlib/simulator/test_event_event.py @@ -0,0 +1,68 @@ +# Copyright (c) 2022 The Regents of the University of California +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer; +# redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution; +# neither the name of the copyright holders nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from testlib import * + +""" +These tests are designed to test the BaseCPUProcessor. It utilizes the +tests/gem5/configs/simple_binary_run.py to run a simple SE-mode simualation +with different configurations of the BaseCPUProcessor. +""" + +verifiers = (verifier.MatchStdoutNoPerf(joinpath(getcwd(), "ref", "simout")),) + + +gem5_verify_config( + name="simulator-exit-event-handler-with-function-list", + verifiers=verifiers, + fixtures=(), + config=joinpath( + config.base_dir, + "tests", + "gem5", + "configs", + "simulator_exit_event_run.py", + ), + config_args=["-l"], + valid_isas=(constants.all_compiled_tag,), + length=constants.quick_tag, +) + +gem5_verify_config( + name="simulator-exit-event-handler-with-generator", + verifiers=verifiers, + fixtures=(), + config=joinpath( + config.base_dir, + "tests", + "gem5", + "configs", + "simulator_exit_event_run.py", + ), + config_args=[], + valid_isas=(constants.all_compiled_tag,), + length=constants.quick_tag, +) -- To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/62751?usp=email To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: public/gem5 Gerrit-Branch: develop Gerrit-Change-Id: Ib5f119730299c0f201a14a9e9bb933d23d65ac62 Gerrit-Change-Number: 62751 Gerrit-PatchSet: 14 Gerrit-Owner: Bobby Bruce <bbruce@ucdavis.edu> Gerrit-Reviewer: Bobby Bruce <bbruce@ucdavis.edu> Gerrit-Reviewer: Jason Lowe-Power <power.jg@gmail.com> Gerrit-Reviewer: Melissa Jost <mkjost@ucdavis.edu> Gerrit-Reviewer: kokoro <noreply+kokoro@google.com>