From 52493b27202fb61aaae74779ebcd91ca8f2bbc2c Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Thu, 2 Oct 2008 11:26:59 -0700 Subject: unittest: Cleanup unit tests. Follow style. Garbage Collect. --HG-- rename : src/unittest/rangemaptest2.cc => src/unittest/rangemultimaptest.cc --- src/unittest/bitvectest.cc | 48 ++++++++--------- src/unittest/circletest.cc | 55 ++++++++++---------- src/unittest/foo.ini | 1 - src/unittest/initest.ini | 14 ----- src/unittest/lru_test.cc | 85 ------------------------------ src/unittest/offtest.cc | 72 ------------------------- src/unittest/paramtest.cc | 107 -------------------------------------- src/unittest/rangemaptest.cc | 3 +- src/unittest/rangemaptest2.cc | 78 --------------------------- src/unittest/rangemultimaptest.cc | 80 ++++++++++++++++++++++++++++ src/unittest/rangetest.cc | 57 ++++++++++---------- src/unittest/sized_test.cc | 70 ------------------------- src/unittest/strnumtest.cc | 63 +++++++++++----------- src/unittest/tracetest.cc | 56 -------------------- 14 files changed, 194 insertions(+), 595 deletions(-) delete mode 100644 src/unittest/initest.ini delete mode 100644 src/unittest/lru_test.cc delete mode 100644 src/unittest/offtest.cc delete mode 100644 src/unittest/paramtest.cc delete mode 100644 src/unittest/rangemaptest2.cc create mode 100644 src/unittest/rangemultimaptest.cc delete mode 100644 src/unittest/sized_test.cc delete mode 100644 src/unittest/tracetest.cc (limited to 'src/unittest') diff --git a/src/unittest/bitvectest.cc b/src/unittest/bitvectest.cc index 440a150a3..2f01d636f 100644 --- a/src/unittest/bitvectest.cc +++ b/src/unittest/bitvectest.cc @@ -35,34 +35,34 @@ int main() { - vector v1(100); + vector v1(100); - v1[0] = true; - v1.resize(500); - v1[100] = true; - v1[499] = true; - v1.resize(10000); - v1[9999] = true; + 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 << "v1.size() = " << v1.size() << "\n"; + for (int i = 0; i < v1.size(); i++) + if (v1[i]) + cout << "v1[" << i << "] = " << v1[i] << "\n"; - cout << "\n"; + cout << "\n"; - vector v2 = v1; + vector v2 = v1; - for (int i = 0; i < v2.size(); i++) - if (v2[i]) - cout << "v2[" << i << "] = " << v2[i] << "\n"; + 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; + 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; } diff --git a/src/unittest/circletest.cc b/src/unittest/circletest.cc index f072cf044..c6fce0f8f 100644 --- a/src/unittest/circletest.cc +++ b/src/unittest/circletest.cc @@ -34,14 +34,15 @@ #include "base/circlebuf.hh" -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" +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 *); @@ -49,26 +50,26 @@ const int num_strings = sizeof(strings) / sizeof(char *); int main() { - CircleBuf buf(1024); + 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); + 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); + 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); + 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); } diff --git a/src/unittest/foo.ini b/src/unittest/foo.ini index 534a4e001..0f91c1fd6 100644 --- a/src/unittest/foo.ini +++ b/src/unittest/foo.ini @@ -1,4 +1,3 @@ -#define JUNK [Foo] Foo1=89 Foo2=384 diff --git a/src/unittest/initest.ini b/src/unittest/initest.ini deleted file mode 100644 index ebf2719d8..000000000 --- a/src/unittest/initest.ini +++ /dev/null @@ -1,14 +0,0 @@ -#define JUNK -// General stuff -#define FOO(X) BAR##X -[General] - Test1=FOO(asdf) - Test2=bar - -#ifdef JUNK -[Junk] // This is the junk -Test3=yo -Test4=mama -#endif - -#include "foo.ini" diff --git a/src/unittest/lru_test.cc b/src/unittest/lru_test.cc deleted file mode 100644 index d10eb1dd0..000000000 --- a/src/unittest/lru_test.cc +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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: Dave Greene - * Nathan Binkert - */ - -#include -#include "bhgp.hh" - -int main(void) -{ - typedef AssociativeTable tableType; - tableType table(10, 4); // 40 entry table - - std::cout << "Initial state:" << std::endl; - table.dump(); - - std::cout << "Inserting (2, 1)" << std::endl; - table[2] = 1; - table.dump(); - - std::cout << "Inserting (5, 2)" << std::endl; - table[5] = 2; - table.dump(); - - std::cout << "Inserting (10 + 2, 3)" << std::endl; - table[10 + 2] = 3; - table.dump(); - - tableType::const_iterator i = table.find(2); - assert(i != table.end()); - std::cout << "Accessed 2: " << *i << std::endl; - table.dump(); - - i = table.find(10 + 2); - assert(i != table.end()); - std::cout << "Accessed 10 + 2: " << *i << std::endl; - table.dump(); - - i = table.find(34); - assert(i == table.end()); - - std::cout << "Inserting (2 * 10 + 2, 4)" << std::endl; - table[2 * 10 + 2] = 4; - table.dump(); - - std::cout << "Replacing (10 + 2) with 5" << std::endl; - table[10 + 2] = 5; - table.dump(); - - std::cout << "Inserting (3 * 10 + 2, 6)" << std::endl; - table[3 * 10 + 2] = 6; - table.dump(); - - std::cout << "Inserting (4 * 10 + 2, 7)" << std::endl; - table[4 * 10 + 2] = 7; - table.dump(); - - return(0); -} diff --git a/src/unittest/offtest.cc b/src/unittest/offtest.cc deleted file mode 100644 index ebfb2515c..000000000 --- a/src/unittest/offtest.cc +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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 -#include -#include -#include "dev/pcireg.h" - -int -main() -{ -#define POFFSET(x) \ - printf("offsetof(PCIConfig, hdr."#x") = %d\n", \ - offsetof(PCIConfig, hdr.x)) - - POFFSET(vendor); - POFFSET(device); - POFFSET(command); - POFFSET(status); - POFFSET(revision); - POFFSET(progIF); - POFFSET(subClassCode); - POFFSET(classCode); - POFFSET(cacheLineSize); - POFFSET(latencyTimer); - POFFSET(headerType); - POFFSET(bist); - POFFSET(pci0.baseAddr0); - POFFSET(pci0.baseAddr1); - POFFSET(pci0.baseAddr2); - POFFSET(pci0.baseAddr3); - POFFSET(pci0.baseAddr4); - POFFSET(pci0.baseAddr5); - POFFSET(pci0.cardbusCIS); - POFFSET(pci0.subsystemVendorID); - POFFSET(pci0.expansionROM); - POFFSET(pci0.reserved0); - POFFSET(pci0.reserved1); - POFFSET(pci0.interruptLine); - POFFSET(pci0.interruptPin); - POFFSET(pci0.minimumGrant); - POFFSET(pci0.minimumLatency); - - return 0; -} diff --git a/src/unittest/paramtest.cc b/src/unittest/paramtest.cc deleted file mode 100644 index e513ab981..000000000 --- a/src/unittest/paramtest.cc +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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 - */ - -// -// This file is not part of the regular simulator. It is solely for -// testing the parameter code. Edit the Makefile to add param_test.cc -// to the sources list, then use configs/test.ini as the configuration -// file. -// -#include "sim/sim_object.hh" -#include "mem/cache/cache.hh" - -class ParamTest : public SimObject -{ - public: - ParamTest(string name) - : SimObject(name) - { - } - - virtual ~ParamTest() {} -}; - -enum Enum1Type { Enum0 }; -enum Enum2Type { Enum10 }; - -BEGIN_DECLARE_SIM_OBJECT_PARAMS(ParamTest) - - Param intparam; - VectorParam vecint; - Param stringparam; - VectorParam vecstring; - Param boolparam; - VectorParam vecbool; - SimObjectParam memobj; - SimObjectVectorParam vecmemobj; - SimpleEnumParam enum1; - MappedEnumParam enum2; - SimpleEnumVectorParam vecenum1; - MappedEnumVectorParam vecenum2; - -END_DECLARE_SIM_OBJECT_PARAMS(ParamTest) - -const char *enum1_strings[] = -{ - "zero", "one", "two", "three" -}; - -const EnumParamMap enum2_map[] = -{ - { "ten", 10 }, - { "twenty", 20 }, - { "thirty", 30 }, - { "forty", 40 } -}; - -BEGIN_INIT_SIM_OBJECT_PARAMS(ParamTest) - - INIT_PARAM(intparam, "intparam"), - INIT_PARAM(vecint, "vecint"), - INIT_PARAM(stringparam, "stringparam"), - INIT_PARAM(vecstring, "vecstring"), - INIT_PARAM(boolparam, "boolparam"), - INIT_PARAM(vecbool, "vecbool"), - INIT_PARAM(memobj, "memobj"), - INIT_PARAM(vecmemobj, "vecmemobj"), - INIT_ENUM_PARAM(enum1, "enum1", enum1_strings), - INIT_ENUM_PARAM(enum2, "enum2", enum2_map), - INIT_ENUM_PARAM(vecenum1, "vecenum1", enum1_strings), - INIT_ENUM_PARAM(vecenum2, "vecenum2", enum2_map) - -END_INIT_SIM_OBJECT_PARAMS(ParamTest) - - -CREATE_SIM_OBJECT(ParamTest) -{ - return new ParamTest(getInstanceName()); -} - -REGISTER_SIM_OBJECT("ParamTest", ParamTest) diff --git a/src/unittest/rangemaptest.cc b/src/unittest/rangemaptest.cc index 983a41520..36223ed9c 100644 --- a/src/unittest/rangemaptest.cc +++ b/src/unittest/rangemaptest.cc @@ -35,7 +35,8 @@ using namespace std; -int main() +int +main() { range_map r; diff --git a/src/unittest/rangemaptest2.cc b/src/unittest/rangemaptest2.cc deleted file mode 100644 index b253dbe86..000000000 --- a/src/unittest/rangemaptest2.cc +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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 -#include -#include "sim/host.hh" -#include "base/range_map.hh" - -using namespace std; - -int main() -{ - range_multimap r; - - range_multimap::iterator i; - std::pair::iterator,range_multimap::iterator> - jk; - - i = r.insert(RangeIn(10,40),5); - assert(i != r.end()); - i = r.insert(RangeIn(10,40),6); - assert(i != r.end()); - i = r.insert(RangeIn(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(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; - - -} - - - - - - - - diff --git a/src/unittest/rangemultimaptest.cc b/src/unittest/rangemultimaptest.cc new file mode 100644 index 000000000..a110256c9 --- /dev/null +++ b/src/unittest/rangemultimaptest.cc @@ -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 +#include + +#include "sim/host.hh" +#include "base/range_map.hh" + +using namespace std; + +int +main() +{ + typedef range_multimap multimap_t; + + multimap_t r; + multimap_t::iterator i; + std::pair jk; + + i = r.insert(RangeIn(10,40),5); + assert(i != r.end()); + i = r.insert(RangeIn(10,40),6); + assert(i != r.end()); + i = r.insert(RangeIn(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(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; + + +} + + + + + + + + diff --git a/src/unittest/rangetest.cc b/src/unittest/rangetest.cc index b7a68ab44..eab2f39a8 100644 --- a/src/unittest/rangetest.cc +++ b/src/unittest/rangetest.cc @@ -38,39 +38,40 @@ using namespace std; int main() { - Range r1(make_pair(9, 28)); - Range r2("0x1000:+0x100"); + Range r1(make_pair(9, 28)); + Range r2("0x1000:+0x100"); - cout << r1 << "\n" - << r2 << "\n"; + cout << r1 << "\n" + << r2 << "\n"; -#define RANGETEST(X, C, Y) \ - cout << X << " "#C" " << Y << " => " << ((X C Y) ? "true" : "false") << "\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) + 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(8, r1); + TESTEM(9, r1); + TESTEM(27, r1); + TESTEM(28, r1); - TESTEM(0x0fff, r2); - TESTEM(0x1000, r2); - TESTEM(0x10ff, r2); - TESTEM(0x1100, r2); + TESTEM(0x0fff, r2); + TESTEM(0x1000, r2); + TESTEM(0x10ff, r2); + TESTEM(0x1100, r2); - return 0; + return 0; } diff --git a/src/unittest/sized_test.cc b/src/unittest/sized_test.cc deleted file mode 100644 index f1bf7528f..000000000 --- a/src/unittest/sized_test.cc +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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: Dave Greene - * Nathan Binkert - */ - -#include -#include - -#include "sized.hh" -#include -#include - -template -void print(C &cont) -{ - std::cout << std::endl; - std::cout << "Printing " << typeid(cont).name() << std::endl; - while (!cont.empty()) { - std::cout << cont.front() << " "; - cont.pop(); - } - std::cout << std::endl; -} - -int main(void) -{ - sized, sized_error_policy > > - error_queue(10); - sized, sized_drop_policy > > - drop_queue(5); - - for (int i = 0; i < 10; ++i) { - error_queue.push(i); - } - - for (int i = 0; i < 3; ++i) { - drop_queue.push(i); - } - - print(error_queue); - print(drop_queue); - - return(0); -} diff --git a/src/unittest/strnumtest.cc b/src/unittest/strnumtest.cc index ea28e35df..0e234884d 100644 --- a/src/unittest/strnumtest.cc +++ b/src/unittest/strnumtest.cc @@ -28,8 +28,7 @@ * Authors: Nathan Binkert */ -#include - +#include #include #include @@ -40,39 +39,39 @@ using namespace std; int main(int argc, char *argv[]) { - if (argc != 2) { - cout << "Usage: " << argv[0] << " \n"; - exit(1); - } + if (argc != 2) { + cout << "Usage: " << argv[0] << " \n"; + exit(1); + } - string s = argv[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) + 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); + 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; + return 0; } diff --git a/src/unittest/tracetest.cc b/src/unittest/tracetest.cc deleted file mode 100644 index b1343aac3..000000000 --- a/src/unittest/tracetest.cc +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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 "sim/host.hh" -#include "base/trace.hh" - -using namespace std; - -Tick curTick = 0; - -struct foo -{ - foo() - { - char foo[9] = "testing"; - DPRINTF(Loader, "%s\n", foo); - } -}; - -int -main() -{ - Trace::flags[Trace::Loader] = true; - Trace::dprintf_stream = &cout; - - foo f; - - return 0; -} -- cgit v1.2.3 From b25755993bbc04be0235975e2967533995a493f0 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Thu, 2 Oct 2008 11:27:01 -0700 Subject: unittest: Add unit tests to the scons framework. Also fix the unit tests so they actually compile correctly. --- src/unittest/Makefile | 101 --------------------------------------------- src/unittest/SConscript | 48 +++++++++++++++++++++ src/unittest/bitvectest.cc | 5 ++- src/unittest/circletest.cc | 5 ++- src/unittest/initest.cc | 20 +-------- src/unittest/nmtest.cc | 3 -- src/unittest/stattest.cc | 30 ++++++++------ src/unittest/symtest.cc | 4 +- 8 files changed, 74 insertions(+), 142 deletions(-) delete mode 100644 src/unittest/Makefile create mode 100644 src/unittest/SConscript (limited to 'src/unittest') diff --git a/src/unittest/Makefile b/src/unittest/Makefile deleted file mode 100644 index e6a621a9e..000000000 --- a/src/unittest/Makefile +++ /dev/null @@ -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 diff --git a/src/unittest/SConscript b/src/unittest/SConscript new file mode 100644 index 000000000..1c1959165 --- /dev/null +++ b/src/unittest/SConscript @@ -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') diff --git a/src/unittest/bitvectest.cc b/src/unittest/bitvectest.cc index 2f01d636f..29069081b 100644 --- a/src/unittest/bitvectest.cc +++ b/src/unittest/bitvectest.cc @@ -28,10 +28,11 @@ * Authors: Nathan Binkert */ -#include - +#include #include +using namespace std; + int main() { diff --git a/src/unittest/circletest.cc b/src/unittest/circletest.cc index c6fce0f8f..2ee75b6df 100644 --- a/src/unittest/circletest.cc +++ b/src/unittest/circletest.cc @@ -29,12 +29,13 @@ */ #include -#include #include +#include + #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", diff --git a/src/unittest/initest.cc b/src/unittest/initest.cc index 8f53fce5c..67ac44874 100644 --- a/src/unittest/initest.cc +++ b/src/unittest/initest.cc @@ -68,32 +68,14 @@ main(int argc, char *argv[]) progname = argv[0]; - vector cppArgs; - - vector 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: // '--
:=' @@ -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); } diff --git a/src/unittest/nmtest.cc b/src/unittest/nmtest.cc index b6b74e08d..fdd865f2d 100644 --- a/src/unittest/nmtest.cc +++ b/src/unittest/nmtest.cc @@ -38,9 +38,6 @@ #include "base/str.hh" using namespace std; -Tick curTick; - -ostream *outputStream = &cout; int main(int argc, char *argv[]) diff --git a/src/unittest/stattest.cc b/src/unittest/stattest.cc index 4e504fde9..78d43c6f3 100644 --- a/src/unittest/stattest.cc +++ b/src/unittest/stattest.cc @@ -30,9 +30,7 @@ #include #include -#include #include -#include #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; } diff --git a/src/unittest/symtest.cc b/src/unittest/symtest.cc index f0142b923..10ffb42e5 100644 --- a/src/unittest/symtest.cc +++ b/src/unittest/symtest.cc @@ -28,12 +28,12 @@ * Authors: Nathan Binkert */ -#include +#include #include "base/str.hh" #include "base/loader/symtab.hh" -Tick curTick = 0; +using namespace std; void usage(const char *progname) -- cgit v1.2.3 From 89f016aacbe92f90c1af98678043f2f6fc82c364 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Fri, 10 Oct 2008 21:45:35 -0700 Subject: cprintf: properly deal with pointer types --- src/unittest/cprintftest.cc | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/unittest') diff --git a/src/unittest/cprintftest.cc b/src/unittest/cprintftest.cc index 7fb10375c..1438f194b 100644 --- a/src/unittest/cprintftest.cc +++ b/src/unittest/cprintftest.cc @@ -34,6 +34,7 @@ #include #include "base/cprintf.hh" +#include "base/misc.hh" using namespace std; @@ -43,6 +44,14 @@ 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", -- cgit v1.2.3 From 74f10be5266039fc9d2c1be14c551d1bcefed99c Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 3 Dec 2008 04:57:54 -0800 Subject: cprintf: support a configurable width and precision ("*" in printf) --- src/unittest/cprintftest.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/unittest') diff --git a/src/unittest/cprintftest.cc b/src/unittest/cprintftest.cc index 1438f194b..6722ce6a3 100644 --- a/src/unittest/cprintftest.cc +++ b/src/unittest/cprintftest.cc @@ -167,6 +167,13 @@ main() cprintf("%c %c\n", 'c', 65); - cout << '9'; + 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; } -- cgit v1.2.3 From bcb7e70178d2d15a8c30561311634df7a2c24c70 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Mon, 23 Feb 2009 12:04:52 -0800 Subject: stats: clean up the statistics unittest --- src/unittest/stattest.cc | 105 +++++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 50 deletions(-) (limited to 'src/unittest') diff --git a/src/unittest/stattest.cc b/src/unittest/stattest.cc index 78d43c6f3..30b7f8a6c 100644 --- a/src/unittest/stattest.cc +++ b/src/unittest/stattest.cc @@ -42,31 +42,6 @@ using namespace std; using namespace Stats; -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; - -Formula f1; -Formula f2; -Formula f3; -Value f4; -Value f5; -Formula f6; -Formula f7; - double testfunc() { @@ -141,15 +116,34 @@ main(int argc, char *argv[]) if (!text && (compat || descriptions)) usage(); - s5.init(5); - s6.init(1, 100, 13); - s7.init(7); - s8.init(10); - s12.init(1, 100, 13); - s13.init(4, 0, 99, 10); - s14.init(9); - s15.init(10); - s16.init(2, 9); + 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; + + Formula f1; + Formula f2; + Formula f3; + Formula f4; + Formula f5; + + cprintf("sizeof(Scalar<>) = %d\n", sizeof(Scalar<>)); + cprintf("sizeof(Vector<>) = %d\n", sizeof(Vector<>)); + cprintf("sizeof(Distribution<>) = %d\n", sizeof(Distribution<>)); s1 .name("Stat01") @@ -165,7 +159,7 @@ main(int argc, char *argv[]) s3 .name("Stat03") .desc("this is statistic 3") - .prereq(f7) + .prereq(f5) ; s4 @@ -175,6 +169,7 @@ main(int argc, char *argv[]) ; s5 + .init(5) .name("Stat05") .desc("this is statistic 5") .prereq(s11) @@ -186,12 +181,14 @@ main(int argc, char *argv[]) ; 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) @@ -200,6 +197,7 @@ main(int argc, char *argv[]) ; s8 + .init(10) .name("Stat08") .desc("this is statistic 8") .precision(2) @@ -221,26 +219,31 @@ main(int argc, char *argv[]) ; 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) @@ -250,6 +253,20 @@ main(int argc, char *argv[]) .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") + ; + + f1 .name("Formula1") .desc("this is formula 1") @@ -275,29 +292,17 @@ main(int argc, char *argv[]) ; f4 - .functor(testfunc) .name("Formula4") .desc("this is formula 4") ; - TestClass testclass; - f5 - .functor(testclass) - .name("Formula5") - .desc("this is formula 5") - ; - - f6 - .name("Formula6") - .desc("this is formula 6") - ; f1 = s1 + s2; f2 = (-s1) / (-s2) * (-s3 + ULL(100) + s4); f3 = sum(s5) * s7; - f6 += constant(10.0); - f6 += s5[3]; - f7 = constant(1); + f4 += constant(10.0); + f4 += s5[3]; + f5 = constant(1); check(); reset(); -- cgit v1.2.3 From cc95b5739097e31fdaa36a3ff443861969e338b1 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Thu, 5 Mar 2009 19:09:53 -0800 Subject: stats: Fix all stats usages to deal with template fixes --- src/unittest/stattest.cc | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/unittest') diff --git a/src/unittest/stattest.cc b/src/unittest/stattest.cc index 30b7f8a6c..3934786ec 100644 --- a/src/unittest/stattest.cc +++ b/src/unittest/stattest.cc @@ -116,22 +116,22 @@ main(int argc, char *argv[]) if (!text && (compat || descriptions)) usage(); - 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; + 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; @@ -141,9 +141,9 @@ main(int argc, char *argv[]) Formula f4; Formula f5; - cprintf("sizeof(Scalar<>) = %d\n", sizeof(Scalar<>)); - cprintf("sizeof(Vector<>) = %d\n", sizeof(Vector<>)); - cprintf("sizeof(Distribution<>) = %d\n", sizeof(Distribution<>)); + cprintf("sizeof(Scalar) = %d\n", sizeof(Scalar)); + cprintf("sizeof(Vector) = %d\n", sizeof(Vector)); + cprintf("sizeof(Distribution) = %d\n", sizeof(Distribution)); s1 .name("Stat01") -- cgit v1.2.3