PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/util/checkpoint-tester.py

https://bitbucket.org/musleh123/gem5_cetus
Python | 135 lines | 47 code | 21 blank | 67 comment | 5 complexity | a8748d03fcb60ae0a1f5d9ecbb29691a MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. #! /usr/bin/env python
  2. # Copyright (c) 2010 Advanced Micro Devices, Inc.
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are
  7. # met: redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer;
  9. # redistributions in binary form must reproduce the above copyright
  10. # notice, this list of conditions and the following disclaimer in the
  11. # documentation and/or other materials provided with the distribution;
  12. # neither the name of the copyright holders nor the names of its
  13. # contributors may be used to endorse or promote products derived from
  14. # this software without specific prior written permission.
  15. #
  16. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  20. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. #
  28. # Author: Steve Reinhardt
  29. #
  30. # Basic test script for checkpointing.
  31. #
  32. # Given an M5 command and an interval (in ticks), this script will:
  33. # 1. Run the command, dumping periodic checkpoints at the given interval.
  34. # 2. Rerun the command for each pair of adjacent checkpoints:
  35. # a. Restore from checkpoint N
  36. # b. Run until the timestamp of checkpoint N+1
  37. # c. Dump a checkpoint and end the simulation
  38. # d. Diff the new checkpoint with the original checkpoint N+1
  39. #
  40. # Note that '--' must be used to separate the script options from the
  41. # M5 command line.
  42. #
  43. # Caveats:
  44. #
  45. # - This script relies on the checkpoint options implemented in
  46. # configs/common/Simulation.py, so it works with commands based on
  47. # the se.py and fs.py scripts in configs/example, but does not work
  48. # directly with the existing regression tests.
  49. # - Interleaving simulator and program output can cause discrepancies
  50. # in the file position checkpoint information since different runs
  51. # have different amount of simulator output.
  52. # - Probably lots more issues we don't even know about yet.
  53. #
  54. # Examples:
  55. #
  56. # util/checkpoint-tester.py -i 400000 -- build/ALPHA_SE/m5.opt \
  57. # configs/example/se.py -c tests/test-progs/hello/bin/alpha/tru64/hello \
  58. # --output=progout --errout=progerr
  59. #
  60. # util/checkpoint-tester.py -i 200000000000 -- build/ALPHA_FS/m5.opt \
  61. # configs/example/fs.py --script tests/halt.sh
  62. #
  63. import os, sys, re
  64. import subprocess
  65. import optparse
  66. parser = optparse.OptionParser()
  67. parser.add_option('-i', '--interval', type='int')
  68. parser.add_option('-d', '--directory', default='checkpoint-test')
  69. (options, args) = parser.parse_args()
  70. interval = options.interval
  71. if os.path.exists(options.directory):
  72. print 'Error: test directory', options.directory, 'exists'
  73. print ' Tester needs to create directory from scratch'
  74. sys.exit(1)
  75. top_dir = options.directory
  76. os.mkdir(top_dir)
  77. cmd_echo = open(os.path.join(top_dir, 'command'), 'w')
  78. print >>cmd_echo, ' '.join(sys.argv)
  79. cmd_echo.close()
  80. m5_binary = args[0]
  81. options = args[1:]
  82. initial_args = ['--take-checkpoints', '%d,%d' % (interval, interval)]
  83. cptdir = os.path.join(top_dir, 'm5out')
  84. print '===> Running initial simulation.'
  85. subprocess.call([m5_binary] + ['-red', cptdir] + options + initial_args)
  86. dirs = os.listdir(cptdir)
  87. expr = re.compile('cpt\.([0-9]*)')
  88. cpts = []
  89. for dir in dirs:
  90. match = expr.match(dir)
  91. if match:
  92. cpts.append(int(match.group(1)))
  93. cpts.sort()
  94. # We test by loading checkpoint N, simulating to (and dumping at)
  95. # checkpoint N+1, then comparing the resulting checkpoint with the
  96. # original checkpoint N+1. Thus the number of tests we can run is one
  97. # less than tha number of checkpoints.
  98. for i in range(1, len(cpts)):
  99. print '===> Running test %d of %d.' % (i, len(cpts)-1)
  100. mydir = os.path.join(top_dir, 'test.%d' % i)
  101. subprocess.call([m5_binary] + ['-red', mydir] + options + initial_args +
  102. ['--max-checkpoints' , '1', '--checkpoint-dir', cptdir,
  103. '--checkpoint-restore', str(i)])
  104. cpt_name = 'cpt.%d' % cpts[i]
  105. diff_name = os.path.join(mydir, 'diffout')
  106. diffout = open(diff_name, 'w')
  107. subprocess.call(['diff', '-ru', '-I', '^##.*',
  108. '%s/%s' % (cptdir, cpt_name),
  109. '%s/%s' % (mydir, cpt_name)], stdout=diffout)
  110. diffout.close()
  111. # print out the diff
  112. diffout = open(diff_name)
  113. print diffout.read(),
  114. diffout.close()