run.py revision 9654
112866Sgabeblack@google.com# Copyright (c) 2012 ARM Limited 212866Sgabeblack@google.com# All rights reserved 312866Sgabeblack@google.com# 412866Sgabeblack@google.com# The license below extends only to copyright in the software and shall 512866Sgabeblack@google.com# not be construed as granting a license to any other intellectual 612866Sgabeblack@google.com# property including but not limited to intellectual property relating 712866Sgabeblack@google.com# to a hardware implementation of the functionality of the software 812866Sgabeblack@google.com# licensed hereunder. You may use the software subject to the license 912866Sgabeblack@google.com# terms below provided that you ensure that this notice is replicated 1012866Sgabeblack@google.com# unmodified and in its entirety in all distributions of the software, 1112866Sgabeblack@google.com# modified or unmodified, in source code or in binary form. 1212866Sgabeblack@google.com# 1312866Sgabeblack@google.com# Copyright (c) 2006-2007 The Regents of The University of Michigan 1412866Sgabeblack@google.com# All rights reserved. 1512866Sgabeblack@google.com# 1612866Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without 1712866Sgabeblack@google.com# modification, are permitted provided that the following conditions are 1812866Sgabeblack@google.com# met: redistributions of source code must retain the above copyright 1912866Sgabeblack@google.com# notice, this list of conditions and the following disclaimer; 2012866Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright 2112866Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the 2212866Sgabeblack@google.com# documentation and/or other materials provided with the distribution; 2312866Sgabeblack@google.com# neither the name of the copyright holders nor the names of its 2412866Sgabeblack@google.com# contributors may be used to endorse or promote products derived from 2512866Sgabeblack@google.com# this software without specific prior written permission. 2612866Sgabeblack@google.com# 2712866Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2812866Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2912866Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3012866Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3112866Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3212866Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3312866Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3412866Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3512866Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3612866Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3712866Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3812866Sgabeblack@google.com# 3912866Sgabeblack@google.com# Authors: Steve Reinhardt 4012866Sgabeblack@google.com 4112866Sgabeblack@google.comimport os 4212866Sgabeblack@google.comimport sys 4312866Sgabeblack@google.comimport re 4412866Sgabeblack@google.comimport string 4512866Sgabeblack@google.com 4612866Sgabeblack@google.comfrom os.path import join as joinpath 4712866Sgabeblack@google.comimport os.path 4812866Sgabeblack@google.comimport os 4912866Sgabeblack@google.com 5012866Sgabeblack@google.comimport m5 5112866Sgabeblack@google.com 5212866Sgabeblack@google.comdef skip_test(reason=""): 5312866Sgabeblack@google.com """Signal that a test should be skipped and optionally print why. 5412866Sgabeblack@google.com 5512866Sgabeblack@google.com Keyword arguments: 5612866Sgabeblack@google.com reason -- Reason why the test failed. Output is omitted if empty. 5712866Sgabeblack@google.com """ 5812866Sgabeblack@google.com 5912866Sgabeblack@google.com if reason: 6012866Sgabeblack@google.com print "Skipping test: %s" % reason 6112866Sgabeblack@google.com sys.exit(2) 6212866Sgabeblack@google.com 6312866Sgabeblack@google.comdef has_sim_object(name): 6412866Sgabeblack@google.com """Test if a SimObject exists in the simulator. 6512922Sgabeblack@google.com 6612869Sgabeblack@google.com Arguments: 6712866Sgabeblack@google.com name -- Name of SimObject (string) 6812869Sgabeblack@google.com 6912866Sgabeblack@google.com Returns: True if the object exists, False otherwise. 7012866Sgabeblack@google.com """ 7112866Sgabeblack@google.com 7212866Sgabeblack@google.com try: 7312866Sgabeblack@google.com cls = getattr(m5.objects, name) 7412866Sgabeblack@google.com return issubclass(cls, m5.objects.SimObject) 7512866Sgabeblack@google.com except AttributeError: 7612866Sgabeblack@google.com return False 7712866Sgabeblack@google.com 7812866Sgabeblack@google.comdef require_sim_object(name, fatal=False): 7912922Sgabeblack@google.com """Test if a SimObject exists and abort/skip test if not. 8012866Sgabeblack@google.com 8112866Sgabeblack@google.com Arguments: 8212866Sgabeblack@google.com name -- Name of SimObject (string) 8312866Sgabeblack@google.com 8412869Sgabeblack@google.com Keyword arguments: 8512869Sgabeblack@google.com fatal -- Set to True to indicate that the test should fail 8612869Sgabeblack@google.com instead of being skipped. 8712869Sgabeblack@google.com """ 8812869Sgabeblack@google.com 8912869Sgabeblack@google.com if has_sim_object(name): 9012869Sgabeblack@google.com return 9112869Sgabeblack@google.com else: 9212866Sgabeblack@google.com msg = "Test requires the '%s' SimObject." % name 9312866Sgabeblack@google.com if fatal: 9412866Sgabeblack@google.com m5.fatal(msg) 9512866Sgabeblack@google.com else: 9612866Sgabeblack@google.com skip_test(msg) 9712866Sgabeblack@google.com 9812866Sgabeblack@google.com 9912866Sgabeblack@google.comdef require_file(path, fatal=False, mode=os.F_OK): 10012866Sgabeblack@google.com """Test if a file exists and abort/skip test if not. 10112866Sgabeblack@google.com 10212866Sgabeblack@google.com Arguments: 10312866Sgabeblack@google.com path -- File to test for. 10412866Sgabeblack@google.com 10512866Sgabeblack@google.com Keyword arguments: 10612866Sgabeblack@google.com fatal -- Set to True to indicate that the test should fail 10712866Sgabeblack@google.com instead of being skipped. 10812866Sgabeblack@google.com modes -- Mode to test for, default to existence. See the 10912866Sgabeblack@google.com Python documentation for os.access(). 11012866Sgabeblack@google.com """ 11112866Sgabeblack@google.com 11212866Sgabeblack@google.com if os.access(path, mode): 11312866Sgabeblack@google.com return 11412866Sgabeblack@google.com else: 11512866Sgabeblack@google.com msg = "Test requires '%s'" % path 11612866Sgabeblack@google.com if not os.path.exists(path): 11712866Sgabeblack@google.com msg += " which does not exist." 11812866Sgabeblack@google.com else: 11912866Sgabeblack@google.com msg += " which has incorrect permissions." 12012866Sgabeblack@google.com 12112866Sgabeblack@google.com if fatal: 12212866Sgabeblack@google.com m5.fatal(msg) 12312866Sgabeblack@google.com else: 12412866Sgabeblack@google.com skip_test(msg) 12512866Sgabeblack@google.com 12612866Sgabeblack@google.comdef require_kvm(kvm_dev="/dev/kvm", fatal=False): 12712866Sgabeblack@google.com """Test if KVM is available. 12812866Sgabeblack@google.com 12912866Sgabeblack@google.com Keyword arguments: 13012866Sgabeblack@google.com kvm_dev -- Device to test (normally /dev/kvm) 13112866Sgabeblack@google.com fatal -- Set to True to indicate that the test should fail 13212866Sgabeblack@google.com instead of being skipped. 13312866Sgabeblack@google.com """ 13412866Sgabeblack@google.com 13512866Sgabeblack@google.com require_sim_object("BaseKvmCPU", fatal=fatal) 13612866Sgabeblack@google.com require_file(kvm_dev, fatal=fatal, mode=os.R_OK | os.W_OK) 13712866Sgabeblack@google.com 13812866Sgabeblack@google.comdef run_test(root): 13912866Sgabeblack@google.com """Default run_test implementations. Scripts can override it.""" 14012866Sgabeblack@google.com 14112866Sgabeblack@google.com # instantiate configuration 14212866Sgabeblack@google.com m5.instantiate() 14312866Sgabeblack@google.com 14412866Sgabeblack@google.com # simulate until program terminates 14512866Sgabeblack@google.com exit_event = m5.simulate(maxtick) 14612866Sgabeblack@google.com print 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause() 14712866Sgabeblack@google.com 14812866Sgabeblack@google.com# Since we're in batch mode, dont allow tcp socket connections 14912866Sgabeblack@google.comm5.disableAllListeners() 15012866Sgabeblack@google.com 15112866Sgabeblack@google.com# single "path" arg encodes everything we need to know about test 15212866Sgabeblack@google.com(category, mode, name, isa, opsys, config) = sys.argv[1].split('/')[-6:] 15312866Sgabeblack@google.com 15412866Sgabeblack@google.com# find path to directory containing this file 15512866Sgabeblack@google.comtests_root = os.path.dirname(__file__) 15612866Sgabeblack@google.comtest_progs = os.environ.get('M5_TEST_PROGS', '/dist/m5/regression/test-progs') 15712866Sgabeblack@google.comif not os.path.isdir(test_progs): 15812866Sgabeblack@google.com test_progs = joinpath(tests_root, 'test-progs') 15912866Sgabeblack@google.com 16012866Sgabeblack@google.com# generate path to binary file 16112866Sgabeblack@google.comdef binpath(app, file=None): 16212866Sgabeblack@google.com # executable has same name as app unless specified otherwise 16312866Sgabeblack@google.com if not file: 164 file = app 165 return joinpath(test_progs, app, 'bin', isa, opsys, file) 166 167# generate path to input file 168def inputpath(app, file=None): 169 # input file has same name as app unless specified otherwise 170 if not file: 171 file = app 172 return joinpath(test_progs, app, 'input', file) 173 174# build configuration 175sys.path.append(joinpath(tests_root, 'configs')) 176test_filename = config 177# for ruby configurations, remove the protocol name from the test filename 178if re.search('-ruby', test_filename): 179 test_filename = test_filename.split('-ruby')[0]+'-ruby' 180execfile(joinpath(tests_root, 'configs', test_filename + '.py')) 181 182# set default maxtick... script can override 183# -1 means run forever 184maxtick = m5.MaxTick 185 186# tweak configuration for specific test 187sys.path.append(joinpath(tests_root, category, mode, name)) 188execfile(joinpath(tests_root, category, mode, name, 'test.py')) 189 190# Initialize all CPUs in a system 191def initCPUs(sys): 192 def initCPU(cpu): 193 # We might actually have a MemTest object or something similar 194 # here that just pretends to be a CPU. 195 if isinstance(cpu, BaseCPU): 196 cpu.createThreads() 197 198 # The CPU attribute doesn't exist in some cases, e.g. the Ruby 199 # testers. 200 if not hasattr(sys, "cpu"): 201 return 202 203 # The CPU can either be a list of CPUs or a single object. 204 if isinstance(sys.cpu, list): 205 [ initCPU(cpu) for cpu in sys.cpu ] 206 else: 207 initCPU(sys.cpu) 208 209# We might be creating a single system or a dual system. Try 210# initializing the CPUs in all known system attributes. 211for sysattr in [ "system", "testsys", "drivesys" ]: 212 if hasattr(root, sysattr): 213 initCPUs(getattr(root, sysattr)) 214 215run_test(root) 216