run.py revision 9447
19401SAndreas.Sandberg@ARM.com# Copyright (c) 2012 ARM Limited
29401SAndreas.Sandberg@ARM.com# All rights reserved
39401SAndreas.Sandberg@ARM.com#
49401SAndreas.Sandberg@ARM.com# The license below extends only to copyright in the software and shall
59401SAndreas.Sandberg@ARM.com# not be construed as granting a license to any other intellectual
69401SAndreas.Sandberg@ARM.com# property including but not limited to intellectual property relating
79401SAndreas.Sandberg@ARM.com# to a hardware implementation of the functionality of the software
89401SAndreas.Sandberg@ARM.com# licensed hereunder.  You may use the software subject to the license
99401SAndreas.Sandberg@ARM.com# terms below provided that you ensure that this notice is replicated
109401SAndreas.Sandberg@ARM.com# unmodified and in its entirety in all distributions of the software,
119401SAndreas.Sandberg@ARM.com# modified or unmodified, in source code or in binary form.
129401SAndreas.Sandberg@ARM.com#
134977Ssaidi@eecs.umich.edu# Copyright (c) 2006-2007 The Regents of The University of Michigan
142997Sstever@eecs.umich.edu# All rights reserved.
152997Sstever@eecs.umich.edu#
162997Sstever@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
172997Sstever@eecs.umich.edu# modification, are permitted provided that the following conditions are
182997Sstever@eecs.umich.edu# met: redistributions of source code must retain the above copyright
192997Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
202997Sstever@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
212997Sstever@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
222997Sstever@eecs.umich.edu# documentation and/or other materials provided with the distribution;
232997Sstever@eecs.umich.edu# neither the name of the copyright holders nor the names of its
242997Sstever@eecs.umich.edu# contributors may be used to endorse or promote products derived from
252997Sstever@eecs.umich.edu# this software without specific prior written permission.
262997Sstever@eecs.umich.edu#
272997Sstever@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
282997Sstever@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
292997Sstever@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
302997Sstever@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
312997Sstever@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
322997Sstever@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
332997Sstever@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
342997Sstever@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
352997Sstever@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
362997Sstever@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
372997Sstever@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
382997Sstever@eecs.umich.edu#
392997Sstever@eecs.umich.edu# Authors: Steve Reinhardt
402997Sstever@eecs.umich.edu
415523Snate@binkert.orgimport os
425523Snate@binkert.orgimport sys
436928SBrad.Beckmann@amd.comimport re
446928SBrad.Beckmann@amd.comimport string
456289Snate@binkert.org
466289Snate@binkert.orgfrom os.path import join as joinpath
476289Snate@binkert.org
485523Snate@binkert.orgimport m5
495523Snate@binkert.org
509401SAndreas.Sandberg@ARM.comdef skip_test(reason=""):
519401SAndreas.Sandberg@ARM.com    """Signal that a test should be skipped and optionally print why.
529401SAndreas.Sandberg@ARM.com
539401SAndreas.Sandberg@ARM.com    Keyword arguments:
549401SAndreas.Sandberg@ARM.com      reason -- Reason why the test failed. Output is omitted if empty.
559401SAndreas.Sandberg@ARM.com    """
569401SAndreas.Sandberg@ARM.com
579401SAndreas.Sandberg@ARM.com    if reason:
589401SAndreas.Sandberg@ARM.com        print "Skipping test: %s" % reason
599401SAndreas.Sandberg@ARM.com    sys.exit(2)
609401SAndreas.Sandberg@ARM.com
619401SAndreas.Sandberg@ARM.comdef has_sim_object(name):
629401SAndreas.Sandberg@ARM.com    """Test if a SimObject exists in the simulator.
639401SAndreas.Sandberg@ARM.com
649401SAndreas.Sandberg@ARM.com    Arguments:
659401SAndreas.Sandberg@ARM.com      name -- Name of SimObject (string)
669401SAndreas.Sandberg@ARM.com
679401SAndreas.Sandberg@ARM.com    Returns: True if the object exists, False otherwise.
689401SAndreas.Sandberg@ARM.com    """
699401SAndreas.Sandberg@ARM.com
709401SAndreas.Sandberg@ARM.com    try:
719401SAndreas.Sandberg@ARM.com        cls = getattr(m5.objects, name)
729401SAndreas.Sandberg@ARM.com        return issubclass(cls, m5.objects.SimObject)
739401SAndreas.Sandberg@ARM.com    except AttributeError:
749401SAndreas.Sandberg@ARM.com        return False
759401SAndreas.Sandberg@ARM.com
769401SAndreas.Sandberg@ARM.comdef require_sim_object(name, fatal=False):
779401SAndreas.Sandberg@ARM.com    """Test if a SimObject exists and abort/skip test if not.
789401SAndreas.Sandberg@ARM.com
799401SAndreas.Sandberg@ARM.com    Arguments:
809401SAndreas.Sandberg@ARM.com      name -- Name of SimObject (string)
819401SAndreas.Sandberg@ARM.com
829401SAndreas.Sandberg@ARM.com    Keyword arguments:
839401SAndreas.Sandberg@ARM.com      fatal -- Set to True to indicate that the test should fail
849401SAndreas.Sandberg@ARM.com               instead of being skipped.
859401SAndreas.Sandberg@ARM.com    """
869401SAndreas.Sandberg@ARM.com
879401SAndreas.Sandberg@ARM.com    if has_sim_object(name):
889401SAndreas.Sandberg@ARM.com        return
899401SAndreas.Sandberg@ARM.com    else:
909401SAndreas.Sandberg@ARM.com        msg = "Test requires the '%s' SimObject." % name
919401SAndreas.Sandberg@ARM.com        if fatal:
929401SAndreas.Sandberg@ARM.com            m5.fatal(msg)
939401SAndreas.Sandberg@ARM.com        else:
949401SAndreas.Sandberg@ARM.com            skip_test(msg)
959401SAndreas.Sandberg@ARM.com
969447SAndreas.Sandberg@ARM.comdef run_test(root):
979447SAndreas.Sandberg@ARM.com    """Default run_test implementations. Scripts can override it."""
989447SAndreas.Sandberg@ARM.com
999447SAndreas.Sandberg@ARM.com    # instantiate configuration
1009447SAndreas.Sandberg@ARM.com    m5.instantiate()
1019447SAndreas.Sandberg@ARM.com
1029447SAndreas.Sandberg@ARM.com    # simulate until program terminates
1039447SAndreas.Sandberg@ARM.com    exit_event = m5.simulate(maxtick)
1049447SAndreas.Sandberg@ARM.com    print 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause()
1059447SAndreas.Sandberg@ARM.com
1065523Snate@binkert.org# Since we're in batch mode, dont allow tcp socket connections
1075523Snate@binkert.orgm5.disableAllListeners()
1082997Sstever@eecs.umich.edu
1092997Sstever@eecs.umich.edu# single "path" arg encodes everything we need to know about test
1108802Sgblack@eecs.umich.edu(category, mode, name, isa, opsys, config) = sys.argv[1].split('/')[-6:]
1112997Sstever@eecs.umich.edu
1122997Sstever@eecs.umich.edu# find path to directory containing this file
1132997Sstever@eecs.umich.edutests_root = os.path.dirname(__file__)
1146874SSteve.Reinhardt@amd.comtest_progs = os.environ.get('M5_TEST_PROGS', '/dist/m5/regression/test-progs')
1156874SSteve.Reinhardt@amd.comif not os.path.isdir(test_progs):
1166289Snate@binkert.org    test_progs = joinpath(tests_root, 'test-progs')
1172998Sstever@eecs.umich.edu
1182998Sstever@eecs.umich.edu# generate path to binary file
1192998Sstever@eecs.umich.edudef binpath(app, file=None):
1202998Sstever@eecs.umich.edu    # executable has same name as app unless specified otherwise
1212998Sstever@eecs.umich.edu    if not file:
1222998Sstever@eecs.umich.edu        file = app
1236289Snate@binkert.org    return joinpath(test_progs, app, 'bin', isa, opsys, file)
1242997Sstever@eecs.umich.edu
1253475Sktlim@umich.edu# generate path to input file
1263475Sktlim@umich.edudef inputpath(app, file=None):
1273475Sktlim@umich.edu    # input file has same name as app unless specified otherwise
1283475Sktlim@umich.edu    if not file:
1293475Sktlim@umich.edu        file = app
1306289Snate@binkert.org    return joinpath(test_progs, app, 'input', file)
1313475Sktlim@umich.edu
1322997Sstever@eecs.umich.edu# build configuration
1336289Snate@binkert.orgsys.path.append(joinpath(tests_root, 'configs'))
1346928SBrad.Beckmann@amd.comtest_filename = config
1356928SBrad.Beckmann@amd.com# for ruby configurations, remove the protocol name from the test filename
1366928SBrad.Beckmann@amd.comif re.search('-ruby', test_filename):
1376928SBrad.Beckmann@amd.com    test_filename = test_filename.split('-ruby')[0]+'-ruby'
1386928SBrad.Beckmann@amd.comexecfile(joinpath(tests_root, 'configs', test_filename + '.py'))
1392997Sstever@eecs.umich.edu
1402997Sstever@eecs.umich.edu# set default maxtick... script can override
1412998Sstever@eecs.umich.edu# -1 means run forever
1425523Snate@binkert.orgmaxtick = m5.MaxTick
1432997Sstever@eecs.umich.edu
1442997Sstever@eecs.umich.edu# tweak configuration for specific test
1458802Sgblack@eecs.umich.edusys.path.append(joinpath(tests_root, category, mode, name))
1468802Sgblack@eecs.umich.eduexecfile(joinpath(tests_root, category, mode, name, 'test.py'))
1472997Sstever@eecs.umich.edu
1489384SAndreas.Sandberg@arm.com# Initialize all CPUs in a system
1499384SAndreas.Sandberg@arm.comdef initCPUs(sys):
1509384SAndreas.Sandberg@arm.com    def initCPU(cpu):
1519384SAndreas.Sandberg@arm.com        # We might actually have a MemTest object or something similar
1529384SAndreas.Sandberg@arm.com        # here that just pretends to be a CPU.
1539384SAndreas.Sandberg@arm.com        if isinstance(cpu, BaseCPU):
1549384SAndreas.Sandberg@arm.com            cpu.createThreads()
1559384SAndreas.Sandberg@arm.com
1569384SAndreas.Sandberg@arm.com    # The CPU attribute doesn't exist in some cases, e.g. the Ruby
1579384SAndreas.Sandberg@arm.com    # testers.
1589384SAndreas.Sandberg@arm.com    if not hasattr(sys, "cpu"):
1599384SAndreas.Sandberg@arm.com        return
1609384SAndreas.Sandberg@arm.com
1619384SAndreas.Sandberg@arm.com    # The CPU can either be a list of CPUs or a single object.
1629384SAndreas.Sandberg@arm.com    if isinstance(sys.cpu, list):
1639384SAndreas.Sandberg@arm.com        [ initCPU(cpu) for cpu in sys.cpu ]
1649384SAndreas.Sandberg@arm.com    else:
1659384SAndreas.Sandberg@arm.com        initCPU(sys.cpu)
1669384SAndreas.Sandberg@arm.com
1679384SAndreas.Sandberg@arm.com# We might be creating a single system or a dual system. Try
1689384SAndreas.Sandberg@arm.com# initializing the CPUs in all known system attributes.
1699384SAndreas.Sandberg@arm.comfor sysattr in [ "system", "testsys", "drivesys" ]:
1709384SAndreas.Sandberg@arm.com    if hasattr(root, sysattr):
1719384SAndreas.Sandberg@arm.com        initCPUs(getattr(root, sysattr))
1729384SAndreas.Sandberg@arm.com
1739447SAndreas.Sandberg@ARM.comrun_test(root)
174