changeset 0db28826e333 in /z/repo/gem5 details: http://repo.gem5.org/gem5?cmd=changeset;node=0db28826e333 description: ext: Add a McPAT regression tester Add a regression tester to McPAT. Joel Hestness wrote these tests and Yasuko Eckert modified them to reflect the new McPAT interface and other changes the previous patch made.
diffstat: .hgignore | 1 + ext/mcpat/regression/README | 75 + ext/mcpat/regression/regression.py | 241 +++++ ext/mcpat/regression/test-0/power_region0.xml | 404 +++++++++ ext/mcpat/regression/test-0/region0.out.ref | 595 ++++++++++++++ ext/mcpat/regression/test-1/power_region0.xml | 811 +++++++++++++++++++ ext/mcpat/regression/test-1/region0.out.ref | 1018 +++++++++++++++++++++++++ ext/mcpat/regression/test-2/power_region0.xml | 242 +++++ ext/mcpat/regression/test-2/region0.out.ref | 190 ++++ ext/mcpat/regression/test-3/power_region0.xml | 71 + ext/mcpat/regression/test-3/region0.out.ref | 82 ++ ext/mcpat/regression/test-4/power_region0.xml | 208 +++++ ext/mcpat/regression/test-4/region0.out.ref | 316 +++++++ ext/mcpat/regression/test-5/power_region0.xml | 338 ++++++++ ext/mcpat/regression/test-5/region0.out.ref | 541 +++++++++++++ ext/mcpat/regression/test-6/power_region0.xml | 401 +++++++++ ext/mcpat/regression/test-6/region0.out.ref | 595 ++++++++++++++ ext/mcpat/regression/test-7/power_region0.xml | 68 + ext/mcpat/regression/test-7/region0.out.ref | 37 + ext/mcpat/regression/test-8/power_region0.xml | 64 + ext/mcpat/regression/test-8/region0.out.ref | 37 + ext/mcpat/regression/verify_output.py | 238 +++++ 22 files changed, 6573 insertions(+), 0 deletions(-) diffs (truncated from 6664 to 300 lines): diff -r 5cb711fa6176 -r 0db28826e333 .hgignore --- a/.hgignore Tue Jun 03 13:32:59 2014 -0700 +++ b/.hgignore Wed Jun 04 07:48:20 2014 -0700 @@ -10,3 +10,4 @@ m5out src/doxygen ext/dramsim2/DRAMSim2 +ext/mcpat/regression/*/*.out diff -r 5cb711fa6176 -r 0db28826e333 ext/mcpat/regression/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ext/mcpat/regression/README Wed Jun 04 07:48:20 2014 -0700 @@ -0,0 +1,75 @@ +regression.py + +Copyright (c) 2010-2014 Advanced Micro Devices, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer; +redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution; +neither the name of the copyright holders nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Authors: Yasuko Eckert <[email protected]> + Joel Hestness <[email protected]> (while interning at AMD) + + +Introduction +============ + +This regression tester is for the McPAT power model. +This tester can compile and runs McPAT on the input contained in the +specified directory, and then compares the output to that of a golden run in +order to ensure that specific power and area calculations do not change. + +Nine tests are included in the initial version of this tester in the directories: + $GEM5/ext/mcpat/regression/test-* + +In each directory, you will find a regression test input file +(power_region0.xml) and the golden-run output (region0.out.bak). +The tester's output file is saved as region0.out, which is then checked against +region0.out.bak. + + +Options +======= +--help, -h Show a help message and exit +--build, -b Build McPAT before running tests +--cleanup, -c Clean up the specified regression directory +--force, -f Force run regression even if directory isn't set up +--maketest, -m Set up the specified test directory +--verbose, -v Print verbose output + + +How to Use +========== + +The regression tester must be invoked from the McPAT directory. + +% cd $GEM5/ext/mcpat + + +To run all regression tests: +% ./regression/regression.py ./regression/ + + +To run a particular regression test, specify its directory to the tester: +% ./regression/regression.py ./regression/test-0 + +Specify the "-v" option to see a diff of the regression output. diff -r 5cb711fa6176 -r 0db28826e333 ext/mcpat/regression/regression.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ext/mcpat/regression/regression.py Wed Jun 04 07:48:20 2014 -0700 @@ -0,0 +1,241 @@ +#!/usr/bin/env python + +# Copyright (c) 2010-2013 Advanced Micro Devices, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer; +# redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution; +# neither the name of the copyright holders nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +""" +SYNOPSIS + + ./regression/regression.py ./regression/ + +DESCRIPTION + + Runs regression tester for McPAT. + This tester can compile and runs McPAT on the input contained in the + specified directory, and then compares the output to that of a prior run in + order to ensure that specific power and area calculations do not change. + +AUTHORS + + Joel Hestness <[email protected]> (while interning at AMD) + Yasuko Eckert <[email protected]> +""" + +import os +import sys +import optparse +import re + +################################ +# Global Variables +################################ + +global mcpat_binary +mcpat_binary = "../../build/mcpat/mcpat" +global optionsparser + +################################ +# Global Functions +################################ + +def run_test(testdir): + test_passed = True + testfiles = os.listdir(testdir) + for testfile in testfiles: + # For each power_region file, run McPAT on it and check the + # output created against the regression + if re.match("power_region.*\.xml$", testfile): + # Get the region index of the test + fileparts = testfile.split(".") + region_index = fileparts[0][12:] + regression_test = os.path.join(testdir, testfile) + regression_output = os.path.join( + testdir, "region%s.out" % region_index) + regression_correct = os.path.join( + testdir, "region%s.out.ref" % region_index) + print "Running test: %s..." % regression_test + # Run McPAT on the input + os.system( + "%s -infile %s -print_level 10 > %s" % + (mcpat_binary, regression_test, regression_output) ) + if os.path.exists(regression_correct): + diff = os.popen( + "diff %s %s" % (regression_output, regression_correct), + "r").read() + if diff != "": + print "WARN: Differences found in %s" % regression_output + if options.verbose: + print diff + test_passed = False + else: + print "WARN: Regression test not set up: %s..." % regression_test + print "WARN: Not able to verify test" + test_passed = False + + if options.cleanup: + if options.verbose: + print "WARN: Cleaning (deleting) regression output file: "\ + "%s" % regression_output + os.system("rm -f %s" % regression_output) + + if test_passed: + print "PASSED: %s\n\n" % testdir + else: + print "FAILED: %s\n\n" % testdir + +def has_power_region_files(testdir): + files = os.listdir(testdir) + for file in files: + if "power_region" in file and ".xml" in file: + return True + +def is_valid_test_directory(testdir): + valid_regression = True + power_region_file_found = False + + files = os.listdir(testdir) + for file in files: + if "power_region" in file and ".xml" in file: + power_region_file_found = True + fileparts = file.split(".") + region_index = fileparts[0][12:] + regression_output = os.path.join( + testdir, "region%s.out.ref" % region_index) + if os.path.exists(regression_output): + if options.verbose: + print "Valid regression test: %s/%s" % (testdir, file) + else: + valid_regression = False + + return valid_regression and power_region_file_found + +################################ +# Execute here +################################ + +optionsparser = optparse.OptionParser( + formatter = optparse.TitledHelpFormatter(), + usage = globals()['__doc__']) +optionsparser.add_option( + "-b", "--build", action = "store_true", default = False, + help = "Build McPAT before running tests") +optionsparser.add_option( + "-c", "--cleanup", action = "store_true", default = False, + help = "Clean up the specified regression directory") +optionsparser.add_option( + "-f", "--force", action = "store_true", default = False, + help = "Force run regression even if directory isn't set up") +optionsparser.add_option( + "-m", "--maketest", action = "store_true", default = False, + help = "Set up the specified test directory") +optionsparser.add_option( + "-v", "--verbose", action = "store_true", default = False, + help = "Print verbose output") +(options, args) = optionsparser.parse_args() + +if not os.path.exists(mcpat_binary) and not options.build: + print "ERROR: McPAT binary does not exist: %s" % mcpat_binary + exit(0) + +if options.build: + print "Building McPAT..." + bin_dir = os.path.dirname(mcpat_binary) + directory = os.path.join(bin_dir, "../../ext/mcpat") + build_output = os.popen( + "cd %s; make clean; make -j 8 dbg 2>&1" % directory).read() + if "error" in build_output.lower(): + print "Error during build: %s" % build_output + exit(0) + +if len(args) < 1: + print "ERROR: Must specify regressions directory" + exit(0) + +# check params +rootdir = args[0]; +if not os.path.exists(rootdir): + print "ERROR: Regressions directory does not exist: %s" % rootdir + exit(0) + +if options.maketest: + # The specified rootdir must exist since we got here + # Check if directory has tests + list = os.listdir(rootdir) + found_test = False + for file in list: + if "power_region" in file and "out" not in file and "ref" not in file: + found_test = True + # Prepare to run the test in order to set it up + fileparts = file.split(".") + region_index = fileparts[0][12:] + regression_test = os.path.join(rootdir, file) + regression_output = os.path.join( + rootdir, "region%s.out.ref" % region_index) + if os.path.exists(regression_output): + print "WARN: Overwriting old regression output: " \ + "%s" % regression_output + # Run the test to set it up + print "Writing new regression output..." + os.system( + "%s -infile %s -print_level 10 > %s" % + (mcpat_binary, regression_test, regression_output)) + + if not found_test: + print "ERROR: Invalid test directory: %s" % rootdir + print "ERROR: Must contain XML file power_region*.xml" + _______________________________________________ gem5-dev mailing list [email protected] http://m5sim.org/mailman/listinfo/gem5-dev
