Adding gem5 source to svn.
git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1819 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
59
simulators/gem5/src/unittest/SConscript
Normal file
59
simulators/gem5/src/unittest/SConscript
Normal file
@ -0,0 +1,59 @@
|
||||
# -*- 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('*')
|
||||
|
||||
if env['TARGET_ISA'] == 'no':
|
||||
Return()
|
||||
|
||||
Source('unittest.cc')
|
||||
|
||||
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('refcnttest', 'refcnttest.cc')
|
||||
UnitTest('strnumtest', 'strnumtest.cc')
|
||||
UnitTest('trietest', 'trietest.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, main=True)
|
||||
|
||||
UnitTest('symtest', 'symtest.cc')
|
||||
UnitTest('tokentest', 'tokentest.cc')
|
||||
UnitTest('tracetest', 'tracetest.cc')
|
||||
69
simulators/gem5/src/unittest/bitvectest.cc
Normal file
69
simulators/gem5/src/unittest/bitvectest.cc
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2002-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
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
vector<bool> v1(100);
|
||||
|
||||
v1[0] = true;
|
||||
v1.resize(500);
|
||||
v1[100] = true;
|
||||
v1[499] = true;
|
||||
v1.resize(10000);
|
||||
v1[9999] = true;
|
||||
|
||||
cout << "v1.size() = " << v1.size() << "\n";
|
||||
for (int i = 0; i < v1.size(); i++)
|
||||
if (v1[i])
|
||||
cout << "v1[" << i << "] = " << v1[i] << "\n";
|
||||
|
||||
cout << "\n";
|
||||
|
||||
vector<bool> v2 = v1;
|
||||
|
||||
for (int i = 0; i < v2.size(); i++)
|
||||
if (v2[i])
|
||||
cout << "v2[" << i << "] = " << v2[i] << "\n";
|
||||
|
||||
cout << "v1 " << ((v1 == v2) ? "==" : "!=") << " v2" << "\n";
|
||||
v2[8583] = true;
|
||||
cout << "v1 " << ((v1 == v2) ? "==" : "!=") << " v2" << "\n";
|
||||
v1[8583] = true;
|
||||
cout << "v1 " << ((v1 == v2) ? "==" : "!=") << " v2" << "\n";
|
||||
v1.resize(100000);
|
||||
cout << "v1 " << ((v1 == v2) ? "==" : "!=") << " v2" << "\n";
|
||||
cout << flush;
|
||||
}
|
||||
76
simulators/gem5/src/unittest/circletest.cc
Normal file
76
simulators/gem5/src/unittest/circletest.cc
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2002-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
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "base/circlebuf.hh"
|
||||
|
||||
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",
|
||||
"that that is is that that was\n",
|
||||
"sue sells sea shells by the sea shore\n",
|
||||
"go to the store and buy me some milk and bread\n",
|
||||
"the friendly flight attendants spoke soothingly to "
|
||||
"the frightened passengers in their native languages\n"
|
||||
};
|
||||
|
||||
const int num_strings = sizeof(strings) / sizeof(char *);
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
CircleBuf buf(1024);
|
||||
|
||||
for (int count = 0; count < 100; count++)
|
||||
buf.write(strings[count % num_strings]);
|
||||
buf.read(STDOUT_FILENO);
|
||||
write(STDOUT_FILENO, "<\n", 2);
|
||||
|
||||
for (int count = 0; count < 100; count++)
|
||||
buf.write(strings[count % num_strings]);
|
||||
buf.read(STDOUT_FILENO, 100);
|
||||
write(STDOUT_FILENO, "<\n", 2);
|
||||
|
||||
buf.flush();
|
||||
buf.write("asdfa asdf asd fasdf asdf\n");
|
||||
buf.write("");
|
||||
buf.write("");
|
||||
buf.write("");
|
||||
buf.write("");
|
||||
buf.write("");
|
||||
buf.write("");
|
||||
buf.read(STDOUT_FILENO);
|
||||
write(STDOUT_FILENO, "<\n", 2);
|
||||
}
|
||||
179
simulators/gem5/src/unittest/cprintftest.cc
Normal file
179
simulators/gem5/src/unittest/cprintftest.cc
Normal file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (c) 2002-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
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "base/cprintf.hh"
|
||||
#include "base/misc.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
char foo[] = "foo";
|
||||
cprintf("%s\n", foo);
|
||||
|
||||
string _bar = "asdfkhasdlkfjhasdlkfhjalksdjfhalksdjhfalksdjfhalksdjhf";
|
||||
int length = 11;
|
||||
char bar[length + 1];
|
||||
bar[length] = 0;
|
||||
|
||||
memcpy(bar, _bar.c_str(), length);
|
||||
warn("%s\n", bar);
|
||||
|
||||
cprintf("%d\n", 'A');
|
||||
cprintf("%shits%%s + %smisses%%s\n", "test", "test");
|
||||
cprintf("%%s%-10s %c he went home \'\"%d %#o %#x %1.5f %1.2E\n",
|
||||
"hello", 'A', 1, 0xff, 0xfffffffffffffULL, 3.141592653589, 1.1e10);
|
||||
|
||||
cprintf("another test\n");
|
||||
|
||||
stringstream buffer;
|
||||
ccprintf(buffer, "%-10s %c he home \'\"%d %#o %#x %1.5f %1.2E\n",
|
||||
"hello", 'A', 1, 0xff, 0xfffffffffffffULL, 3.14159265, 1.1e10);
|
||||
|
||||
double f = 314159.26535897932384;
|
||||
|
||||
#define ctest(x, y) printf(x, y); cprintf(x, y); cprintf("\n");
|
||||
ctest("%1.8f\n", f);
|
||||
ctest("%2.8f\n", f);
|
||||
ctest("%3.8f\n", f);
|
||||
ctest("%4.8f\n", f);
|
||||
ctest("%5.8f\n", f);
|
||||
ctest("%6.8f\n", f);
|
||||
ctest("%12.8f\n", f);
|
||||
ctest("%1000.8f\n", f);
|
||||
ctest("%1.0f\n", f);
|
||||
ctest("%1.1f\n", f);
|
||||
ctest("%1.2f\n", f);
|
||||
ctest("%1.3f\n", f);
|
||||
ctest("%1.4f\n", f);
|
||||
ctest("%1.5f\n", f);
|
||||
ctest("%1.6f\n", f);
|
||||
ctest("%1.7f\n", f);
|
||||
ctest("%1.8f\n", f);
|
||||
ctest("%1.9f\n", f);
|
||||
ctest("%1.10f\n", f);
|
||||
ctest("%1.11f\n", f);
|
||||
ctest("%1.12f\n", f);
|
||||
ctest("%1.13f\n", f);
|
||||
ctest("%1.14f\n", f);
|
||||
ctest("%1.15f\n", f);
|
||||
ctest("%1.16f\n", f);
|
||||
ctest("%1.17f\n", f);
|
||||
ctest("%1.18f\n", f);
|
||||
|
||||
cout << "foo\n";
|
||||
|
||||
f = 0.00000026535897932384;
|
||||
ctest("%1.8f\n", f);
|
||||
ctest("%2.8f\n", f);
|
||||
ctest("%3.8f\n", f);
|
||||
ctest("%4.8f\n", f);
|
||||
ctest("%5.8f\n", f);
|
||||
ctest("%6.8f\n", f);
|
||||
ctest("%12.8f\n", f);
|
||||
ctest("%1.0f\n", f);
|
||||
ctest("%1.1f\n", f);
|
||||
ctest("%1.2f\n", f);
|
||||
ctest("%1.3f\n", f);
|
||||
ctest("%1.4f\n", f);
|
||||
ctest("%1.5f\n", f);
|
||||
ctest("%1.6f\n", f);
|
||||
ctest("%1.7f\n", f);
|
||||
ctest("%1.8f\n", f);
|
||||
ctest("%1.9f\n", f);
|
||||
ctest("%1.10f\n", f);
|
||||
ctest("%1.11f\n", f);
|
||||
ctest("%1.12f\n", f);
|
||||
ctest("%1.13f\n", f);
|
||||
ctest("%1.14f\n", f);
|
||||
ctest("%1.15f\n", f);
|
||||
ctest("%1.16f\n", f);
|
||||
ctest("%1.17f\n", f);
|
||||
ctest("%1.18f\n", f);
|
||||
|
||||
f = 0.00000026535897932384;
|
||||
ctest("%1.8e\n", f);
|
||||
ctest("%2.8e\n", f);
|
||||
ctest("%3.8e\n", f);
|
||||
ctest("%4.8e\n", f);
|
||||
ctest("%5.8e\n", f);
|
||||
ctest("%6.8e\n", f);
|
||||
ctest("%12.8e\n", f);
|
||||
ctest("%1.0e\n", f);
|
||||
ctest("%1.1e\n", f);
|
||||
ctest("%1.2e\n", f);
|
||||
ctest("%1.3e\n", f);
|
||||
ctest("%1.4e\n", f);
|
||||
ctest("%1.5e\n", f);
|
||||
ctest("%1.6e\n", f);
|
||||
ctest("%1.7e\n", f);
|
||||
ctest("%1.8e\n", f);
|
||||
ctest("%1.9e\n", f);
|
||||
ctest("%1.10e\n", f);
|
||||
ctest("%1.11e\n", f);
|
||||
ctest("%1.12e\n", f);
|
||||
ctest("%1.13e\n", f);
|
||||
ctest("%1.14e\n", f);
|
||||
ctest("%1.15e\n", f);
|
||||
ctest("%1.16e\n", f);
|
||||
ctest("%1.17e\n", f);
|
||||
ctest("%1.18e\n", f);
|
||||
|
||||
cout << buffer.str();
|
||||
|
||||
cout.width(0);
|
||||
cout.precision(1);
|
||||
cout << f << "\n";
|
||||
|
||||
string foo1 = "string test";
|
||||
cprintf("%s\n", foo1);
|
||||
|
||||
stringstream foo2;
|
||||
foo2 << "stringstream test";
|
||||
cprintf("%s\n", foo2);
|
||||
|
||||
cprintf("%c %c\n", 'c', 65);
|
||||
|
||||
cout << '9' << endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
cprintf("%08.4f\n", 99.99);
|
||||
cprintf("%0*.*f\n", 8, 4, 99.99);
|
||||
cprintf("%07.*f\n", 4, 1.234);
|
||||
cprintf("%#0*x\n", 9, 123412);
|
||||
return 0;
|
||||
}
|
||||
90
simulators/gem5/src/unittest/cprintftime.cc
Normal file
90
simulators/gem5/src/unittest/cprintftime.cc
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2002-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
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "base/cprintf.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
volatile int stop = false;
|
||||
|
||||
void
|
||||
handle_alarm(int signal)
|
||||
{
|
||||
stop = true;
|
||||
}
|
||||
|
||||
void
|
||||
do_test(int seconds)
|
||||
{
|
||||
stop = false;
|
||||
alarm(seconds);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
stringstream result;
|
||||
int iterations = 0;
|
||||
|
||||
signal(SIGALRM, handle_alarm);
|
||||
|
||||
do_test(10);
|
||||
while (!stop) {
|
||||
stringstream result;
|
||||
ccprintf(result,
|
||||
"this is a %s of %d iterations %3.2f %#x\n",
|
||||
"test", iterations, 51.934, &result);
|
||||
|
||||
iterations += 1;
|
||||
}
|
||||
|
||||
cprintf("completed %d iterations of ccprintf in 10s, %f iterations/s\n",
|
||||
iterations, iterations / 10.0);
|
||||
|
||||
do_test(10);
|
||||
while (!stop) {
|
||||
char result[1024];
|
||||
sprintf(result,
|
||||
"this is a %s of %d iterations %3.2f %#x\n",
|
||||
"test", iterations, 51.934, &result);
|
||||
|
||||
iterations += 1;
|
||||
}
|
||||
|
||||
cprintf("completed %d iterations of sprintf in 10s, %f iterations/s\n",
|
||||
iterations, iterations / 10.0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
9
simulators/gem5/src/unittest/foo.ini
Normal file
9
simulators/gem5/src/unittest/foo.ini
Normal file
@ -0,0 +1,9 @@
|
||||
[Foo]
|
||||
Foo1=89
|
||||
Foo2=384
|
||||
|
||||
[General]
|
||||
Test3=89
|
||||
|
||||
[Junk]
|
||||
Test4+=mia
|
||||
74
simulators/gem5/src/unittest/genini.py
Executable file
74
simulators/gem5/src/unittest/genini.py
Executable file
@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) 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 getopt, os, os.path, sys
|
||||
from os.path import join as joinpath, realpath
|
||||
|
||||
mypath = sys.path[0]
|
||||
sys.path.append(joinpath(mypath, '..'))
|
||||
sys.path.append(joinpath(mypath, '../python'))
|
||||
sys.path.append(joinpath(mypath, '../util/pbs'))
|
||||
|
||||
pathlist = [ '.' ]
|
||||
|
||||
m5_build_env = {}
|
||||
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], '-E:I:')
|
||||
for opt,arg in opts:
|
||||
if opt == '-E':
|
||||
offset = arg.find('=')
|
||||
if offset == -1:
|
||||
name = arg
|
||||
value = 'True'
|
||||
else:
|
||||
name = arg[:offset]
|
||||
value = arg[offset+1:]
|
||||
os.environ[name] = value
|
||||
m5_build_env[name] = value
|
||||
if opt == '-I':
|
||||
pathlist.append(arg)
|
||||
except getopt.GetoptError:
|
||||
sys.exit('Improper Usage')
|
||||
|
||||
import __main__
|
||||
__main__.m5_build_env = m5_build_env
|
||||
|
||||
from m5 import *
|
||||
|
||||
for path in pathlist:
|
||||
AddToPath(path)
|
||||
|
||||
for arg in args:
|
||||
m5execfile(arg, globals())
|
||||
|
||||
if globals().has_key('root') and isinstance(root, Root):
|
||||
instantiate(root)
|
||||
else:
|
||||
print "Instantiation skipped: no root object found."
|
||||
127
simulators/gem5/src/unittest/initest.cc
Normal file
127
simulators/gem5/src/unittest/initest.cc
Normal file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2002-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
|
||||
* Steve Reinhardt
|
||||
*/
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/cprintf.hh"
|
||||
#include "base/inifile.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
char *progname;
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
cout << "Usage: " << progname << " <ini file>\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#if 0
|
||||
char *defines = getenv("CONFIG_DEFINES");
|
||||
if (defines) {
|
||||
char *c = defines;
|
||||
while ((c = strchr(c, ' ')) != NULL) {
|
||||
*c++ = '\0';
|
||||
count++;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
IniFile simConfigDB;
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
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 '-':
|
||||
// command-line configuration parameter:
|
||||
// '--<section>:<parameter>=<value>'
|
||||
|
||||
if (!simConfigDB.add(arg_str + 2)) {
|
||||
// parse error
|
||||
ccprintf(cerr,
|
||||
"Could not parse configuration argument '%s'\n"
|
||||
"Expecting --<section>:<parameter>=<value>\n",
|
||||
arg_str);
|
||||
exit(0);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// no '-', treat as config file name
|
||||
|
||||
if (!simConfigDB.load(arg_str)) {
|
||||
cprintf("Error processing file %s\n", arg_str);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string value;
|
||||
|
||||
#define FIND(C, E) \
|
||||
if (simConfigDB.find(C, E, value)) \
|
||||
cout << ">" << value << "<\n"; \
|
||||
else \
|
||||
cout << "Not Found!\n"
|
||||
|
||||
FIND("General", "Test2");
|
||||
FIND("Junk", "Test3");
|
||||
FIND("Junk", "Test4");
|
||||
FIND("General", "Test1");
|
||||
FIND("Junk2", "test3");
|
||||
FIND("General", "Test3");
|
||||
|
||||
cout << "\n";
|
||||
|
||||
simConfigDB.dump();
|
||||
|
||||
return 0;
|
||||
}
|
||||
82
simulators/gem5/src/unittest/nmtest.cc
Normal file
82
simulators/gem5/src/unittest/nmtest.cc
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2002-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
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/loader/object_file.hh"
|
||||
#include "base/loader/symtab.hh"
|
||||
#include "base/misc.hh"
|
||||
#include "base/str.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2 && argc != 3)
|
||||
panic("usage: %s <filename> <symbol>\n", argv[0]);
|
||||
|
||||
ObjectFile *obj = createObjectFile(argv[1]);
|
||||
if (!obj)
|
||||
panic("file not found\n");
|
||||
|
||||
SymbolTable symtab;
|
||||
obj->loadGlobalSymbols(&symtab);
|
||||
obj->loadLocalSymbols(&symtab);
|
||||
|
||||
if (argc == 2) {
|
||||
SymbolTable::ATable::const_iterator i = symtab.getAddrTable().begin();
|
||||
SymbolTable::ATable::const_iterator end = symtab.getAddrTable().end();
|
||||
while (i != end) {
|
||||
cprintf("%#x %s\n", i->first, i->second);
|
||||
++i;
|
||||
}
|
||||
} else {
|
||||
string symbol = argv[2];
|
||||
Addr address;
|
||||
|
||||
if (symbol[0] == '0' && symbol[1] == 'x') {
|
||||
if (to_number(symbol, address) &&
|
||||
symtab.findSymbol(address, symbol))
|
||||
cprintf("address = %#x, symbol = %s\n", address, symbol);
|
||||
else
|
||||
cprintf("address = %#x was not found\n", address);
|
||||
} else {
|
||||
if (symtab.findAddress(symbol, address))
|
||||
cprintf("symbol = %s address = %#x\n", symbol, address);
|
||||
else
|
||||
cprintf("symbol = %s was not found\n", symbol);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
76
simulators/gem5/src/unittest/rangemaptest.cc
Normal file
76
simulators/gem5/src/unittest/rangemaptest.cc
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2006 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: Ali Saidi
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#include "base/range_map.hh"
|
||||
#include "base/types.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
range_map<Addr,int> r;
|
||||
|
||||
range_map<Addr,int>::iterator i;
|
||||
|
||||
i = r.insert(RangeIn<Addr>(10,40),5);
|
||||
assert(i != r.end());
|
||||
i = r.insert(RangeIn<Addr>(60,90),3);
|
||||
assert(i != r.end());
|
||||
|
||||
i = r.find(RangeIn(20,30));
|
||||
assert(i != r.end());
|
||||
cout << i->first << " " << i->second << endl;
|
||||
|
||||
i = r.find(RangeIn(55,55));
|
||||
assert(i == r.end());
|
||||
|
||||
i = r.insert(RangeIn<Addr>(0,12),1);
|
||||
assert(i == r.end());
|
||||
|
||||
i = r.insert(RangeIn<Addr>(0,9),1);
|
||||
assert(i != r.end());
|
||||
|
||||
i = r.find(RangeIn(20,30));
|
||||
assert(i != r.end());
|
||||
cout << i->first << " " << i->second << endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
80
simulators/gem5/src/unittest/rangemultimaptest.cc
Normal file
80
simulators/gem5/src/unittest/rangemultimaptest.cc
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2006 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: Ali Saidi
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#include "base/range_map.hh"
|
||||
#include "base/types.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
typedef range_multimap<Addr, int> multimap_t;
|
||||
|
||||
multimap_t r;
|
||||
multimap_t::iterator i;
|
||||
std::pair<multimap_t::iterator, multimap_t::iterator> jk;
|
||||
|
||||
i = r.insert(RangeIn<Addr>(10,40),5);
|
||||
assert(i != r.end());
|
||||
i = r.insert(RangeIn<Addr>(10,40),6);
|
||||
assert(i != r.end());
|
||||
i = r.insert(RangeIn<Addr>(60,90),3);
|
||||
assert(i != r.end());
|
||||
|
||||
jk = r.find(RangeIn(20,30));
|
||||
assert(jk.first != r.end());
|
||||
cout << jk.first->first << " " << jk.first->second << endl;
|
||||
cout << jk.second->first << " " << jk.second->second << endl;
|
||||
|
||||
i = r.insert(RangeIn<Addr>(0,3),5);
|
||||
assert(i != r.end());
|
||||
|
||||
for( i = r.begin(); i != r.end(); i++)
|
||||
cout << i->first << " " << i->second << endl;
|
||||
|
||||
jk = r.find(RangeIn(20,30));
|
||||
assert(jk.first != r.end());
|
||||
cout << jk.first->first << " " << jk.first->second << endl;
|
||||
cout << jk.second->first << " " << jk.second->second << endl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
77
simulators/gem5/src/unittest/rangetest.cc
Normal file
77
simulators/gem5/src/unittest/rangetest.cc
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2002-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
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "base/range.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
Range<int> r1(make_pair(9, 28));
|
||||
Range<unsigned> r2("0x1000:+0x100");
|
||||
|
||||
cout << r1 << "\n"
|
||||
<< r2 << "\n";
|
||||
|
||||
#define RANGETEST(X, C, Y) \
|
||||
cout << X << " "#C" " << Y << " => " << \
|
||||
((X C Y) ? "true" : "false") << "\n"
|
||||
|
||||
#define TESTEM(X, Y) do { \
|
||||
RANGETEST(X, < , Y); \
|
||||
RANGETEST(X, <=, Y); \
|
||||
RANGETEST(X, > , Y); \
|
||||
RANGETEST(X, >=, Y); \
|
||||
RANGETEST(X, ==, Y); \
|
||||
RANGETEST(X, !=, Y); \
|
||||
RANGETEST(Y, < , X); \
|
||||
RANGETEST(Y, <=, X); \
|
||||
RANGETEST(Y, > , X); \
|
||||
RANGETEST(Y, >=, X); \
|
||||
RANGETEST(Y, ==, X); \
|
||||
RANGETEST(Y, !=, X); \
|
||||
} while (0)
|
||||
|
||||
TESTEM(8, r1);
|
||||
TESTEM(9, r1);
|
||||
TESTEM(27, r1);
|
||||
TESTEM(28, r1);
|
||||
|
||||
TESTEM(0x0fff, r2);
|
||||
TESTEM(0x1000, r2);
|
||||
TESTEM(0x10ff, r2);
|
||||
TESTEM(0x1100, r2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
194
simulators/gem5/src/unittest/refcnttest.cc
Normal file
194
simulators/gem5/src/unittest/refcnttest.cc
Normal file
@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (c) 2010 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: Gabe Black
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
|
||||
#include "base/cprintf.hh"
|
||||
#include "base/refcnt.hh"
|
||||
#include "unittest/unittest.hh"
|
||||
|
||||
using namespace std;
|
||||
using UnitTest::setCase;
|
||||
|
||||
namespace {
|
||||
|
||||
bool printNewDel = false;
|
||||
|
||||
class TestRC;
|
||||
typedef list<TestRC *> LiveList;
|
||||
LiveList liveList;
|
||||
|
||||
int
|
||||
live()
|
||||
{
|
||||
return liveList.size();
|
||||
}
|
||||
|
||||
int
|
||||
liveChange()
|
||||
{
|
||||
static int oldLive = 0;
|
||||
int newLive = live();
|
||||
int diff = newLive - oldLive;
|
||||
oldLive = newLive;
|
||||
return diff;
|
||||
}
|
||||
|
||||
class TestRC : public RefCounted
|
||||
{
|
||||
protected:
|
||||
const char *_tag;
|
||||
LiveList::iterator liveIt;
|
||||
|
||||
public:
|
||||
TestRC(const char *newTag) : _tag(newTag)
|
||||
{
|
||||
if (printNewDel)
|
||||
cprintf(" Creating object \"%s\"\n", _tag);
|
||||
liveList.push_front(this);
|
||||
liveIt = liveList.begin();
|
||||
}
|
||||
|
||||
~TestRC()
|
||||
{
|
||||
if (printNewDel)
|
||||
cprintf(" Destroying object \"%s\"\n", _tag);
|
||||
liveList.erase(liveIt);
|
||||
}
|
||||
|
||||
const char *
|
||||
tag()
|
||||
{
|
||||
return _tag;
|
||||
}
|
||||
|
||||
int testVal;
|
||||
};
|
||||
|
||||
typedef RefCountingPtr<TestRC> Ptr;
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
assert(live() == 0);
|
||||
assert(liveChange() == 0);
|
||||
|
||||
// Create an empty Ptr and verify it's data pointer is NULL.
|
||||
setCase("NULL check");
|
||||
Ptr nullCheck;
|
||||
EXPECT_EQ(nullCheck.get(), NULL);
|
||||
|
||||
EXPECT_EQ(liveChange(), 0);
|
||||
|
||||
// Construct a Ptr from a TestRC pointer.
|
||||
setCase("construction from pointer");
|
||||
Ptr constFromPointer = new TestRC("construction from pointer");
|
||||
|
||||
EXPECT_EQ(liveChange(), 1);
|
||||
|
||||
// Construct a Ptr from an existing Ptr.
|
||||
setCase("construction from a Ptr");
|
||||
Ptr constFromPtr = constFromPointer;
|
||||
|
||||
EXPECT_EQ(liveChange(), 0);
|
||||
|
||||
// Test a Ptr being destroyed.
|
||||
setCase("destroying a Ptr");
|
||||
Ptr *ptrPtr = new Ptr(new TestRC("destroying a ptr"));
|
||||
EXPECT_EQ(liveChange(), 1);
|
||||
delete ptrPtr;
|
||||
EXPECT_EQ(liveChange(), -1);
|
||||
|
||||
// Test assignment from a pointer and from a Ptr.
|
||||
setCase("assignment operators");
|
||||
Ptr assignmentTarget;
|
||||
TestRC *assignmentSourcePointer = new TestRC("assignment source 1");
|
||||
EXPECT_EQ(liveChange(), 1);
|
||||
assignmentTarget = assignmentSourcePointer;
|
||||
EXPECT_EQ(liveChange(), 0);
|
||||
assignmentTarget = NULL;
|
||||
EXPECT_EQ(liveChange(), -1);
|
||||
Ptr assignmentSourcePtr(new TestRC("assignment source 2"));
|
||||
EXPECT_EQ(liveChange(), 1);
|
||||
assignmentTarget = assignmentSourcePtr;
|
||||
EXPECT_EQ(liveChange(), 0);
|
||||
assignmentSourcePtr = NULL;
|
||||
EXPECT_EQ(liveChange(), 0);
|
||||
assignmentTarget = NULL;
|
||||
EXPECT_EQ(liveChange(), -1);
|
||||
|
||||
// Test access to members of the pointed to class and dereferencing.
|
||||
setCase("access to members");
|
||||
TestRC *accessTest = new TestRC("access test");
|
||||
Ptr accessTestPtr = accessTest;
|
||||
accessTest->testVal = 1;
|
||||
EXPECT_EQ(accessTestPtr->testVal, 1);
|
||||
EXPECT_EQ((*accessTestPtr).testVal, 1);
|
||||
accessTest->testVal = 2;
|
||||
EXPECT_EQ(accessTestPtr->testVal, 2);
|
||||
EXPECT_EQ((*accessTestPtr).testVal, 2);
|
||||
accessTestPtr->testVal = 3;
|
||||
EXPECT_EQ(accessTest->testVal, 3);
|
||||
(*accessTestPtr).testVal = 4;
|
||||
EXPECT_EQ(accessTest->testVal, 4);
|
||||
accessTestPtr = NULL;
|
||||
accessTest = NULL;
|
||||
EXPECT_EQ(liveChange(), 0);
|
||||
|
||||
// Test bool and ! operator overloads.
|
||||
setCase("conversion to bool and ! overload");
|
||||
Ptr boolTest = new TestRC("bool test");
|
||||
EXPECT_EQ(boolTest, true);
|
||||
EXPECT_EQ(!boolTest, false);
|
||||
boolTest = NULL;
|
||||
EXPECT_EQ(boolTest, false);
|
||||
EXPECT_EQ(!boolTest, true);
|
||||
EXPECT_EQ(liveChange(), 0);
|
||||
|
||||
// Test the equality operators.
|
||||
setCase("equality operators");
|
||||
TestRC *equalTestA = new TestRC("equal test a");
|
||||
Ptr equalTestAPtr = equalTestA;
|
||||
Ptr equalTestAPtr2 = equalTestA;
|
||||
TestRC *equalTestB = new TestRC("equal test b");
|
||||
Ptr equalTestBPtr = equalTestB;
|
||||
EXPECT_TRUE(equalTestA == equalTestAPtr);
|
||||
EXPECT_TRUE(equalTestAPtr == equalTestA);
|
||||
EXPECT_TRUE(equalTestAPtr == equalTestAPtr2);
|
||||
EXPECT_TRUE(equalTestA != equalTestBPtr);
|
||||
EXPECT_TRUE(equalTestAPtr != equalTestB);
|
||||
EXPECT_TRUE(equalTestAPtr != equalTestBPtr);
|
||||
|
||||
return UnitTest::printResults();
|
||||
}
|
||||
672
simulators/gem5/src/unittest/stattest.cc
Normal file
672
simulators/gem5/src/unittest/stattest.cc
Normal file
@ -0,0 +1,672 @@
|
||||
/*
|
||||
* Copyright (c) 2003-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
|
||||
*/
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "base/cprintf.hh"
|
||||
#include "base/misc.hh"
|
||||
#include "base/statistics.hh"
|
||||
#include "base/types.hh"
|
||||
#include "sim/core.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;
|
||||
|
||||
double
|
||||
testfunc()
|
||||
{
|
||||
return 9.8;
|
||||
}
|
||||
|
||||
class TestClass {
|
||||
public:
|
||||
double operator()() { return 9.7; }
|
||||
};
|
||||
|
||||
struct StatTest
|
||||
{
|
||||
Scalar s1;
|
||||
Scalar s2;
|
||||
Average s3;
|
||||
Scalar s4;
|
||||
Vector s5;
|
||||
Distribution s6;
|
||||
Vector s7;
|
||||
AverageVector s8;
|
||||
StandardDeviation s9;
|
||||
AverageDeviation s10;
|
||||
Scalar s11;
|
||||
Distribution s12;
|
||||
VectorDistribution s13;
|
||||
VectorStandardDeviation s14;
|
||||
VectorAverageDeviation s15;
|
||||
Vector2d s16;
|
||||
Value s17;
|
||||
Value s18;
|
||||
Histogram h01;
|
||||
Histogram h02;
|
||||
Histogram h03;
|
||||
Histogram h04;
|
||||
Histogram h05;
|
||||
Histogram h06;
|
||||
Histogram h07;
|
||||
Histogram h08;
|
||||
Histogram h09;
|
||||
Histogram h10;
|
||||
Histogram h11;
|
||||
Histogram h12;
|
||||
SparseHistogram sh1;
|
||||
|
||||
Vector s19;
|
||||
Vector s20;
|
||||
|
||||
Formula f1;
|
||||
Formula f2;
|
||||
Formula f3;
|
||||
Formula f4;
|
||||
Formula f5;
|
||||
Formula f6;
|
||||
|
||||
void run();
|
||||
void init();
|
||||
};
|
||||
|
||||
StatTest &
|
||||
__stattest()
|
||||
{
|
||||
static StatTest st;
|
||||
return st;
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
s1
|
||||
.name("Stat01")
|
||||
.desc("this is statistic 1")
|
||||
;
|
||||
|
||||
s2
|
||||
.name("Stat02")
|
||||
.desc("this is statistic 2")
|
||||
.prereq(s11)
|
||||
;
|
||||
|
||||
s3
|
||||
.name("Stat03")
|
||||
.desc("this is statistic 3")
|
||||
.prereq(f5)
|
||||
;
|
||||
|
||||
s4
|
||||
.name("Stat04")
|
||||
.desc("this is statistic 4")
|
||||
.prereq(s11)
|
||||
;
|
||||
|
||||
s5
|
||||
.init(5)
|
||||
.name("Stat05")
|
||||
.desc("this is statistic 5")
|
||||
.prereq(s11)
|
||||
.subname(0, "foo1")
|
||||
.subname(1, "foo2")
|
||||
.subname(2, "foo3")
|
||||
.subname(3, "foo4")
|
||||
.subname(4, "foo5")
|
||||
;
|
||||
|
||||
s6
|
||||
.init(1, 100, 13)
|
||||
.name("Stat06")
|
||||
.desc("this is statistic 6")
|
||||
.prereq(s11)
|
||||
;
|
||||
|
||||
s7
|
||||
.init(7)
|
||||
.name("Stat07")
|
||||
.desc("this is statistic 7")
|
||||
.precision(1)
|
||||
.flags(pdf | total)
|
||||
.prereq(s11)
|
||||
;
|
||||
|
||||
s8
|
||||
.init(10)
|
||||
.name("Stat08")
|
||||
.desc("this is statistic 8")
|
||||
.precision(2)
|
||||
.prereq(s11)
|
||||
.subname(4, "blarg")
|
||||
;
|
||||
|
||||
s9
|
||||
.name("Stat09")
|
||||
.desc("this is statistic 9")
|
||||
.precision(4)
|
||||
.prereq(s11)
|
||||
;
|
||||
|
||||
s10
|
||||
.name("Stat10")
|
||||
.desc("this is statistic 10")
|
||||
.prereq(s11)
|
||||
;
|
||||
|
||||
s12
|
||||
.init(1, 100, 13)
|
||||
.name("Stat12")
|
||||
.desc("this is statistic 12")
|
||||
;
|
||||
|
||||
s13
|
||||
.init(4, 0, 99, 10)
|
||||
.name("Stat13")
|
||||
.desc("this is statistic 13")
|
||||
;
|
||||
|
||||
s14
|
||||
.init(9)
|
||||
.name("Stat14")
|
||||
.desc("this is statistic 14")
|
||||
;
|
||||
|
||||
s15
|
||||
.init(10)
|
||||
.name("Stat15")
|
||||
.desc("this is statistic 15")
|
||||
;
|
||||
|
||||
s16
|
||||
.init(2, 9)
|
||||
.name("Stat16")
|
||||
.desc("this is statistic 16")
|
||||
.flags(total)
|
||||
.subname(0, "sub0")
|
||||
.subname(1, "sub1")
|
||||
.ysubname(0, "y0")
|
||||
.ysubname(1, "y1")
|
||||
;
|
||||
|
||||
s17
|
||||
.functor(testfunc)
|
||||
.name("Stat17")
|
||||
.desc("this is stat 17")
|
||||
;
|
||||
|
||||
TestClass testclass;
|
||||
s18
|
||||
.functor(testclass)
|
||||
.name("Stat18")
|
||||
.desc("this is stat 18")
|
||||
;
|
||||
|
||||
h01
|
||||
.init(11)
|
||||
.name("Histogram01")
|
||||
.desc("this is histogram 1")
|
||||
;
|
||||
|
||||
h02
|
||||
.init(10)
|
||||
.name("Histogram02")
|
||||
.desc("this is histogram 2")
|
||||
;
|
||||
|
||||
h03
|
||||
.init(11)
|
||||
.name("Histogram03")
|
||||
.desc("this is histogram 3")
|
||||
;
|
||||
|
||||
h04
|
||||
.init(10)
|
||||
.name("Histogram04")
|
||||
.desc("this is histogram 4")
|
||||
;
|
||||
|
||||
h05
|
||||
.init(11)
|
||||
.name("Histogram05")
|
||||
.desc("this is histogram 5")
|
||||
;
|
||||
|
||||
h06
|
||||
.init(10)
|
||||
.name("Histogram06")
|
||||
.desc("this is histogram 6")
|
||||
;
|
||||
|
||||
h07
|
||||
.init(11)
|
||||
.name("Histogram07")
|
||||
.desc("this is histogram 7")
|
||||
;
|
||||
|
||||
h08
|
||||
.init(10)
|
||||
.name("Histogram08")
|
||||
.desc("this is histogram 8")
|
||||
;
|
||||
|
||||
h09
|
||||
.init(11)
|
||||
.name("Histogram09")
|
||||
.desc("this is histogram 9")
|
||||
;
|
||||
|
||||
h10
|
||||
.init(10)
|
||||
.name("Histogram10")
|
||||
.desc("this is histogram 10")
|
||||
;
|
||||
|
||||
h11
|
||||
.init(11)
|
||||
.name("Histogram11")
|
||||
.desc("this is histogram 11")
|
||||
;
|
||||
|
||||
h12
|
||||
.init(10)
|
||||
.name("Histogram12")
|
||||
.desc("this is histogram 12")
|
||||
;
|
||||
|
||||
sh1
|
||||
.init(0)
|
||||
.name("SparseHistogram1")
|
||||
.desc("this is sparse histogram 1")
|
||||
;
|
||||
|
||||
f1
|
||||
.name("Formula1")
|
||||
.desc("this is formula 1")
|
||||
.prereq(s11)
|
||||
;
|
||||
|
||||
f2
|
||||
.name("Formula2")
|
||||
.desc("this is formula 2")
|
||||
.prereq(s11)
|
||||
.precision(1)
|
||||
;
|
||||
|
||||
f3
|
||||
.name("Formula3")
|
||||
.desc("this is formula 3")
|
||||
.prereq(s11)
|
||||
.subname(0, "bar1")
|
||||
.subname(1, "bar2")
|
||||
.subname(2, "bar3")
|
||||
.subname(3, "bar4")
|
||||
.subname(4, "bar5")
|
||||
;
|
||||
|
||||
f4
|
||||
.name("Formula4")
|
||||
.desc("this is formula 4")
|
||||
;
|
||||
|
||||
s19
|
||||
.init(2)
|
||||
.name("Stat19")
|
||||
.desc("this is statistic 19 for vector op testing")
|
||||
.flags(total | nozero | nonan)
|
||||
;
|
||||
s20
|
||||
.init(2)
|
||||
.name("Stat20")
|
||||
.desc("this is statistic 20 for vector op testing")
|
||||
.flags(total | nozero | nonan)
|
||||
;
|
||||
|
||||
f6
|
||||
.name("vector_op_test_formula")
|
||||
.desc("The total stat should equal 1")
|
||||
.flags(total |nozero |nonan)
|
||||
;
|
||||
|
||||
f1 = s1 + s2;
|
||||
f2 = (-s1) / (-s2) * (-s3 + ULL(100) + s4);
|
||||
f3 = sum(s5) * s7;
|
||||
f4 += constant(10.0);
|
||||
f4 += s5[3];
|
||||
f5 = constant(1);
|
||||
f6 = s19/s20;
|
||||
}
|
||||
|
||||
void
|
||||
StatTest::run()
|
||||
{
|
||||
s16[1][0] = 1;
|
||||
s16[0][1] = 3;
|
||||
s16[0][0] = 2;
|
||||
s16[1][1] = 9;
|
||||
s16[1][1] += 9;
|
||||
s16[1][8] += 8;
|
||||
s16[1][7] += 7;
|
||||
s16[1][6] += 6;
|
||||
s16[1][5] += 5;
|
||||
s16[1][4] += 4;
|
||||
|
||||
s11 = 1;
|
||||
s3 = 9;
|
||||
s8[3] = 9;
|
||||
s15[0].sample(1234);
|
||||
s15[1].sample(1234);
|
||||
s15[2].sample(1234);
|
||||
s15[3].sample(1234);
|
||||
s15[4].sample(1234);
|
||||
s15[5].sample(1234);
|
||||
s15[6].sample(1234);
|
||||
s15[7].sample(1234);
|
||||
s15[8].sample(1234);
|
||||
s15[9].sample(1234);
|
||||
|
||||
s10.sample(1000000000);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s10.sample(100000);
|
||||
s10.sample(100000);
|
||||
s10.sample(100000);
|
||||
s10.sample(100000);
|
||||
s10.sample(100000);
|
||||
s10.sample(100000);
|
||||
s10.sample(100000);
|
||||
s10.sample(100000);
|
||||
s10.sample(100000);
|
||||
s10.sample(100000);
|
||||
s10.sample(100000);
|
||||
s10.sample(100000);
|
||||
s10.sample(100000);
|
||||
s13[0].sample(12);
|
||||
s13[1].sample(29);
|
||||
s13[2].sample(12);
|
||||
s13[3].sample(29);
|
||||
s13[0].sample(42);
|
||||
s13[1].sample(29);
|
||||
s13[2].sample(42);
|
||||
s13[3].sample(32);
|
||||
s13[0].sample(52);
|
||||
s13[1].sample(49);
|
||||
s13[2].sample(42);
|
||||
s13[3].sample(25);
|
||||
s13[0].sample(32);
|
||||
s13[1].sample(49);
|
||||
s13[2].sample(22);
|
||||
s13[3].sample(49);
|
||||
s13[0].sample(62);
|
||||
s13[1].sample(99);
|
||||
s13[2].sample(72);
|
||||
s13[3].sample(23);
|
||||
s13[0].sample(52);
|
||||
s13[1].sample(78);
|
||||
s13[2].sample(69);
|
||||
s13[3].sample(49);
|
||||
|
||||
s14[0].sample(1234);
|
||||
s14[1].sample(4134);
|
||||
s14[4].sample(1213);
|
||||
s14[3].sample(1124);
|
||||
s14[2].sample(1243);
|
||||
s14[7].sample(1244);
|
||||
s14[4].sample(7234);
|
||||
s14[2].sample(9234);
|
||||
s14[3].sample(1764);
|
||||
s14[7].sample(1564);
|
||||
s14[3].sample(3234);
|
||||
s14[1].sample(2234);
|
||||
s14[5].sample(1234);
|
||||
s14[2].sample(4334);
|
||||
s14[2].sample(1234);
|
||||
s14[4].sample(4334);
|
||||
s14[6].sample(1234);
|
||||
s14[8].sample(8734);
|
||||
s14[1].sample(5234);
|
||||
s14[3].sample(8234);
|
||||
s14[7].sample(5234);
|
||||
s14[4].sample(4434);
|
||||
s14[3].sample(7234);
|
||||
s14[2].sample(1934);
|
||||
s14[1].sample(9234);
|
||||
s14[5].sample(5634);
|
||||
s14[3].sample(1264);
|
||||
s14[7].sample(5223);
|
||||
s14[0].sample(1234);
|
||||
s14[0].sample(5434);
|
||||
s14[3].sample(8634);
|
||||
s14[1].sample(1234);
|
||||
|
||||
|
||||
s15[0].sample(1234);
|
||||
s15[1].sample(4134);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s15[4].sample(1213);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s15[3].sample(1124);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s15[2].sample(1243);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s15[7].sample(1244);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s15[4].sample(7234);
|
||||
s15[2].sample(9234);
|
||||
s15[3].sample(1764);
|
||||
s15[7].sample(1564);
|
||||
s15[3].sample(3234);
|
||||
s15[1].sample(2234);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s15[5].sample(1234);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s15[9].sample(4334);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s15[2].sample(1234);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s15[4].sample(4334);
|
||||
s15[6].sample(1234);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s15[8].sample(8734);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s15[1].sample(5234);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s15[3].sample(8234);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s15[7].sample(5234);
|
||||
s15[4].sample(4434);
|
||||
s15[3].sample(7234);
|
||||
s15[2].sample(1934);
|
||||
s15[1].sample(9234);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s15[5].sample(5634);
|
||||
s15[3].sample(1264);
|
||||
s15[7].sample(5223);
|
||||
s15[0].sample(1234);
|
||||
s15[0].sample(5434);
|
||||
s15[3].sample(8634);
|
||||
curTick(curTick() + ULL(1000000));
|
||||
s15[1].sample(1234);
|
||||
|
||||
s4 = curTick();
|
||||
|
||||
s8[3] = 99999;
|
||||
|
||||
s3 = 12;
|
||||
s3++;
|
||||
curTick(curTick() + 9);
|
||||
|
||||
s1 = 9;
|
||||
s1 += 9;
|
||||
s1 -= 11;
|
||||
s1++;
|
||||
++s1;
|
||||
s1--;
|
||||
--s1;
|
||||
|
||||
s2 = 9;
|
||||
|
||||
s5[0] += 1;
|
||||
s5[1] += 2;
|
||||
s5[2] += 3;
|
||||
s5[3] += 4;
|
||||
s5[4] += 5;
|
||||
|
||||
s7[0] = 10;
|
||||
s7[1] = 20;
|
||||
s7[2] = 30;
|
||||
s7[3] = 40;
|
||||
s7[4] = 50;
|
||||
s7[5] = 60;
|
||||
s7[6] = 70;
|
||||
|
||||
s6.sample(0);
|
||||
s6.sample(1);
|
||||
s6.sample(2);
|
||||
s6.sample(3);
|
||||
s6.sample(4);
|
||||
s6.sample(5);
|
||||
s6.sample(6);
|
||||
s6.sample(7);
|
||||
s6.sample(8);
|
||||
s6.sample(9);
|
||||
|
||||
s6.sample(10);
|
||||
s6.sample(10);
|
||||
s6.sample(10);
|
||||
s6.sample(10);
|
||||
s6.sample(10);
|
||||
s6.sample(10);
|
||||
s6.sample(10);
|
||||
s6.sample(10);
|
||||
s6.sample(11);
|
||||
s6.sample(19);
|
||||
s6.sample(20);
|
||||
s6.sample(20);
|
||||
s6.sample(21);
|
||||
s6.sample(21);
|
||||
s6.sample(31);
|
||||
s6.sample(98);
|
||||
s6.sample(99);
|
||||
s6.sample(99);
|
||||
s6.sample(99);
|
||||
|
||||
s7[0] = 700;
|
||||
s7[1] = 600;
|
||||
s7[2] = 500;
|
||||
s7[3] = 400;
|
||||
s7[4] = 300;
|
||||
s7[5] = 200;
|
||||
s7[6] = 100;
|
||||
|
||||
s9.sample(100);
|
||||
s9.sample(100);
|
||||
s9.sample(100);
|
||||
s9.sample(100);
|
||||
s9.sample(10);
|
||||
s9.sample(10);
|
||||
s9.sample(10);
|
||||
s9.sample(10);
|
||||
s9.sample(10);
|
||||
|
||||
curTick(curTick() + 9);
|
||||
s4 = curTick();
|
||||
s6.sample(100);
|
||||
s6.sample(100);
|
||||
s6.sample(100);
|
||||
s6.sample(101);
|
||||
s6.sample(102);
|
||||
|
||||
s12.sample(100);
|
||||
for (int i = 0; i < 100; i++) {
|
||||
h01.sample(i);
|
||||
h02.sample(i);
|
||||
}
|
||||
|
||||
for (int i = -100; i < 100; i++) {
|
||||
h03.sample(i);
|
||||
h04.sample(i);
|
||||
}
|
||||
|
||||
for (int i = -100; i < 1000; i++) {
|
||||
h05.sample(i);
|
||||
h06.sample(i);
|
||||
}
|
||||
|
||||
for (int i = 100; i >= -1000; i--) {
|
||||
h07.sample(i);
|
||||
h08.sample(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i <= 1023; i++) {
|
||||
h09.sample(i);
|
||||
h10.sample(i);
|
||||
}
|
||||
|
||||
for (int i = -1024; i <= 1023; i++) {
|
||||
h11.sample(i);
|
||||
h12.sample(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
sh1.sample(random() % 10000);
|
||||
}
|
||||
|
||||
s19[0] = 1;
|
||||
s19[1] = 100000;
|
||||
s20[0] = 100000;
|
||||
s20[1] = 1;
|
||||
|
||||
}
|
||||
36
simulators/gem5/src/unittest/stattest.i
Normal file
36
simulators/gem5/src/unittest/stattest.i
Normal file
@ -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();
|
||||
%}
|
||||
19
simulators/gem5/src/unittest/stattestmain.py
Normal file
19
simulators/gem5/src/unittest/stattestmain.py
Normal file
@ -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()
|
||||
77
simulators/gem5/src/unittest/strnumtest.cc
Normal file
77
simulators/gem5/src/unittest/strnumtest.cc
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2002-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
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/str.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2) {
|
||||
cout << "Usage: " << argv[0] << " <number>\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
string s = argv[1];
|
||||
|
||||
#define OUTVAL(valtype, type) do { \
|
||||
valtype value; \
|
||||
cout << "TYPE = " #valtype "\n"; \
|
||||
if (to_number(s, value)) { \
|
||||
cout << "Number(" << s << ") = " << dec \
|
||||
<< (unsigned long long)(unsigned type)value << "\n" \
|
||||
<< "Number(" << s << ") = " << dec \
|
||||
<< (signed long long)(signed type)value << "\n" \
|
||||
<< "Number(" << s << ") = 0x" << hex \
|
||||
<< (unsigned long long)(unsigned type)value << "\n" \
|
||||
<< "Number(" << s << ") = 0" << oct \
|
||||
<< (unsigned long long)(unsigned type)value << "\n\n"; \
|
||||
} else \
|
||||
cout << "Number(" << s << ") is invalid\n\n"; \
|
||||
} while (0)
|
||||
|
||||
OUTVAL(signed long long, long long);
|
||||
OUTVAL(unsigned long long, long long);
|
||||
OUTVAL(signed long, long);
|
||||
OUTVAL(unsigned long, long);
|
||||
OUTVAL(signed int, int);
|
||||
OUTVAL(unsigned int, int);
|
||||
OUTVAL(signed short, short);
|
||||
OUTVAL(unsigned short, short);
|
||||
OUTVAL(signed char, char);
|
||||
OUTVAL(unsigned char, char);
|
||||
|
||||
return 0;
|
||||
}
|
||||
79
simulators/gem5/src/unittest/symtest.cc
Normal file
79
simulators/gem5/src/unittest/symtest.cc
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2002-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
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "base/loader/symtab.hh"
|
||||
#include "base/str.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void
|
||||
usage(const char *progname)
|
||||
{
|
||||
cout << "Usage: " << progname << " <symbol file> <symbol>" << endl;
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SymbolTable symtab;
|
||||
|
||||
if (argc != 3)
|
||||
usage(argv[0]);
|
||||
|
||||
if (!symtab.load(argv[1])) {
|
||||
cout << "could not load symbol file: " << argv[1] << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
string symbol = argv[2];
|
||||
Addr address;
|
||||
|
||||
if (!to_number(symbol, address)) {
|
||||
if (!symtab.findAddress(symbol, address)) {
|
||||
cout << "could not find symbol: " << symbol << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cout << symbol << " -> " << "0x" << hex << address << endl;
|
||||
} else {
|
||||
if (!symtab.findSymbol(address, symbol)) {
|
||||
cout << "could not find address: " << address << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
cout << "0x" << hex << address << " -> " << symbol<< endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
83
simulators/gem5/src/unittest/tokentest.cc
Normal file
83
simulators/gem5/src/unittest/tokentest.cc
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2002-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
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/str.hh"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
if (argc != 3) {
|
||||
cout << "Usage: " << argv[0] << " <string> <token>\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int i;
|
||||
string test = argv[1];
|
||||
vector<string> tokens1;
|
||||
vector<string> tokens2;
|
||||
char token = argv[2][0];
|
||||
|
||||
cout << "string = \"" << test << "\", token = \'" << token << "\'\n";
|
||||
cout << "testing without ignore\n";
|
||||
tokenize(tokens1, test, token, false);
|
||||
|
||||
if (tokens1.size()) {
|
||||
int size = tokens1.size();
|
||||
cout << "size = " << size << "\n";
|
||||
for (i = 0; i < size; i++) {
|
||||
cout << "'" << tokens1[i] << "' (" << tokens1[i].size()
|
||||
<< ")" << ((i == size - 1) ? "\n" : ", ");
|
||||
}
|
||||
} else {
|
||||
cout << "no tokens" << endl;
|
||||
}
|
||||
|
||||
cout << "testing with ignore\n";
|
||||
tokenize(tokens2, test, token, true);
|
||||
|
||||
if (tokens2.size()) {
|
||||
int size = tokens2.size();
|
||||
cout << "size = " << size << "\n";
|
||||
for (i = 0; i < size; i++) {
|
||||
cout << "'" << tokens2[i] << "' (" << tokens2[i].size()
|
||||
<< ")" << ((i == size - 1) ? "\n" : ", ");
|
||||
}
|
||||
} else {
|
||||
cout << "no tokens" << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
127
simulators/gem5/src/unittest/trietest.cc
Normal file
127
simulators/gem5/src/unittest/trietest.cc
Normal file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Google
|
||||
* 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: Gabe Black
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#include "base/cprintf.hh"
|
||||
#include "base/trie.hh"
|
||||
#include "base/types.hh"
|
||||
#include "unittest/unittest.hh"
|
||||
|
||||
using UnitTest::setCase;
|
||||
|
||||
typedef Trie<Addr, uint32_t> TestTrie;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
// Create an empty Ptr and verify it's data pointer is NULL.
|
||||
setCase("An empty trie.");
|
||||
TestTrie trie1;
|
||||
trie1.dump("Empty");
|
||||
cprintf("\n\n");
|
||||
|
||||
setCase("A single entry.");
|
||||
trie1.insert(0x0123456789abcdef, 40, (uint32_t *)(uintptr_t)(1));
|
||||
trie1.dump("One entry");
|
||||
cprintf("\n\n");
|
||||
|
||||
setCase("Two entries, one on the way to the other.");
|
||||
TestTrie trie2;
|
||||
trie2.insert(0x0123456789abcdef, 40, (uint32_t *)(uintptr_t)(1));
|
||||
trie2.insert(0x0123456789abcdef, 36, (uint32_t *)(uintptr_t)(2));
|
||||
trie2.dump("Two entries inline v1");
|
||||
cprintf("\n\n");
|
||||
|
||||
TestTrie trie3;
|
||||
trie3.insert(0x0123456789abcdef, 36, (uint32_t *)(uintptr_t)(2));
|
||||
trie3.insert(0x0123456789abcdef, 40, (uint32_t *)(uintptr_t)(1));
|
||||
trie3.dump("Two entries inline v2");
|
||||
cprintf("\n\n");
|
||||
|
||||
setCase("Two entries on different paths.");
|
||||
TestTrie trie4;
|
||||
trie4.insert(0x0123456789abcdef, 40, (uint32_t *)(uintptr_t)(2));
|
||||
trie4.insert(0x0123456776543210, 40, (uint32_t *)(uintptr_t)(1));
|
||||
trie4.dump("Two split entries");
|
||||
cprintf("\n\n");
|
||||
|
||||
setCase("Skipping past an entry but not two.");
|
||||
TestTrie trie5;
|
||||
trie5.insert(0x0123456789000000, 40, (uint32_t *)(uintptr_t)(4));
|
||||
trie5.insert(0x0123000000000000, 40, (uint32_t *)(uintptr_t)(1));
|
||||
trie5.insert(0x0123456780000000, 40, (uint32_t *)(uintptr_t)(3));
|
||||
trie5.insert(0x0123456700000000, 40, (uint32_t *)(uintptr_t)(2));
|
||||
trie5.dump("Complex insertion");
|
||||
cprintf("\n\n");
|
||||
|
||||
setCase("Looking things up.");
|
||||
EXPECT_EQ((uintptr_t)trie5.lookup(0x0123000000000000), 1);
|
||||
EXPECT_EQ((uintptr_t)trie5.lookup(0x0123456700000000), 2);
|
||||
EXPECT_EQ((uintptr_t)trie5.lookup(0x0123456780000000), 3);
|
||||
EXPECT_EQ((uintptr_t)trie5.lookup(0x0123456789000000), 4);
|
||||
|
||||
setCase("Removing entries.");
|
||||
TestTrie trie6;
|
||||
TestTrie::Handle node1, node2;
|
||||
trie6.insert(0x0123456789000000, 40, (uint32_t *)(uintptr_t)(4));
|
||||
trie6.insert(0x0123000000000000, 40, (uint32_t *)(uintptr_t)(1));
|
||||
trie6.insert(0x0123456780000000, 40, (uint32_t *)(uintptr_t)(3));
|
||||
node1 = trie6.insert(0x0123456700000000, 40, (uint32_t *)(uintptr_t)(2));
|
||||
node2 = trie6.insert(0x0123456700000000, 32, (uint32_t *)(uintptr_t)(10));
|
||||
trie6.dump("Fill before removal");
|
||||
cprintf("\n\n");
|
||||
|
||||
EXPECT_EQ((uintptr_t)trie6.lookup(0x0123000000000000), 1);
|
||||
EXPECT_EQ((uintptr_t)trie6.lookup(0x0123456700000000), 10);
|
||||
EXPECT_EQ((uintptr_t)trie6.lookup(0x0123456780000000), 10);
|
||||
EXPECT_EQ((uintptr_t)trie6.lookup(0x0123456789000000), 10);
|
||||
|
||||
trie6.remove(node2);
|
||||
trie6.dump("One node removed");
|
||||
cprintf("\n\n");
|
||||
|
||||
EXPECT_EQ((uintptr_t)trie6.lookup(0x0123000000000000), 1);
|
||||
EXPECT_EQ((uintptr_t)trie6.lookup(0x0123456700000000), 2);
|
||||
EXPECT_EQ((uintptr_t)trie6.lookup(0x0123456780000000), 3);
|
||||
EXPECT_EQ((uintptr_t)trie6.lookup(0x0123456789000000), 4);
|
||||
|
||||
trie6.remove(node1);
|
||||
trie6.dump("Two nodes removed");
|
||||
cprintf("\n\n");
|
||||
|
||||
EXPECT_EQ((uintptr_t)trie6.lookup(0x0123000000000000), 1);
|
||||
EXPECT_EQ(trie6.lookup(0x0123456700000000), NULL);
|
||||
EXPECT_EQ((uintptr_t)trie6.lookup(0x0123456780000000), 3);
|
||||
EXPECT_EQ((uintptr_t)trie6.lookup(0x0123456789000000), 4);
|
||||
|
||||
return UnitTest::printResults();
|
||||
}
|
||||
93
simulators/gem5/src/unittest/unittest.cc
Normal file
93
simulators/gem5/src/unittest/unittest.cc
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2011 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: Gabe Black
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include "base/cprintf.hh"
|
||||
#include "unittest/unittest.hh"
|
||||
|
||||
namespace {
|
||||
|
||||
bool _printOnPass = (getenv("PRINT_ON_PASS") != NULL);
|
||||
unsigned _passes = 0;
|
||||
unsigned _failures = 0;
|
||||
|
||||
bool _casePrinted = false;
|
||||
const char *_case = NULL;
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
void
|
||||
checkVal(const char *file, const unsigned line,
|
||||
const char *test, const bool result)
|
||||
{
|
||||
if (!result || _printOnPass) {
|
||||
if (!_casePrinted && _case) {
|
||||
cprintf("CASE %s:\n", _case);
|
||||
_casePrinted = true;
|
||||
}
|
||||
cprintf(" CHECK %s: %s:%d %s\n",
|
||||
result ? "PASSED" : "FAILED", file, line, test);
|
||||
}
|
||||
if (result) _passes++;
|
||||
else _failures++;
|
||||
}
|
||||
|
||||
bool printOnPass() { return _printOnPass; }
|
||||
void printOnPass(bool newPrintOnPass) { _printOnPass = newPrintOnPass; }
|
||||
|
||||
unsigned passes() { return _passes; }
|
||||
unsigned failures() { return _failures; }
|
||||
|
||||
unsigned
|
||||
printResults()
|
||||
{
|
||||
cprintf("TEST %s: %d checks passed, %d checks failed.\n",
|
||||
_failures ? "FAILED" : "PASSED", _passes, _failures);
|
||||
return _failures;
|
||||
}
|
||||
|
||||
void
|
||||
reset()
|
||||
{
|
||||
_passes = 0;
|
||||
_failures = 0;
|
||||
}
|
||||
|
||||
void
|
||||
setCase(const char *newCase)
|
||||
{
|
||||
_casePrinted = false;
|
||||
_case = newCase;
|
||||
}
|
||||
|
||||
} //namespace UnitTest
|
||||
116
simulators/gem5/src/unittest/unittest.hh
Normal file
116
simulators/gem5/src/unittest/unittest.hh
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2011 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: Gabe Black
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file This file defines functions and macros for use in unit tests.
|
||||
*/
|
||||
|
||||
#ifndef __UNITTEST_UNITTEST_HH__
|
||||
#define __UNITTEST_UNITTEST_HH__
|
||||
|
||||
namespace UnitTest {
|
||||
|
||||
/**
|
||||
* Function that actually handles checking whether an EXPECT_* passed. This
|
||||
* should be used through the EXPECT macros below and not called directly.
|
||||
* @param file The name of the file this check is in.
|
||||
* @param line The line number this check is on.
|
||||
* @param test Text specifying what check is being performed.
|
||||
* @param result Whether the check passed.
|
||||
*/
|
||||
void checkVal(const char *file, const unsigned line,
|
||||
const char *test, const bool result);
|
||||
|
||||
/**
|
||||
* Print on pass is a switch that specifies whether to print a message even
|
||||
* when a check passes. It's default value is whether or not "PRINT_ON_PASS"
|
||||
* is set in the calling environment. What it's actually set to is ignored.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function for retrieving the current setting for print on pass.
|
||||
* @return The current setting.
|
||||
*/
|
||||
bool printOnPass();
|
||||
|
||||
/**
|
||||
* Function for setting print on pass.
|
||||
* @param newVal The new setting.
|
||||
*/
|
||||
void printOnPass(bool newVal);
|
||||
|
||||
/**
|
||||
* Function that returns the current number of passed checks.
|
||||
* @return Number of checks that have passed so far.
|
||||
*/
|
||||
unsigned passes();
|
||||
|
||||
/**
|
||||
* Function that returns the current number of failed checks.
|
||||
* @return Number of checks that have failed so far.
|
||||
*/
|
||||
unsigned failures();
|
||||
|
||||
/**
|
||||
* Function to call at the end of a test that prints an overall result and a
|
||||
* summary of how many checks passed and failed. main() should return the
|
||||
* return value of this function which is the number of failed checks.
|
||||
* @return Number of failed checks.
|
||||
*/
|
||||
unsigned printResults();
|
||||
|
||||
/// Zero the number of passes and failures so far.
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Sets the current test case. Test cases are used to group checks together and
|
||||
* describe what that group is doing. Setting a new case defines the start of
|
||||
* a new group and the end of the previous one. The case string is used in
|
||||
* place and not copied, so don't modify or invalidate it until a new case
|
||||
* label is installed.
|
||||
* @param newCase The name of the new test case.
|
||||
*/
|
||||
void setCase(const char *newCase);
|
||||
|
||||
} // namespace UnitTest
|
||||
|
||||
/// A macro which verifies that expr evaluates to true.
|
||||
#define EXPECT_TRUE(expr) \
|
||||
UnitTest::checkVal(__FILE__, __LINE__, "EXPECT_TRUE(" #expr ")", (expr))
|
||||
/// A macro which verifies that expr evaluates to false.
|
||||
#define EXPECT_FALSE(expr) \
|
||||
UnitTest::checkVal(__FILE__, __LINE__, \
|
||||
"EXPECT_FALSE(" #expr ")", (expr) == false)
|
||||
/// A macro which verifies that lhs and rhs are equal to each other.
|
||||
#define EXPECT_EQ(lhs, rhs) \
|
||||
UnitTest::checkVal(__FILE__, __LINE__, \
|
||||
"EXPECT_EQ(" #lhs ", " #rhs ")", (lhs) == (rhs));
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user