tests: Delete authors lists from test files.
[gem5.git] / tests / legacy-configs / run.py
1 # Copyright (c) 2017 Mark D. Hill and David A. Wood
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met: redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer;
8 # redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution;
11 # neither the name of the copyright holders nor the names of its
12 # contributors may be used to endorse or promote products derived from
13 # this software without specific prior written permission.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 '''
28 New version of the run.py script. For this, all dependencies should be
29 handled outside of the script.
30
31 .. warning:: This script is NOT the recommended way to handle configurations
32 for new tests. This exists for legacy support only. New Tests should
33 either use configs from the normal gem5 configs or create their own for
34 a test.
35 '''
36 import argparse
37 import sys
38 import os
39 from os.path import abspath, join as joinpath, dirname
40
41 import m5
42
43 # Add the normal gem5 config path to system path.
44 # This requirement should be removed if possible from all legacy scripts, but
45 # I've left it here for now.
46 sys.path.insert(0, abspath(joinpath(dirname(__file__), '../../configs')))
47
48 # set default maxtick... script can override
49 # -1 means run forever
50 maxtick = m5.MaxTick
51
52 def run_test(root):
53 """Default run_test implementations. Scripts can override it."""
54
55 # instantiate configuration
56 m5.instantiate()
57
58 # simulate until program terminates
59 exit_event = m5.simulate(maxtick)
60 print 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause()
61
62 test_progs = os.environ.get('M5_TEST_PROGS', '/dist/m5/regression/test-progs')
63
64 # Since we're in batch mode, dont allow tcp socket connections
65 m5.disableAllListeners()
66
67 parser = argparse.ArgumentParser()
68 parser.add_argument('--cmd',
69 action='store',
70 type=str,
71 help='Command to pass to the test system')
72 parser.add_argument('--executable',
73 action='store',
74 type=str,
75 help='Executable to pass to the test system')
76 parser.add_argument('--config',
77 action='append',
78 type=str,
79 help='A config file to initialize the system with.'\
80 + ' If more than one given, loads them in order given.')
81 args = parser.parse_args()
82
83 executable = args.executable
84
85 for config in args.config:
86 exec(compile(open(config).read(), config, 'exec'))
87
88 # Initialize all CPUs in a system
89 def initCPUs(sys):
90 def initCPU(cpu):
91 # We might actually have a MemTest object or something similar
92 # here that just pretends to be a CPU.
93 try:
94 cpu.createThreads()
95 except:
96 pass
97
98 # The CPU attribute doesn't exist in some cases, e.g. the Ruby testers.
99 if not hasattr(sys, "cpu"):
100 return
101
102 # The CPU can either be a list of CPUs or a single object.
103 if isinstance(sys.cpu, list):
104 [ initCPU(cpu) for cpu in sys.cpu ]
105 else:
106 initCPU(sys.cpu)
107
108 # TODO: Might want to automatically place the cmd and executable on the
109 # cpu[0].workload, although I think most legacy configs do this automatically
110 # or somewhere in their `test.py` config.
111
112
113 # We might be creating a single system or a dual system. Try
114 # initializing the CPUs in all known system attributes.
115 for sysattr in [ "system", "testsys", "drivesys" ]:
116 if hasattr(root, sysattr):
117 initCPUs(getattr(root, sysattr))
118
119 run_test(root)