run.py revision 9401
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 965523Snate@binkert.org# Since we're in batch mode, dont allow tcp socket connections 975523Snate@binkert.orgm5.disableAllListeners() 982997Sstever@eecs.umich.edu 992997Sstever@eecs.umich.edu# single "path" arg encodes everything we need to know about test 1008802Sgblack@eecs.umich.edu(category, mode, name, isa, opsys, config) = sys.argv[1].split('/')[-6:] 1012997Sstever@eecs.umich.edu 1022997Sstever@eecs.umich.edu# find path to directory containing this file 1032997Sstever@eecs.umich.edutests_root = os.path.dirname(__file__) 1046874SSteve.Reinhardt@amd.comtest_progs = os.environ.get('M5_TEST_PROGS', '/dist/m5/regression/test-progs') 1056874SSteve.Reinhardt@amd.comif not os.path.isdir(test_progs): 1066289Snate@binkert.org test_progs = joinpath(tests_root, 'test-progs') 1072998Sstever@eecs.umich.edu 1082998Sstever@eecs.umich.edu# generate path to binary file 1092998Sstever@eecs.umich.edudef binpath(app, file=None): 1102998Sstever@eecs.umich.edu # executable has same name as app unless specified otherwise 1112998Sstever@eecs.umich.edu if not file: 1122998Sstever@eecs.umich.edu file = app 1136289Snate@binkert.org return joinpath(test_progs, app, 'bin', isa, opsys, file) 1142997Sstever@eecs.umich.edu 1153475Sktlim@umich.edu# generate path to input file 1163475Sktlim@umich.edudef inputpath(app, file=None): 1173475Sktlim@umich.edu # input file has same name as app unless specified otherwise 1183475Sktlim@umich.edu if not file: 1193475Sktlim@umich.edu file = app 1206289Snate@binkert.org return joinpath(test_progs, app, 'input', file) 1213475Sktlim@umich.edu 1222997Sstever@eecs.umich.edu# build configuration 1236289Snate@binkert.orgsys.path.append(joinpath(tests_root, 'configs')) 1246928SBrad.Beckmann@amd.comtest_filename = config 1256928SBrad.Beckmann@amd.com# for ruby configurations, remove the protocol name from the test filename 1266928SBrad.Beckmann@amd.comif re.search('-ruby', test_filename): 1276928SBrad.Beckmann@amd.com test_filename = test_filename.split('-ruby')[0]+'-ruby' 1286928SBrad.Beckmann@amd.comexecfile(joinpath(tests_root, 'configs', test_filename + '.py')) 1292997Sstever@eecs.umich.edu 1302997Sstever@eecs.umich.edu# set default maxtick... script can override 1312998Sstever@eecs.umich.edu# -1 means run forever 1325523Snate@binkert.orgmaxtick = m5.MaxTick 1332997Sstever@eecs.umich.edu 1342997Sstever@eecs.umich.edu# tweak configuration for specific test 1358802Sgblack@eecs.umich.edusys.path.append(joinpath(tests_root, category, mode, name)) 1368802Sgblack@eecs.umich.eduexecfile(joinpath(tests_root, category, mode, name, 'test.py')) 1372997Sstever@eecs.umich.edu 1389384SAndreas.Sandberg@arm.com# Initialize all CPUs in a system 1399384SAndreas.Sandberg@arm.comdef initCPUs(sys): 1409384SAndreas.Sandberg@arm.com def initCPU(cpu): 1419384SAndreas.Sandberg@arm.com # We might actually have a MemTest object or something similar 1429384SAndreas.Sandberg@arm.com # here that just pretends to be a CPU. 1439384SAndreas.Sandberg@arm.com if isinstance(cpu, BaseCPU): 1449384SAndreas.Sandberg@arm.com cpu.createThreads() 1459384SAndreas.Sandberg@arm.com 1469384SAndreas.Sandberg@arm.com # The CPU attribute doesn't exist in some cases, e.g. the Ruby 1479384SAndreas.Sandberg@arm.com # testers. 1489384SAndreas.Sandberg@arm.com if not hasattr(sys, "cpu"): 1499384SAndreas.Sandberg@arm.com return 1509384SAndreas.Sandberg@arm.com 1519384SAndreas.Sandberg@arm.com # The CPU can either be a list of CPUs or a single object. 1529384SAndreas.Sandberg@arm.com if isinstance(sys.cpu, list): 1539384SAndreas.Sandberg@arm.com [ initCPU(cpu) for cpu in sys.cpu ] 1549384SAndreas.Sandberg@arm.com else: 1559384SAndreas.Sandberg@arm.com initCPU(sys.cpu) 1569384SAndreas.Sandberg@arm.com 1579384SAndreas.Sandberg@arm.com# We might be creating a single system or a dual system. Try 1589384SAndreas.Sandberg@arm.com# initializing the CPUs in all known system attributes. 1599384SAndreas.Sandberg@arm.comfor sysattr in [ "system", "testsys", "drivesys" ]: 1609384SAndreas.Sandberg@arm.com if hasattr(root, sysattr): 1619384SAndreas.Sandberg@arm.com initCPUs(getattr(root, sysattr)) 1629384SAndreas.Sandberg@arm.com 1632997Sstever@eecs.umich.edu# instantiate configuration 1647525Ssteve.reinhardt@amd.comm5.instantiate() 1652997Sstever@eecs.umich.edu 1662997Sstever@eecs.umich.edu# simulate until program terminates 1672997Sstever@eecs.umich.eduexit_event = m5.simulate(maxtick) 1682997Sstever@eecs.umich.edu 1692997Sstever@eecs.umich.eduprint 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause() 170