diff -r 9253d58fb4aa -r 4073cc899399 src/SConscript --- a/src/SConscript Tue Dec 21 08:26:38 2010 -0800 +++ b/src/SConscript Tue Dec 21 08:28:34 2010 -0800 @@ -193,12 +193,14 @@ self.py_source = PySource(package, py_file, parent=self) unit_tests = [] -def UnitTest(target, sources): - if not isinstance(sources, (list, tuple)): - sources = [ sources ] +def UnitTest(target, *sources): + objs = [] + for src in sources: + if not isinstance(src, SourceFile): + src = Source(src, skip_lib=True) + src.flags[target] = True - sources = [ Source(src, skip_lib=True) for src in sources ] - unit_tests.append((target, sources)) + unit_tests.append(target) # Children should have access Export('Source') @@ -629,10 +631,11 @@ env.Command([swig.cc_source.tnode, swig.py_source.tnode], swig.tnode, MakeAction('$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} ' '-o ${TARGETS[0]} $SOURCES', " [ SWIG] $STRIP_TARGET")) - init_file = 'python/swig/init_%s.cc' % swig.module + cc_file = str(swig.tnode) + init_file = '%s/init_%s.cc' % (dirname(cc_file), basename(cc_file)) env.Command(init_file, Value(swig.module), MakeAction(makeEmbeddedSwigInit, " [EMBED SW] $STRIP_TARGET")) - Source(init_file) + Source(init_file, **swig.flags) # # Handle trace flags @@ -850,13 +853,16 @@ static_lib = new_env.StaticLibrary(libname, static_objs) shared_lib = new_env.SharedLibrary(libname, shared_objs) - for target, sources in unit_tests: - objs = [ make_obj(s, static=True) for s in sources ] - new_env.Program("unittest/%s.%s" % (target, label), objs + static_objs) - # Now link a stub with main() and the static library. main_objs = [ make_obj(s, True) for s in Source.get(main=True) ] + for target in unit_tests: + flags = { target : True } + test_sources = Source.get(**flags) + test_objs = [ make_obj(s, static=True) for s in test_sources ] + testname = "unittest/%s.%s" % (target, label) + new_env.Program(testname, main_objs + test_objs + static_objs) + progname = exename if strip: progname += '.unstripped' diff -r 9253d58fb4aa -r 4073cc899399 src/unittest/SConscript --- a/src/unittest/SConscript Tue Dec 21 08:26:38 2010 -0800 +++ b/src/unittest/SConscript Tue Dec 21 08:28:34 2010 -0800 @@ -44,8 +44,12 @@ UnitTest('rangetest', 'rangetest.cc') UnitTest('rangemaptest', 'rangemaptest.cc') UnitTest('rangemultimaptest', 'rangemultimaptest.cc') -UnitTest('stattest', 'stattest.cc') UnitTest('strnumtest', 'strnumtest.cc') + +stattest_py = PySource('m5', 'stattestmain.py', skip_lib=True) +stattest_swig = SwigSource('m5.internal', 'stattest.i', skip_lib=True) +UnitTest('stattest', 'stattest.cc', stattest_py, stattest_swig) + UnitTest('symtest', 'symtest.cc') UnitTest('tokentest', 'tokentest.cc') UnitTest('tracetest', 'tracetest.cc') diff -r 9253d58fb4aa -r 4073cc899399 src/unittest/stattest.cc --- a/src/unittest/stattest.cc Tue Dec 21 08:26:38 2010 -0800 +++ b/src/unittest/stattest.cc Tue Dec 21 08:28:34 2010 -0800 @@ -35,11 +35,17 @@ #include "base/cprintf.hh" #include "base/misc.hh" #include "base/statistics.hh" -#include "base/stats/text.hh" -#include "base/stats/mysql.hh" #include "base/types.hh" #include "sim/stat_control.hh" +// override the default main() code for this unittest +const char *m5MainCommands[] = { + "import m5.stattestmain", + "m5.stattestmain.main()", + 0 // sentinel is required +}; + + using namespace std; using namespace Stats; @@ -54,67 +60,8 @@ double operator()() { return 9.7; } }; -const char *progname = ""; - -void -usage() +struct StatTest { - panic("incorrect usage.\n" - "usage:\n" - "\t%s [-t [-c] [-d]]\n", progname); -} - -int -main(int argc, char *argv[]) -{ - bool descriptions = false; - bool text = false; - -#if USE_MYSQL - string mysql_name; - string mysql_db; - string mysql_host; - string mysql_user = "binkertn"; - string mysql_passwd; -#endif - - char c; - progname = argv[0]; - while ((c = getopt(argc, argv, "cD:dh:P:p:s:tu:")) != -1) { - switch (c) { - case 'd': - descriptions = true; - break; - case 't': - text = true; - break; -#if USE_MYSQL - case 'D': - mysql_db = optarg; - break; - case 'h': - mysql_host = optarg; - break; - case 'P': - mysql_passwd = optarg; - break; - case 's': - mysql_name = optarg; - break; - case 'u': - mysql_user = optarg; - break; -#endif - default: - usage(); - } - } - - if (!text && descriptions) - usage(); - - initSimStats(); - Scalar s1; Scalar s2; Average s3; @@ -140,6 +87,26 @@ Formula f4; Formula f5; + void run(); + void init(); +}; + +StatTest __stattest; +void +stattest_init() +{ + __stattest.init(); +} + +void +stattest_run() +{ + __stattest.run(); +} + +void +StatTest::init() +{ cprintf("sizeof(Scalar) = %d\n", sizeof(Scalar)); cprintf("sizeof(Vector) = %d\n", sizeof(Vector)); cprintf("sizeof(Distribution) = %d\n", sizeof(Distribution)); @@ -302,10 +269,11 @@ f4 += constant(10.0); f4 += s5[3]; f5 = constant(1); +} - enable(); - reset(); - +void +StatTest::run() +{ s16[1][0] = 1; s16[0][1] = 3; s16[0][0] = 2; @@ -543,23 +511,4 @@ s6.sample(102); s12.sample(100); - - prepare(); - - if (text) { - Text out(cout); - out.descriptions = descriptions; - out(); - } - -#if USE_MYSQL - if (!mysql_name.empty()) { - MySql out; - out.connect(mysql_host, mysql_db, mysql_user, mysql_passwd, "test", - mysql_name, "test"); - out(); - } -#endif - - return 0; } diff -r 9253d58fb4aa -r 4073cc899399 src/unittest/stattest.i --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/unittest/stattest.i Tue Dec 21 08:28:34 2010 -0800 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010 The Hewlett-Packard Development Company + * 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: Nathan Binkert + */ + +%module(package="m5.internal") stattest + +%inline %{ +extern void stattest_init(); +extern void stattest_run(); +%} diff -r 9253d58fb4aa -r 4073cc899399 src/unittest/stattestmain.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/unittest/stattestmain.py Tue Dec 21 08:28:34 2010 -0800 @@ -0,0 +1,19 @@ +def main(): + from m5.internal.stattest import stattest_init, stattest_run + import m5.stats + + stattest_init() + + # Initialize the global statistics + m5.stats.initSimStats() + m5.stats.initText("cout") + + # We're done registering statistics. Enable the stats package now. + m5.stats.enable() + + # Reset to put the stats in a consistent state. + m5.stats.reset() + + stattest_run() + + m5.stats.dump()