gem5 v24.0.0.0
Loading...
Searching...
No Matches
info.test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Daniel R. Carvalho
3 * All rights reserved
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <gtest/gtest-spi.h>
30#include <gtest/gtest.h>
31
32#include "base/stats/info.hh"
33
34using namespace gem5;
35
37{
38 public:
40
41 int value = 0;
42
43 bool check() const override { return true; }
44 void prepare() override {}
45 void reset() override { value = 0; }
46 bool zero() const override { return false; }
47 void visit(statistics::Output &visitor) override {}
48};
49
51TEST(StatsInfoTest, NameNewStyle)
52{
53 TestInfo info;
54 info.setName("InfoNameNewStyle", false);
55 ASSERT_EQ(info.name, "InfoNameNewStyle");
56}
57
59TEST(StatsInfoTest, NameFirstCharacter)
60{
61 TestInfo info;
62 info.setName("X", false);
63 ASSERT_EQ(info.name, "X");
64
65 TestInfo info2;
66 info2.setName("a", false);
67 ASSERT_EQ(info2.name, "a");
68
69 TestInfo info3;
70 info3.setName("_", false);
71 ASSERT_EQ(info3.name, "_");
72
73 TestInfo info4;
74 info4.setName("X.Y", false);
75 ASSERT_EQ(info4.name, "X.Y");
76
77 TestInfo info5;
78 info5.setName("a.b._.d.e", false);
79 ASSERT_EQ(info5.name, "a.b._.d.e");
80}
81
83TEST(StatsInfoTest, NameOtherCharacters)
84{
85 TestInfo info;
86 info.setName("abCde", false);
87 ASSERT_EQ(info.name, "abCde");
88
89 TestInfo info2;
90 info2.setName("ab_de", false);
91 ASSERT_EQ(info2.name, "ab_de");
92
93 TestInfo info3;
94 info3.setName("ab9de", false);
95 ASSERT_EQ(info3.name, "ab9de");
96
97 TestInfo info4;
98 info4.setName("a_bCD12_ef", false);
99 ASSERT_EQ(info4.name, "a_bCD12_ef");
100
101 TestInfo info5;
102 info5.setName("a_._bC.D12_ef", false);
103 ASSERT_EQ(info5.name, "a_._bC.D12_ef");
104}
105
110TEST(StatsInfoTest, NameOldStyle)
111{
112 TestInfo info;
113 info.setName("InfoNameOldStyle", true);
114 ASSERT_EQ(info.name, "InfoNameOldStyle");
115
116 const auto &it = statistics::nameMap().find(info.name);
117 ASSERT_NE(it, statistics::nameMap().cend());
118 ASSERT_EQ(info.id, it->second->id);
119}
120
126TEST(StatsInfoTest, DISABLED_NameOldStyleTwice)
127{
128 TestInfo info;
129 std::string old_name = "InfoNameOldStyleTwice";
130 info.setName(old_name, true);
131 info.setName("InfoNameOldStyleTwice2", true);
132 ASSERT_EQ(info.name, "InfoNameOldStyleTwice2");
133
134 const auto &it = statistics::nameMap().find(old_name);
135 ASSERT_EQ(it, statistics::nameMap().cend());
136}
137
143TEST(StatsInfoTest, NameNewStyleDuplicate)
144{
145 TestInfo info;
146 std::string name = "InfoNameNewStyleDuplicate";
147 info.setName(name, false);
148 EXPECT_EQ(info.name, name);
149
150 TestInfo info2;
151 info2.setName(name, false);
152 ASSERT_EQ(info2.name, name);
153}
154
160TEST(StatsInfoTest, NameMixStyleDuplicate)
161{
162 TestInfo info;
163 std::string name = "InfoNameMixStyleDuplicate";
164 info.setName(name, false);
165 EXPECT_EQ(info.name, name);
166
167 TestInfo info2;
168 info2.setName(name, true);
169 ASSERT_EQ(info2.name, name);
170}
171
173TEST(StatsInfoTest, Separator)
174{
175 TestInfo info;
176
177 // Get current separator
178 auto separator = info.separatorString;
179
180 // Do the test with EXPECT_ so that we can restore the separator later
181 info.setSeparator(",-=-,");
182 EXPECT_EQ(statistics::Info::separatorString, ",-=-,");
183
184 // Restore separator
185 info.setSeparator(separator);
186}
187
189TEST(StatsInfoTest, Less)
190{
191 TestInfo info;
192 info.setName("Less1");
193 TestInfo info2;
194 info2.setName("Less2");
195
196 ASSERT_TRUE(statistics::Info::less(&info, &info2));
197 ASSERT_FALSE(statistics::Info::less(&info2, &info));
198}
199
201TEST(StatsInfoTest, BaseCheckInit)
202{
203 TestInfo info;
205 ASSERT_TRUE(info.baseCheck());
206}
207
209TEST(StatsInfoTest, BaseCheckDisplay)
210{
211 TestInfo info;
212 info.setName("BaseCheckDisplay");
214 ASSERT_TRUE(info.baseCheck());
215}
216
220TEST(StatsInfoTest, LessSub)
221{
222 TestInfo info;
223 info.setName("Less.Sub2.a");
224 TestInfo info2;
225 info2.setName("Less.Sub1.b");
226
227 ASSERT_TRUE(statistics::Info::less(&info2, &info));
228 ASSERT_FALSE(statistics::Info::less(&info, &info2));
229}
230
232TEST(StatsInfoDeathTest, NameEmpty)
233{
234 TestInfo info;
235 ASSERT_ANY_THROW(info.setName("", false));
236}
237
239TEST(StatsInfoDeathTest, NameSubEmpty)
240{
241 TestInfo info;
242 ASSERT_ANY_THROW(info.setName(".a", false));
243}
244
246TEST(StatsInfoDeathTest, NameSubEmpty2)
247{
248 TestInfo info;
249 ASSERT_ANY_THROW(info.setName("A.", false));
250}
251
253TEST(StatsInfoDeathTest, NameSubEmpty3)
254{
255 TestInfo info;
256 ASSERT_ANY_THROW(info.setName("a.b..c", false));
257}
258
260TEST(StatsInfoDeathTest, NameFirstCharacterNumber)
261{
262 TestInfo info;
263 ASSERT_ANY_THROW(info.setName("1", false));
264}
265
267TEST(StatsInfoDeathTest, NameFirstCharacterNumberSub)
268{
269 TestInfo info;
270 ASSERT_ANY_THROW(info.setName("A.1", false));
271}
272
274TEST(StatsInfoDeathTest, NameFirstCharacterSpecial)
275{
276 TestInfo info;
277 ASSERT_ANY_THROW(info.setName("!", false));
278}
279
284TEST(StatsInfoDeathTest, NameFirstCharacterSpecialSub)
285{
286 TestInfo info;
287 ASSERT_ANY_THROW(info.setName("A.!", false));
288}
289
291TEST(StatsInfoDeathTest, NameOtherCharacterSpecial)
292{
293 TestInfo info;
294 ASSERT_ANY_THROW(info.setName("ab!de", false));
295}
296
298TEST(StatsInfoDeathTest, NameOldStyleDuplicate)
299{
300 TestInfo info;
301 std::string name = "InfoNameOldStyleDuplicate";
302 info.setName(name, true);
303 EXPECT_EQ(info.name, name);
304
305 TestInfo info2;
306 ASSERT_ANY_THROW(info2.setName(name, true));
307}
308
310TEST(StatsInfoDeathTest, BaseCheckNoInit)
311{
312 TestInfo info;
313 ASSERT_ANY_THROW(info.baseCheck());
314}
315
317TEST(StatsInfoDeathTest, BaseCheckDisplayNoName)
318{
319 TestInfo info;
321 ASSERT_ANY_THROW(info.baseCheck());
322}
void visit(statistics::Output &visitor) override
Visitor entry for outputing statistics data.
Definition info.test.cc:47
bool zero() const override
Definition info.test.cc:46
bool check() const override
Check that this stat has been set up properly and is ready for use.
Definition info.test.cc:43
void reset() override
Reset the stat to the default state.
Definition info.test.cc:45
int value
Definition info.test.cc:41
void prepare() override
Prepare the stat for dumping.
Definition info.test.cc:44
void setName(const std::string &name, bool old_style=true)
Set the name of this statistic.
Definition info.cc:127
Flags flags
The formatting flags.
Definition info.hh:91
std::string name
The name of the stat.
Definition info.hh:83
static std::string separatorString
The separator string used for vectors, dist, etc.
Definition info.hh:85
bool baseCheck() const
Definition info.cc:172
static bool less(Info *stat1, Info *stat2)
Checks if the first stat's name is alphabetically less than the second.
Definition info.cc:146
void setSeparator(std::string _sep)
Definition info.hh:119
void set(Type mask)
Set all flag's bits matching the given mask.
Definition flags.hh:116
TEST(StatsInfoTest, NameNewStyle)
Test that a name is properly assigned under the new style.
Definition info.test.cc:51
const FlagsType init
This Stat is Initialized.
Definition info.hh:55
NameMapType & nameMap()
Definition info.cc:65
const FlagsType display
Print this stat.
Definition info.hh:57
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:01 for gem5 by doxygen 1.11.0