se.py revision 2889
1# Simple test script
2#
3# Alpha: "m5 test.py"
4# MIPS: "m5 test.py -a Mips -c hello_mips"
5
6import os, optparse, sys
7
8import m5
9from m5.objects import *
10from FullO3Config import *
11
12# parse command-line arguments
13parser = optparse.OptionParser()
14
15parser.add_option("-c", "--cmd", default="hello",
16        help="The binary to run in syscall emulation mode.")
17parser.add_option("-o", "--options", default="",
18        help="The options to pass to the binary, use \" \" around the entire\
19                string.")
20parser.add_option("-i", "--input", default="",
21        help="A file of input to give to the binary.")
22parser.add_option("-t", "--timing", action="store_true",
23        help="Use simple timing CPU.")
24parser.add_option("-d", "--detailed", action="store_true",
25        help="Use detailed CPU.")
26parser.add_option("-m", "--maxtick", type="int",
27        help="Set the maximum number of ticks to run  for")
28
29(options, args) = parser.parse_args()
30
31if args:
32    print "Error: script doesn't take any positional arguments"
33    sys.exit(1)
34
35# build configuration
36this_dir = os.path.dirname(__file__)
37
38process = LiveProcess()
39process.executable = os.path.join(this_dir, options.cmd)
40process.cmd = options.cmd + " " + options.options
41if options.input != "":
42    process.input = options.input
43
44magicbus = Bus()
45mem = PhysicalMemory()
46
47if options.timing and options.detailed:
48       print "Error: you may only specify one cpu model";
49       sys.exit(1)
50
51if options.timing:
52    cpu = TimingSimpleCPU()
53elif 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()
74else:
75    cpu = AtomicSimpleCPU()
76cpu.workload = process
77cpu.mem = magicbus
78cpu.icache_port=magicbus.port
79cpu.dcache_port=magicbus.port
80
81system = System(physmem = mem, cpu = cpu)
82mem.port = magicbus.port
83root = Root(system = system)
84
85# instantiate configuration
86m5.instantiate(root)
87
88# simulate until program terminates
89if options.maxtick:
90    exit_event = m5.simulate(options.maxtick)
91else:
92    exit_event = m5.simulate()
93
94print 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause()
95
96