Merge ktlim@zizzer:/bk/newmem
[gem5.git] / configs / test / test.py
1 # Simple test script
2 #
3 # Alpha: "m5 test.py"
4 # MIPS: "m5 test.py -a Mips -c hello_mips"
5
6 import os, optparse, sys
7 import m5
8 from m5.objects import *
9 from FullO3Config import *
10
11 # parse command-line arguments
12 parser = optparse.OptionParser(option_list=m5.standardOptions)
13
14 parser.add_option("-c", "--cmd", default="hello",
15 help="The binary to run in syscall emulation mode.")
16 parser.add_option("-o", "--options", default="",
17 help="The options to pass to the binary, use \" \" around the entire\
18 string.")
19 parser.add_option("-i", "--input", default="",
20 help="A file of input to give to the binary.")
21 parser.add_option("-t", "--timing", action="store_true",
22 help="Use simple timing CPU.")
23 parser.add_option("-d", "--detailed", action="store_true",
24 help="Use detailed CPU.")
25 parser.add_option("-m", "--maxtick", type="int",
26 help="Set the maximum number of ticks to run for")
27
28 (options, args) = parser.parse_args()
29 m5.setStandardOptions(options)
30
31 if args:
32 print "Error: script doesn't take any positional arguments"
33 sys.exit(1)
34
35 # build configuration
36 this_dir = os.path.dirname(__file__)
37
38 process = LiveProcess()
39 process.executable = os.path.join(this_dir, options.cmd)
40 process.cmd = options.cmd + " " + options.options
41 if options.input != "":
42 process.input = options.input
43
44 magicbus = Bus()
45 mem = PhysicalMemory()
46
47 if options.timing and options.detailed:
48 print "Error: you may only specify one cpu model";
49 sys.exit(1)
50
51 if options.timing:
52 cpu = TimingSimpleCPU()
53 elif options.detailed:
54 #check for SMT workload
55 workloads = options.cmd.split(';')
56 if len(workloads) > 1:
57 process = []
58 smt_idx = 0
59 inputs = []
60
61 if options.input != "":
62 inputs = options.input.split(';')
63
64 for wrkld in workloads:
65 smt_process = LiveProcess()
66 smt_process.executable = os.path.join(this_dir, wrkld)
67 smt_process.cmd = wrkld + " " + options.options
68 if inputs and inputs[smt_idx]:
69 smt_process.input = inputs[smt_idx]
70 process += [smt_process, ]
71 smt_idx += 1
72
73 cpu = DetailedO3CPU()
74 else:
75 cpu = AtomicSimpleCPU()
76 cpu.workload = process
77 cpu.mem = magicbus
78
79 system = System(physmem = mem, cpu = cpu)
80 mem.port = magicbus.port
81 root = Root(system = system)
82
83 # instantiate configuration
84 m5.instantiate(root)
85
86 # simulate until program terminates
87 if options.maxtick:
88 exit_event = m5.simulate(options.maxtick)
89 else:
90 exit_event = m5.simulate()
91
92 print 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause()
93