114143Snikos.nikoleris@arm.com# Copyright (c) 2012, 2019 ARM Limited
214143Snikos.nikoleris@arm.com# All rights reserved
314143Snikos.nikoleris@arm.com#
414143Snikos.nikoleris@arm.com# The license below extends only to copyright in the software and shall
514143Snikos.nikoleris@arm.com# not be construed as granting a license to any other intellectual
614143Snikos.nikoleris@arm.com# property including but not limited to intellectual property relating
714143Snikos.nikoleris@arm.com# to a hardware implementation of the functionality of the software
814143Snikos.nikoleris@arm.com# licensed hereunder.  You may use the software subject to the license
914143Snikos.nikoleris@arm.com# terms below provided that you ensure that this notice is replicated
1014143Snikos.nikoleris@arm.com# unmodified and in its entirety in all distributions of the software,
1114143Snikos.nikoleris@arm.com# modified or unmodified, in source code or in binary form.
1214143Snikos.nikoleris@arm.com#
1314143Snikos.nikoleris@arm.com# Copyright (c) 2006-2007 The Regents of The University of Michigan
1414143Snikos.nikoleris@arm.com# All rights reserved.
1514143Snikos.nikoleris@arm.com#
1614143Snikos.nikoleris@arm.com# Redistribution and use in source and binary forms, with or without
1714143Snikos.nikoleris@arm.com# modification, are permitted provided that the following conditions are
1814143Snikos.nikoleris@arm.com# met: redistributions of source code must retain the above copyright
1914143Snikos.nikoleris@arm.com# notice, this list of conditions and the following disclaimer;
2014143Snikos.nikoleris@arm.com# redistributions in binary form must reproduce the above copyright
2114143Snikos.nikoleris@arm.com# notice, this list of conditions and the following disclaimer in the
2214143Snikos.nikoleris@arm.com# documentation and/or other materials provided with the distribution;
2314143Snikos.nikoleris@arm.com# neither the name of the copyright holders nor the names of its
2414143Snikos.nikoleris@arm.com# contributors may be used to endorse or promote products derived from
2514143Snikos.nikoleris@arm.com# this software without specific prior written permission.
2614143Snikos.nikoleris@arm.com#
2714143Snikos.nikoleris@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2814143Snikos.nikoleris@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2914143Snikos.nikoleris@arm.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3014143Snikos.nikoleris@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3114143Snikos.nikoleris@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3214143Snikos.nikoleris@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3314143Snikos.nikoleris@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3414143Snikos.nikoleris@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3514143Snikos.nikoleris@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3614143Snikos.nikoleris@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3714143Snikos.nikoleris@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3814143Snikos.nikoleris@arm.com#
3914143Snikos.nikoleris@arm.com# Authors: Steve Reinhardt
4014143Snikos.nikoleris@arm.com#          Nikos Nikoleris
4114143Snikos.nikoleris@arm.com
4214143Snikos.nikoleris@arm.comfrom __future__ import print_function
4314143Snikos.nikoleris@arm.com
4414143Snikos.nikoleris@arm.comimport sys
4514143Snikos.nikoleris@arm.comimport os
4614143Snikos.nikoleris@arm.comimport os.path
4714143Snikos.nikoleris@arm.comfrom os.path import join as joinpath
4814143Snikos.nikoleris@arm.com
4914143Snikos.nikoleris@arm.comimport m5
5014143Snikos.nikoleris@arm.com
5114143Snikos.nikoleris@arm.comdef run_test(root):
5214143Snikos.nikoleris@arm.com    """Default run_test implementations. Scripts can override it."""
5314143Snikos.nikoleris@arm.com
5414143Snikos.nikoleris@arm.com    # instantiate configuration
5514143Snikos.nikoleris@arm.com    m5.instantiate()
5614143Snikos.nikoleris@arm.com
5714143Snikos.nikoleris@arm.com    # simulate until program terminates
5814143Snikos.nikoleris@arm.com    exit_event = m5.simulate()
5914143Snikos.nikoleris@arm.com    print('Exiting @ tick', m5.curTick(), 'because', exit_event.getCause())
6014143Snikos.nikoleris@arm.com
6114143Snikos.nikoleris@arm.comconfig = sys.argv[1]
6214143Snikos.nikoleris@arm.comos.environ['M5_PATH'] = os.path.dirname(__file__)
6314143Snikos.nikoleris@arm.com
6414143Snikos.nikoleris@arm.com# path setup
6514143Snikos.nikoleris@arm.comgem5_root = joinpath(os.path.dirname(__file__), '..', '..', '..', '..', '..')
6614143Snikos.nikoleris@arm.comsys.path.append(joinpath(gem5_root, 'configs'))
6714143Snikos.nikoleris@arm.comtests_root = joinpath(gem5_root, 'tests')
6814143Snikos.nikoleris@arm.comsys.path.append(joinpath(tests_root, 'configs'))
6914143Snikos.nikoleris@arm.com
7014143Snikos.nikoleris@arm.comexec(compile(open(config).read(), config, 'exec'))
7114143Snikos.nikoleris@arm.com
7214143Snikos.nikoleris@arm.comsystem = root.system
7314143Snikos.nikoleris@arm.comsystem.readfile = os.path.join(tests_root, 'halt.sh')
7414143Snikos.nikoleris@arm.com
7514143Snikos.nikoleris@arm.com# The CPU can either be a list of CPUs or a single object.
7614143Snikos.nikoleris@arm.comif isinstance(system.cpu, list):
7714143Snikos.nikoleris@arm.com    [ cpu.createThreads() for cpu in system.cpu ]
7814143Snikos.nikoleris@arm.comelse:
7914143Snikos.nikoleris@arm.com    system.cpu.createThreads()
8014143Snikos.nikoleris@arm.com
8114143Snikos.nikoleris@arm.com# Since we're in batch mode, don't allow tcp socket connections
8214143Snikos.nikoleris@arm.comm5.disableAllListeners()
8314143Snikos.nikoleris@arm.com
8414143Snikos.nikoleris@arm.comrun_test(root)
85