se.py revision 2957
1# Simple test script
2#
3# Alpha: "m5 test.py"
4# MIPS: "m5 test.py -c hello_mips"
5
6import m5
7import os, optparse, sys
8m5.AddToPath('../common')
9from SEConfig import *
10from FullO3Config import *
11from m5.objects import *
12
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("-d", "--detailed", action="store_true")
23parser.add_option("-t", "--timing", action="store_true")
24parser.add_option("-m", "--maxtick", type="int")
25
26(options, args) = parser.parse_args()
27
28if args:
29    print "Error: script doesn't take any positional arguments"
30    sys.exit(1)
31
32this_dir = os.path.dirname(__file__)
33
34process = LiveProcess()
35process.executable = os.path.join(this_dir, options.cmd)
36process.cmd = options.cmd + " " + options.options
37if options.input != "":
38    process.input = options.input
39
40if options.detailed:
41    #check for SMT workload
42    workloads = options.cmd.split(';')
43    if len(workloads) > 1:
44        process = []
45        smt_idx = 0
46        inputs = []
47
48        if options.input != "":
49            inputs = options.input.split(';')
50
51        for wrkld in workloads:
52            smt_process = LiveProcess()
53            smt_process.executable = os.path.join(this_dir, wrkld)
54            smt_process.cmd = wrkld + " " + options.options
55            if inputs and inputs[smt_idx]:
56                smt_process.input = inputs[smt_idx]
57            process += [smt_process, ]
58            smt_idx += 1
59
60
61if options.timing:
62    cpu = TimingSimpleCPU()
63elif options.detailed:
64    cpu = DetailedO3CPU()
65else:
66    cpu = AtomicSimpleCPU()
67
68root = MySESystem(cpu, process)
69
70if options.timing or options.detailed:
71    root.system.mem_mode = 'timing'
72
73# instantiate configuration
74m5.instantiate(root)
75
76# simulate until program terminates
77if options.maxtick:
78    exit_event = m5.simulate(options.maxtick)
79else:
80    exit_event = m5.simulate()
81
82print 'Exiting @ tick', m5.curTick(), 'because', exit_event.getCause()
83
84