unittest: Add unit tests to the scons framework.

Also fix the unit tests so they actually compile correctly.
This commit is contained in:
Nathan Binkert 2008-10-02 11:27:01 -07:00
parent 52493b2720
commit b25755993b
9 changed files with 92 additions and 142 deletions

View file

@ -144,12 +144,26 @@ def SwigSource(package, source):
val = source,package
swig_sources.append(val)
unit_tests = []
def UnitTest(target, sources):
if not isinstance(sources, (list, tuple)):
sources = [ sources ]
srcs = []
for source in sources:
if not isinstance(source, SCons.Node.FS.File):
source = File(source)
srcs.append(source)
unit_tests.append((target, srcs))
# Children should have access
Export('Source')
Export('BinSource')
Export('PySource')
Export('SimObject')
Export('SwigSource')
Export('UnitTest')
########################################################################
#
@ -962,6 +976,10 @@ def makeEnv(label, objsfx, strip = False, **kwargs):
m5lib = newEnv.Library('m5_' + label,
make_objs(cc_lib_sources, newEnv) + swig_objs)
for target, sources in unit_tests:
objs = [ newEnv.StaticObject(s) for s in sources ]
newEnv.Program("unittest/%s.%s" % (target, label), objs + m5lib)
# Now link a stub with main() and the library.
exe = 'm5.' + label # final executable
objects = [newEnv.Object(s) for s in cc_bin_sources] + m5lib

View file

@ -1,101 +0,0 @@
# Copyright (c) 2006-2007 The Regents of The University of Michigan
# 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
# Steve Reinhardt
CC?= gcc
CXX?= g++
PYTHON?=/usr/bin/env python
CURDIR?= $(shell /bin/pwd)
SRCDIR?= $(CURDIR)/..
CCFLAGS= -g -O0 -MMD -I. -I$(SRCDIR) -I- -DTRACING_ON=0
MYSQL= -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient
VPATH=$(SRCDIR):$(CURDIR)
default:
@echo "You must specify a target"
base/traceflags.cc base/traceflags.hh: $(SRCDIR)/base/traceflags.py
mkdir -p base; \
cd base; \
$(PYTHON) $<
bitvectest: unittest/bitvectest.cc
$(CXX) $(CCFLAGS) -o $@ $^
circletest: unittest/circletest.cc base/circlebuf.cc
$(CXX) $(CCFLAGS) -o $@ $^
cprintftest: unittest/cprintftest.cc base/cprintf.cc
$(CXX) $(CCFLAGS) -o $@ $^
cprintftime: unittest/cprintftime.cc base/cprintf.cc
$(CXX) $(CCFLAGS) -o $@ $^
initest: unittest/initest.cc base/str.cc base/inifile.cc base/cprintf.cc
$(CXX) $(CCFLAGS) -o $@ $^
lrutest: unittest/lru_test.cc
$(CXX) $(CCFLAGS) -o $@ $^
nmtest: unittest/nmtest.cc base/output.cc base/hostinfo.cc base/cprintf.cc base/misc.cc base/loader/object_file.cc base/loader/symtab.cc base/misc.cc base/str.cc base/loader/aout_object.cc base/loader/ecoff_object.cc base/loader/elf_object.cc
$(CXX) $(CCFLAGS) -I/n/ziff/z/binkertn/build/work/ALPHA_FS -lelf -o $@ $^
offtest: unittest/offtest.cc
$(CXX) $(CCFLAGS) -o $@ $^
rangetest: unittest/rangetest.cc base/range.cc base/str.cc
$(CXX) $(CCFLAGS) -o $@ $^
STATTEST+= base/cprintf.cc base/hostinfo.cc base/misc.cc base/mysql.cc
STATTEST+= base/python.cc base/str.cc base/time.cc
STATTEST+= base/statistics.cc base/stats/mysql.cc base/stats/python.cc
STATTEST+= base/stats/statdb.cc base/stats/text.cc base/stats/visit.cc
STATTEST+= unittest/stattest.cc
stattest: $(STATTEST)
$(CXX) $(CCFLAGS) $(MYSQL) -o $@ $^
strnumtest: unittest/strnumtest.cc base/str.cc
$(CXX) $(CCFLAGS) -o $@ $^
symtest: unittest/symtest.cc base/misc.cc base/symtab.cc base/str.cc
$(CXX) $(CCFLAGS) -o $@ $^
tokentest: unittest/tokentest.cc base/str.cc
$(CXX) $(CCFLAGS) -o $@ $^
TRACE+=unittest/tracetest.cc base/trace.cc base/trace_flags.cc base/cprintf.cc
TRACE+=base/str.cc base/misc.cc
tracetest: $(TRACE)
$(CXX) $(CCFLAGS) -o $@ $^
clean:
@rm -rf *test *~ .#* *.core core base
.PHONY: clean

48
src/unittest/SConscript Normal file
View file

