diff options
author | Bobby R. Bruce <bbruce@ucdavis.edu> | 2019-10-22 16:16:10 -0700 |
---|---|---|
committer | Bobby R. Bruce <bbruce@ucdavis.edu> | 2019-10-24 16:25:09 +0000 |
commit | 69930afa9b63c25baab86ff5fbe632fc02ce5369 (patch) | |
tree | b26df22c0621a2ab274a36a3ce332accdac1441d /src/unittest | |
parent | f60383d060ed82400526a47a1ba3182253e9f2f5 (diff) | |
download | gem5-69930afa9b63c25baab86ff5fbe632fc02ce5369.tar.xz |
tests: Added GTests for base/str.cc
Adding these tests supercedes the unittest/strnumtest.cc
and unittest/tokentest.cc tests. They have thereby been removed.
Function "to_number" in base/str.hh previously failed to cast negative
float/double numbers. This was due to the use of
std::numeric_limits<T>::min() instead of std::numeric_limits<T>::lowest()
to determine whether a string-to-float/double conversion was
"Out of range". Tests "StrTest.ToNumberFloatNegative" and
"StrTest.ToNumberDoubleNegative" exposed this bug. It has been fixed.
Methods "split_first" and "split_last" in base/str.hh have had their
documentation updated to remove abiguity in their functionality.
Change-Id: I16e0fe40d884e22dd010db4045857eb6e7f33d4a
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/22084
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'src/unittest')
-rw-r--r-- | src/unittest/SConscript | 2 | ||||
-rw-r--r-- | src/unittest/strnumtest.cc | 77 | ||||
-rw-r--r-- | src/unittest/tokentest.cc | 83 |
3 files changed, 0 insertions, 162 deletions
diff --git a/src/unittest/SConscript b/src/unittest/SConscript index f437a1dda..0ca0702c1 100644 --- a/src/unittest/SConscript +++ b/src/unittest/SConscript @@ -35,10 +35,8 @@ Source('unittest.cc') UnitTest('cprintftime', 'cprintftime.cc') UnitTest('nmtest', 'nmtest.cc') UnitTest('refcnttest', 'refcnttest.cc') -UnitTest('strnumtest', 'strnumtest.cc') stattest_py = PySource('m5', 'stattestmain.py', tags='stattest') UnitTest('stattest', 'stattest.cc', with_tag('stattest'), main=True) UnitTest('symtest', 'symtest.cc') -UnitTest('tokentest', 'tokentest.cc') diff --git a/src/unittest/strnumtest.cc b/src/unittest/strnumtest.cc deleted file mode 100644 index 0e234884d..000000000 --- a/src/unittest/strnumtest.cc +++ /dev/null @@ -1,77 +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 <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; -} diff --git a/src/unittest/tokentest.cc b/src/unittest/tokentest.cc deleted file mode 100644 index 128346b5b..000000000 --- a/src/unittest/tokentest.cc +++ /dev/null @@ -1,83 +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 <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; -} |