-
Notifications
You must be signed in to change notification settings - Fork 9
/
run_tests.py
executable file
·464 lines (372 loc) · 16.6 KB
/
run_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
#!/usr/bin/env python
import copy
import os
import re
import shutil
import sys
import tempfile
import unittest
import xiosim_driver as xd
import xiosim_stat as xs
def CreateDriver():
XIOSIM_INSTALL = os.environ["XIOSIM_INSTALL"]
XIOSIM_TREE = os.environ["XIOSIM_TREE"]
ARCH = os.environ["TARGET_ARCH"]
xio = xd.XIOSimDriver(XIOSIM_INSTALL, XIOSIM_TREE, ARCH)
return xio
class XIOSimTest(unittest.TestCase):
''' Test fixtures for XIOSim end-to-end tests.'''
def setUp(self):
''' Set up a driver with common options and a temp run directory.'''
self.xio = CreateDriver()
self.run_dir = tempfile.mkdtemp()
self.clean_run_dir = ("LEAVE_TEST_DIR" not in os.environ)
self.setDriverParams()
self.expected_vals = []
self.expected_exprs = []
self.bmk_expected_vals = []
def tearDown(self):
if self.clean_run_dir:
shutil.rmtree(self.xio.GetRunDir())
def runAndValidate(self):
''' Execute XIOSimDriver and check output for golden values of stats.'''
out_file = os.path.join(self.run_dir, "harness.out")
err_file = os.path.join(self.run_dir, "harness.err")
ret = self.xio.Exec(stdout_file=out_file, stderr_file=err_file, cwd=self.run_dir)
self.assertEqual(ret, 0, "XIOSim run failed (errcode %d)" % ret)
for re, golden_val in self.expected_vals:
val = xs.GetStat(self.xio.GetSimOut(), re)
res = xs.ValidateStat(val, golden_val)
self.assertEqual(res, True, "%s: expected %.2f, got %.2f" %
(re, golden_val, val))
for re, golden_val in self.bmk_expected_vals:
val = xs.GetStat(self.xio.GetTestOut(), re)
res = xs.ValidateStat(val, golden_val)
self.assertEqual(res, True, "%s: expected %.6f, got %.6f" %
(re, golden_val, val))
for re, expr in self.expected_exprs:
val = xs.GetStat(self.xio.GetSimOut(), re)
test_fn = expr[0]
test_val = expr[1]
test_fn(val, test_val, "%s: %s %.2f, got %.2f" %
(re, test_fn.__name__, test_val, val))
def writeTestBmkConfig(self, bmk, num_copies=1):
''' Create a temp benchmark config file in the test run directory.'''
cfg_file = self.xio.GenerateTestBmkConfig(bmk, num_copies)
bmk_cfg = os.path.join(self.run_dir, "%s.cfg" % bmk)
with open(bmk_cfg, "w") as f:
for l in cfg_file:
f.write(l)
return bmk_cfg
def writeTestConfig(self, start_config, changes):
''' Create a temp config file in the test run directory,
starting with @start_config and applying a dictionary or
paramter changes. '''
cfg_file = os.path.join(self.run_dir, os.path.basename(start_config))
cfg_contents = self.xio.GenerateConfigFile(start_config, changes)
with open(cfg_file, "w") as f:
for l in cfg_contents:
f.write(l)
return cfg_file
class Fib1Test(XIOSimTest):
''' End-to-end test with a single binary running from start to end.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("fib")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
self.xio.AddZestoOptions(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "N.cfg"))
def setUp(self):
super(Fib1Test, self).setUp()
self.expected_vals.append((xs.PerfStatRE("all_insn"), 114495.0))
def runTest(self):
self.runAndValidate()
class NoneTest(XIOSimTest):
''' End-to-end test with the 'none' core model.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("fib")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
self.xio.AddZestoOptions(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "none.cfg"))
def setUp(self):
super(NoneTest, self).setUp()
self.expected_vals.append((xs.PerfStatRE("all_insn"), 114495.0))
def runTest(self):
self.runAndValidate()
class Fib1LengthTest(XIOSimTest):
''' End-to-end test with a single binary running for X instructions.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("fib")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
self.xio.AddInstLength(10000)
self.xio.AddZestoOptions(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "N.cfg"))
def setUp(self):
super(Fib1LengthTest, self).setUp()
self.expected_vals.append((xs.PerfStatRE("all_insn"), 9900.0))
def runTest(self):
self.runAndValidate()
class Fib1SkipTest(XIOSimTest):
''' End-to-end test with a single binary skipping first X instructions.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("fib")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
self.xio.AddSkipInst(50000)
self.xio.AddZestoOptions(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "N.cfg"))
def setUp(self):
super(Fib1SkipTest, self).setUp()
self.expected_vals.append((xs.PerfStatRE("all_insn"), 64495.0))
def runTest(self):
self.runAndValidate()
class Fib1PinPointTest(XIOSimTest):
''' End-to-end test with a single binary and one pinpoint.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("fib")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
ppfile = os.path.join(self.xio.GetTreeDir(), "tests",
self.xio.TARGET_ARCH, "fib..pintool.1.pp")
self.xio.AddPinPointFile(ppfile)
self.xio.AddZestoOptions(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "N.cfg"))
def setUp(self):
super(Fib1PinPointTest, self).setUp()
self.expected_vals.append((xs.PerfStatRE("all_insn"), 30000.0))
def runTest(self):
self.runAndValidate()
class Fib1PinPointsTest(XIOSimTest):
''' End-to-end test with a single binary and multiple pinpoints.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("fib")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
ppfile = os.path.join(self.xio.GetTreeDir(), "tests",
self.xio.TARGET_ARCH, "fib..pintool.2.pp")
self.xio.AddPinPointFile(ppfile)
self.xio.AddZestoOptions(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "N.cfg"))
def setUp(self):
super(Fib1PinPointsTest, self).setUp()
self.expected_vals.append((xs.PerfStatRE("all_insn"), 9430.0))
def runTest(self):
self.runAndValidate()
class ROITest(XIOSimTest):
''' End-to-end test with a single binary with ROI hooks.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("roi")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
self.xio.AddROIOptions()
self.xio.AddZestoOptions(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "N.cfg"))
def setUp(self):
super(ROITest, self).setUp()
self.expected_vals.append((xs.PerfStatRE("all_insn"), 217000.0))
def runTest(self):
self.runAndValidate()
class ReplaceTest(XIOSimTest):
''' End-to-end test where we replace a function call with a NOP.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("repl")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
self.xio.AddReplaceOptions("fib_repl")
# 30K cycles for the magic instruction that replaces fib_repl()
# 30K is high enough that the test can catch if we didn't add it,
# yet low enough that it doesn't tickle the deadlock threshold (50K)
repl = {
"core_cfg.exec_cfg.exeu magic.latency" : "30000",
"core_cfg.exec_cfg.exeu magic.rate" : "30000",
}
test_cfg = self.writeTestConfig(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "N.cfg"),
repl)
self.xio.AddZestoOptions(test_cfg)
def setUp(self):
super(ReplaceTest, self).setUp()
# repl is ~1M instructions
# when we correctly ignore the middle call, we expect ~450K
self.expected_vals.append((xs.PerfStatRE("all_insn"), 447000.0))
# repl when we just ignore the middle call takes ~397K cycles + 30K magic
# XXX: Disable this check for now. Branch NOP-iness makes this flaky
# self.expected_vals.append((xs.PerfStatRE("sim_cycle"), 426000.0))
def runTest(self):
self.runAndValidate()
class PowerTest(XIOSimTest):
''' End-to-end test that calculates power.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("fib")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
repl = {
"system_cfg.simulate_power" : "true"
}
test_cfg = self.writeTestConfig(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "A.cfg"),
repl)
self.xio.AddZestoOptions(test_cfg)
def setUp(self):
super(PowerTest, self).setUp()
self.expected_vals.append((xs.PowerStatRE(" Runtime Dynamic"), 0.589))
self.expected_vals.append((xs.PowerStatRE(" Total Leakage"), 0.48))
def runTest(self):
self.runAndValidate()
#TODO(skanev): Add a power trace test
class DFSTest(XIOSimTest):
''' End-to-end test that checks that "sample" DFS modifies frequencies.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("step")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
repl = {
"system_cfg.simulate_power" : "true",
"uncore_cfg.dvfs_cfg.config" : "\"sample\"",
"uncore_cfg.dvfs_cfg.interval" : "20000",
}
test_cfg = self.writeTestConfig(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "A.cfg"),
repl)
self.xio.AddZestoOptions(test_cfg)
def setUp(self):
super(DFSTest, self).setUp()
# Average freq ~901 MHz = 1600 * 2757944.0 / 4895888.0
self.expected_vals.append((xs.PerfStatRE("c0.sim_cycle"), 2757944.0))
self.expected_vals.append((xs.PerfStatRE("sim_cycle"), 4895888.0))
# XXX: The dynamic number appears a little low, but that's more of a
# validation issue, not a "hey, DFS is working" issue
self.expected_vals.append((xs.PowerStatRE(" Runtime Dynamic"), 0.263))
self.expected_vals.append((xs.PowerStatRE(" Total Leakage"), 0.48))
def runTest(self):
self.runAndValidate()
class Fib2Test(XIOSimTest):
''' End-to-end test with multiple programs running from start to end.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("fib", num_copies=2)
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
self.xio.AddZestoOptions(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "N.cfg"))
def setUp(self):
super(Fib2Test, self).setUp()
self.expected_vals.append((xs.PerfStatRE("all_insn"), 228990.00))
def runTest(self):
self.runAndValidate()
class REPTest(XIOSimTest):
''' End-to-end test for REP instructions.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("rep")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
self.xio.AddROIOptions()
self.xio.AddZestoOptions(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "none.cfg"))
def setUp(self):
super(REPTest, self).setUp()
# 917,504 = 3.5 * 256 * 1024 -- see rep.cpp
self.expected_vals.append((xs.PerfStatRE("all_insn"), 917504.0))
def runTest(self):
self.runAndValidate()
class SegfTest(XIOSimTest):
''' End-to-end test for faults on speculative path.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("segf")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
self.xio.AddZestoOptions(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "N.cfg"))
def setUp(self):
super(SegfTest, self).setUp()
def runTest(self):
self.runAndValidate()
class ChaseTest(XIOSimTest):
''' Pointer chase test.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("chase")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
self.xio.AddROIOptions()
self.xio.AddZestoOptions(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "N.cfg"))
def setUp(self):
super(ChaseTest, self).setUp()
self.expected_vals.append((xs.PerfStatRE("all_insn"), 1310720))
# Random tests are random. Give them *very* loose bounds.
self.expected_exprs.append((xs.PerfStatRE("total_IPC"),
(self.assertLess, 0.3)))
def runTest(self):
self.runAndValidate()
class PrefetchTest(XIOSimTest):
''' Pointer chase test with a SW prefetch.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("prefetch")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
self.xio.AddROIOptions()
self.xio.AddZestoOptions(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "N.cfg"))
def setUp(self):
super(PrefetchTest, self).setUp()
self.expected_vals.append((xs.PerfStatRE("all_insn"), 2621440))
# Random tests are random. Give them *very* loose bounds.
self.expected_exprs.append((xs.PerfStatRE("total_IPC"),
(self.assertGreater, 0.9)))
def runTest(self):
self.runAndValidate()
class IgnorePCTest(XIOSimTest):
''' End-to-end test where we ignore specific instructions.'''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("ignore")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
self.xio.AddROIOptions()
if self.xio.TARGET_ARCH == "k8":
self.xio.AddIgnorePCOptions("0x40108a")
else:
self.xio.AddIgnorePCOptions("0x8048bcd")
self.xio.AddZestoOptions(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "none.cfg"))
def setUp(self):
super(IgnorePCTest, self).setUp()
self.expected_vals.append((xs.PerfStatRE("all_insn"), 30000.0))
def runTest(self):
self.runAndValidate()
class TimeTest(XIOSimTest):
''' End-to-end test for gettimeofday(). '''
def setDriverParams(self):
bmk_cfg = self.writeTestBmkConfig("time")
self.xio.AddBmks(bmk_cfg)
self.xio.AddPinOptions()
self.xio.AddPintoolOptions(num_cores=1)
self.xio.AddZestoOptions(os.path.join(self.xio.GetTreeDir(),
"xiosim/config", "N.cfg"))
def setUp(self):
super(TimeTest, self).setUp()
self.expected_vals.append((xs.PerfStatRE("all_insn"), 3000000.0))
# Set up expected output from the simulated program.
# 2M instructions / 3.2GHz = 625us.
elapsed_re = "Elapsed: (%s) sec" % xs.DECIMAL_RE
self.bmk_expected_vals.append((elapsed_re, 0.000625))
def runTest(self):
self.runAndValidate()
if __name__ == "__main__":
unittest.main()