112882Sspwilson2@wisc.edu# Copyright (c) 2017 Mark D. Hill and David A. Wood
212882Sspwilson2@wisc.edu# All rights reserved.
312882Sspwilson2@wisc.edu#
412882Sspwilson2@wisc.edu# Redistribution and use in source and binary forms, with or without
512882Sspwilson2@wisc.edu# modification, are permitted provided that the following conditions are
612882Sspwilson2@wisc.edu# met: redistributions of source code must retain the above copyright
712882Sspwilson2@wisc.edu# notice, this list of conditions and the following disclaimer;
812882Sspwilson2@wisc.edu# redistributions in binary form must reproduce the above copyright
912882Sspwilson2@wisc.edu# notice, this list of conditions and the following disclaimer in the
1012882Sspwilson2@wisc.edu# documentation and/or other materials provided with the distribution;
1112882Sspwilson2@wisc.edu# neither the name of the copyright holders nor the names of its
1212882Sspwilson2@wisc.edu# contributors may be used to endorse or promote products derived from
1312882Sspwilson2@wisc.edu# this software without specific prior written permission.
1412882Sspwilson2@wisc.edu#
1512882Sspwilson2@wisc.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612882Sspwilson2@wisc.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712882Sspwilson2@wisc.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812882Sspwilson2@wisc.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912882Sspwilson2@wisc.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012882Sspwilson2@wisc.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112882Sspwilson2@wisc.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212882Sspwilson2@wisc.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312882Sspwilson2@wisc.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412882Sspwilson2@wisc.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512882Sspwilson2@wisc.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612882Sspwilson2@wisc.edu#
2712882Sspwilson2@wisc.edu# Authors: Sean Wilson
2812882Sspwilson2@wisc.edu
2912882Sspwilson2@wisc.edu'''
3012882Sspwilson2@wisc.eduNew version of the run.py script. For this, all dependencies should be
3112882Sspwilson2@wisc.eduhandled outside of the script.
3212882Sspwilson2@wisc.edu
3312882Sspwilson2@wisc.edu.. warning:: This script is NOT the recommended way to handle configurations
3412882Sspwilson2@wisc.edu    for new tests. This exists for legacy support only. New Tests should
3512882Sspwilson2@wisc.edu    either use configs from the normal gem5 configs or create their own for
3612882Sspwilson2@wisc.edu    a test.
3712882Sspwilson2@wisc.edu'''
3812882Sspwilson2@wisc.eduimport argparse
3912882Sspwilson2@wisc.eduimport sys
4012882Sspwilson2@wisc.eduimport os
4112882Sspwilson2@wisc.edufrom os.path import abspath, join as joinpath, dirname
4212882Sspwilson2@wisc.edu
4312882Sspwilson2@wisc.eduimport m5
4412882Sspwilson2@wisc.edu
4512882Sspwilson2@wisc.edu# Add the normal gem5 config path to system path.
4612882Sspwilson2@wisc.edu# This requirement should be removed if possible from all legacy scripts, but
4712882Sspwilson2@wisc.edu# I've left it here for now.
4812882Sspwilson2@wisc.edusys.path.insert(0, abspath(joinpath(dirname(__file__), '../../configs')))
4912882Sspwilson2@wisc.edu
5012882Sspwilson2@wisc.edu# set default maxtick... script can override
5112882Sspwilson2@wisc.edu# -1 means run forever
5212882Sspwilson2@wisc.edumaxtick = m5.MaxTick
5312882Sspwilson2@wisc.edu
5412882Sspwilson2@wisc.edudef run_test(root):
5512882Sspwilson2@wisc.edu    """Default run_test implementations. Scripts can override it."""
5612882Sspwilson2@wisc.edu
5712882Sspwilson2@wisc.edu    # instantiate configuration
5812882Sspwilson2@wisc.edu    m5.instantiate()
5912882Sspwilson2@wisc.edu
6012882Sspwilson2@wisc.edu    # simulate until program terminates
6112882Sspwilson2@wisc.edu    exit_event = m5.simulate(maxtick)
6212882Sspwilson2@wisc.edu    print 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause()
6312882Sspwilson2@wisc.edu
6412882Sspwilson2@wisc.edutest_progs = os.environ.get('M5_TEST_PROGS', '/dist/m5/regression/test-progs')
6512882Sspwilson2@wisc.edu
6612882Sspwilson2@wisc.edu# Since we're in batch mode, dont allow tcp socket connections
6712882Sspwilson2@wisc.edum5.disableAllListeners()
6812882Sspwilson2@wisc.edu
6912882Sspwilson2@wisc.eduparser = argparse.ArgumentParser()
7012882Sspwilson2@wisc.eduparser.add_argument('--cmd',
7112882Sspwilson2@wisc.edu                    action='store',
7212882Sspwilson2@wisc.edu                    type=str,
7312882Sspwilson2@wisc.edu                    help='Command to pass to the test system')
7412882Sspwilson2@wisc.eduparser.add_argument('--executable',
7512882Sspwilson2@wisc.edu                    action='store',
7612882Sspwilson2@wisc.edu                    type=str,
7712882Sspwilson2@wisc.edu                    help='Executable to pass to the test system')
7812882Sspwilson2@wisc.eduparser.add_argument('--config',
7912882Sspwilson2@wisc.edu                    action='append',
8012882Sspwilson2@wisc.edu                    type=str,
8112882Sspwilson2@wisc.edu                    help='A config file to initialize the system with.'\
8212882Sspwilson2@wisc.edu                    + ' If more than one given, loads them in order given.')
8312882Sspwilson2@wisc.eduargs = parser.parse_args()
8412882Sspwilson2@wisc.edu
8512882Sspwilson2@wisc.eduexecutable = args.executable
8612882Sspwilson2@wisc.edu
8712882Sspwilson2@wisc.edufor config in args.config:
8813718Sandreas.sandberg@arm.com    exec(compile(open(config).read(), config, 'exec'))
8912882Sspwilson2@wisc.edu
9012882Sspwilson2@wisc.edu# Initialize all CPUs in a system
9112882Sspwilson2@wisc.edudef initCPUs(sys):
9212882Sspwilson2@wisc.edu    def initCPU(cpu):
9312882Sspwilson2@wisc.edu        # We might actually have a MemTest object or something similar
9412882Sspwilson2@wisc.edu        # here that just pretends to be a CPU.
9512882Sspwilson2@wisc.edu        try:
9612882Sspwilson2@wisc.edu            cpu.createThreads()
9712882Sspwilson2@wisc.edu        except:
9812882Sspwilson2@wisc.edu            pass
9912882Sspwilson2@wisc.edu
10012882Sspwilson2@wisc.edu    # The CPU attribute doesn't exist in some cases, e.g. the Ruby testers.
10112882Sspwilson2@wisc.edu    if not hasattr(sys, "cpu"):
10212882Sspwilson2@wisc.edu        return
10312882Sspwilson2@wisc.edu
10412882Sspwilson2@wisc.edu    # The CPU can either be a list of CPUs or a single object.
10512882Sspwilson2@wisc.edu    if isinstance(sys.cpu, list):
10612882Sspwilson2@wisc.edu        [ initCPU(cpu) for cpu in sys.cpu ]
10712882Sspwilson2@wisc.edu    else:
10812882Sspwilson2@wisc.edu        initCPU(sys.cpu)
10912882Sspwilson2@wisc.edu
11012882Sspwilson2@wisc.edu# TODO: Might want to automatically place the cmd and executable on the
11112882Sspwilson2@wisc.edu# cpu[0].workload, although I think most legacy configs do this automatically
11212882Sspwilson2@wisc.edu# or somewhere in their `test.py` config.
11312882Sspwilson2@wisc.edu
11412882Sspwilson2@wisc.edu
11512882Sspwilson2@wisc.edu# We might be creating a single system or a dual system. Try
11612882Sspwilson2@wisc.edu# initializing the CPUs in all known system attributes.
11712882Sspwilson2@wisc.edufor sysattr in [ "system", "testsys", "drivesys" ]:
11812882Sspwilson2@wisc.edu    if hasattr(root, sysattr):
11912882Sspwilson2@wisc.edu        initCPUs(getattr(root, sysattr))
12012882Sspwilson2@wisc.edu
12112882Sspwilson2@wisc.edurun_test(root)
122