@ -0,0 +1,48 @@
# -*- mode:python -*-
# Copyright (c) 2004-2005 The Regents of The University of Michigan
# 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
Import('*')
UnitTest('bitvectest', 'bitvectest.cc')
UnitTest('circletest', 'circletest.cc')
UnitTest('cprintftest', 'cprintftest.cc')
UnitTest('cprintftime', 'cprintftest.cc')
UnitTest('initest', 'initest.cc')
UnitTest('lrutest', 'lru_test.cc')
UnitTest('nmtest', 'nmtest.cc')
UnitTest('offtest', 'offtest.cc')
UnitTest('rangetest', 'rangetest.cc')
UnitTest('rangemaptest', 'rangemaptest.cc')
UnitTest('rangemultimaptest', 'rangemultimaptest.cc')
UnitTest('stattest', 'stattest.cc')
UnitTest('strnumtest', 'strnumtest.cc')
UnitTest('symtest', 'symtest.cc')
UnitTest('tokentest', 'tokentest.cc')
UnitTest('tracetest', 'tracetest.cc')

View file

@ -28,10 +28,11 @@
* Authors: Nathan Binkert
*/
#include <iostream.h>
#include <iostream>
#include <vector>
using namespace std;
int
main()
{

View file

@ -29,12 +29,13 @@
*/
#include <fcntl.h>
#include <iostream.h>
#include <unistd.h>
#include <iostream>
#include "base/circlebuf.hh"
char *strings[] = {
const char *strings[] = {
"This is the first test\n",
"he went with his woman to the store\n",
"the man with the bat hit the woman with the hat\n",

View file

@ -68,32 +68,14 @@ main(int argc, char *argv[])
progname = argv[0];
vector<char *> cppArgs;
vector<char *> cpp_options;
cpp_options.reserve(argc * 2);
for (int i = 1; i < argc; ++i) {
char *arg_str = argv[i];
// if arg starts with '-', parse as option,
// else treat it as a configuration file name and load it
if (arg_str[0] == '-') {
// switch on second char
switch (arg_str[1]) {
case 'D':
case 'U':
case 'I':
// cpp options: record & pass to cpp. Note that these
// cannot have spaces, i.e., '-Dname=val' is OK, but
// '-D name=val' is not. I don't consider this a
// problem, since even though gnu cpp accepts the
// latter, other cpp implementations do not (Tru64,
// for one).
cppArgs.push_back(arg_str);
break;
case '-':
// command-line configuration parameter:
// '--<section>:<parameter>=<value>'
@ -115,7 +97,7 @@ main(int argc, char *argv[])
else {
// no '-', treat as config file name
if (!simConfigDB.loadCPP(arg_str, cppArgs)) {
if (!simConfigDB.load(arg_str)) {
cprintf("Error processing file %s\n", arg_str);
exit(1);
}

View file

@ -38,9 +38,6 @@
#include "base/str.hh"
using namespace std;
Tick curTick;
ostream *outputStream = &cout;
int
main(int argc, char *argv[])

View file

@ -30,9 +30,7 @@
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
#include <unistd.h>
#include "base/cprintf.hh"
#include "base/misc.hh"
@ -44,9 +42,6 @@
using namespace std;
using namespace Stats;
Tick curTick = 0;
Tick ticksPerSecond = ULL(2000000000);
Scalar<> s1;
Scalar<> s2;
Average<> s3;
@ -72,8 +67,6 @@ Value f5;
Formula f6;
Formula f7;
ostream *outputStream = &cout;
double
testfunc()
{
@ -85,7 +78,7 @@ class TestClass {
double operator()() { return 9.7; }
};
char *progname = "";
const char *progname = "";
void
usage()
@ -101,14 +94,18 @@ main(int argc, char *argv[])
bool descriptions = false;
bool compat = 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, "cdh:P:p:s:tu:")) != -1) {
while ((c = getopt(argc, argv, "cD:dh:P:p:s:tu:")) != -1) {
switch (c) {
case 'c':
compat = true;
@ -116,6 +113,13 @@ main(int argc, char *argv[])
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;
@ -125,12 +129,10 @@ main(int argc, char *argv[])
case 's':
mysql_name = optarg;
break;
case 't':
text = true;
break;
case 'u':
mysql_user = optarg;
break;
#endif
default:
usage();
}
@ -545,12 +547,14 @@ main(int argc, char *argv[])
out();
}
#if USE_MYSQL
if (!mysql_name.empty()) {
MySql out;
out.connect(mysql_host, mysql_user, mysql_passwd, "m5stats",
out.connect(mysql_host, mysql_db, mysql_user, mysql_passwd, "test",
mysql_name, "test");
out();
}
#endif
return 0;
}

View file

@ -28,12 +28,12 @@
* Authors: Nathan Binkert
*/
#include <iostream.h>
#include <iostream>
#include "base/str.hh"
#include "base/loader/symtab.hh"
Tick curTick = 0;
using namespace std;
void
usage(const char *progname)