29#include <gtest/gtest-spi.h>
30#include <gtest/gtest.h>
39TEST(StatsGroupTest, ConstructNoParent)
46TEST(StatsGroupTest, AddGetSingleStatGroup)
53 ASSERT_EQ(root_map.size(), 1);
54 ASSERT_NE(root_map.find(
"Node1"), root_map.end());
60TEST(StatsGroupDeathTest, AddUniqueNameStatGroup)
70TEST(StatsGroupTest, AddNotUniqueNameAmongGroups)
82TEST(StatsGroupDeathTest, AddNull)
89TEST(StatsGroupDeathTest, AddItself)
96TEST(StatsGroupDeathTest, DISABLED_AddCycle)
107TEST(StatsGroupTest, AddGetMultipleStatGroup)
116 ASSERT_EQ(root_map.size(), 2);
117 ASSERT_NE(root_map.find(
"Node1"), root_map.end());
118 ASSERT_NE(root_map.find(
"Node2"), root_map.end());
125TEST(StatsGroupTest, ConstructCorrectlyAssigned)
135 ASSERT_EQ(node1.
getStatGroups().find(
"Node1_1")->second->getStatGroups(),
147TEST(StatsGroupTest, ConstructOneLevelLinear)
153 ASSERT_EQ(root_map.size(), 1);
154 ASSERT_NE(root_map.find(
"Node1"), root_map.end());
167TEST(StatsGroupTest, ConstructOneLevelOfTwoNodes)
174 ASSERT_EQ(root_map.size(), 2);
175 ASSERT_NE(root_map.find(
"Node1"), root_map.end());
176 ASSERT_NE(root_map.find(
"Node2"), root_map.end());
192TEST(StatsGroupTest, ConstructTwoLevelsLinear)
199 ASSERT_EQ(root_map.size(), 1);
200 ASSERT_NE(root_map.find(
"Node1"), root_map.end());
201 ASSERT_EQ(root_map.find(
"Node1_1"), root_map.end());
220TEST(StatsGroupTest, ConstructTwoLevelsUnbalancedTree)
230 ASSERT_EQ(root_map.size(), 2);
231 ASSERT_NE(root_map.find(
"Node1"), root_map.end());
232 ASSERT_NE(root_map.find(
"Node2"), root_map.end());
233 ASSERT_EQ(root_map.find(
"Node1_1"), root_map.end());
234 ASSERT_EQ(root_map.find(
"Node2_1"), root_map.end());
235 ASSERT_EQ(root_map.find(
"Node2_2"), root_map.end());
265 bool check()
const override {
return true; }
268 bool zero()
const override {
return false; }
273TEST(StatsGroupTest, AddGetStat)
277 ASSERT_EQ(info_vec.size(), 0);
280 info.
setName(
"InfoAddGetStat");
283 ASSERT_EQ(info_vec.size(), 1);
284 ASSERT_EQ(info_vec[0]->
name,
"InfoAddGetStat");
287 info2.
setName(
"InfoAddGetStat2");
290 ASSERT_EQ(info_vec.size(), 2);
291 ASSERT_EQ(info_vec[0]->
name,
"InfoAddGetStat");
292 ASSERT_EQ(info_vec[1]->
name,
"InfoAddGetStat2");
296TEST(StatsGroupDeathTest, MergeStatGroupNoGroup)
303TEST(StatsGroupDeathTest, MergeStatGroupItself)
310TEST(StatsGroupTest, MergeStatGroup)
316 info.
setName(
"InfoMergeStatGroup");
319 info2.
setName(
"InfoMergeStatGroup2");
324 ASSERT_EQ(info_vec.size(), 2);
325 ASSERT_EQ(info_vec[0]->
name,
"InfoMergeStatGroup");
326 ASSERT_EQ(info_vec[1]->
name,
"InfoMergeStatGroup2");
330TEST(StatsGroupDeathTest, MergeStatGroupMergedParent)
343TEST(StatsGroupTest, AddStatMergedParent)
353 info.
setName(
"AddStatMergedParent");
357 ASSERT_EQ(info_vec.size(), 1);
358 ASSERT_EQ(info_vec[0]->
name,
"AddStatMergedParent");
360 ASSERT_EQ(info_vec.size(), 0);
362 ASSERT_EQ(info_vec.size(), 1);
363 ASSERT_EQ(info_vec[0]->
name,
"AddStatMergedParent");
370TEST(StatsGroupTest, AddStatMergedParentMain)
378 info.
setName(
"AddStatMergedParentMain");
382 ASSERT_EQ(info_vec.size(), 1);
383 ASSERT_EQ(info_vec[0]->
name,
"AddStatMergedParentMain");
385 ASSERT_EQ(info_vec.size(), 0);
392TEST(StatsGroupTest, ConstructNoName)
398 info.
setName(
"InfoConstructNoName");
402 ASSERT_EQ(info_vec.size(), 1);
403 ASSERT_EQ(info_vec[0]->
name,
"InfoConstructNoName");
427 TestGroup root(
nullptr);
429 TestGroup node1(&root,
"Node1");
431 TestGroup node1_1(&node1,
"Node1_1");
433 TestGroup node1_2(&node1_1);
437 ASSERT_EQ(root.value, 1);
438 ASSERT_EQ(node1.value, 3);
439 ASSERT_EQ(node1_1.value, 4);
440 ASSERT_EQ(node1_2.value, 5);
448TEST(StatsGroupTest, ResetStats)
456 info.
setName(
"InfoResetStats");
461 info2.
setName(
"InfoResetStats2");
466 info3.
setName(
"InfoResetStats3");
471 info4.
setName(
"InfoResetStats4");
476 info5.
setName(
"InfoResetStats5");
481 ASSERT_EQ(info.
value, 1);
482 ASSERT_EQ(info2.
value, 0);
483 ASSERT_EQ(info3.
value, 0);
484 ASSERT_EQ(info4.
value, 0);
485 ASSERT_EQ(info5.
value, 0);
492TEST(StatsGroupTest, PreDumpStats)
502 preDumpStats()
override
509 TestGroup root(
nullptr);
511 TestGroup node1(&root,
"Node1");
513 TestGroup node1_1(&node1,
"Node1_1");
515 TestGroup node1_2(&node1_1);
518 node1.preDumpStats();
519 ASSERT_EQ(root.value, 1);
520 ASSERT_EQ(node1.value, 3);
521 ASSERT_EQ(node1_1.value, 4);
522 ASSERT_EQ(node1_2.value, 5);
526TEST(StatsGroupTest, ResolveStatNone)
531 info.
setName(
"InfoResolveStatNone");
534 auto info_found = root.
resolveStat(
"InfoResolveStatAny");
535 ASSERT_EQ(info_found,
nullptr);
539TEST(StatsGroupTest, ResolveStatSelf)
544 info.
setName(
"InfoResolveStatSelf");
548 info2.
setName(
"InfoResolveStatSelf2");
552 info3.
setName(
"InfoResolveStatSelf3");
555 auto info_found = root.
resolveStat(
"InfoResolveStatSelf");
556 ASSERT_NE(info_found,
nullptr);
557 ASSERT_EQ(info_found->name,
"InfoResolveStatSelf");
559 info_found = root.
resolveStat(
"InfoResolveStatSelf2");
560 ASSERT_NE(info_found,
nullptr);
561 ASSERT_EQ(info_found->name,
"InfoResolveStatSelf2");
563 info_found = root.
resolveStat(
"InfoResolveStatSelf3");
564 ASSERT_NE(info_found,
nullptr);
565 ASSERT_EQ(info_found->name,
"InfoResolveStatSelf3");
569TEST(StatsGroupTest, ResolveSubGroupStatFromParent)
577 info.
setName(
"InfoResolveSubGroupStatFromParent");
581 info2.
setName(
"InfoResolveSubGroupStatFromParent2");
585 info3.
setName(
"InfoResolveSubGroupStatFromParent3");
589 root.
resolveStat(
"Node1.InfoResolveSubGroupStatFromParent");
590 ASSERT_NE(info_found,
nullptr);
591 ASSERT_EQ(info_found->name,
"InfoResolveSubGroupStatFromParent");
594 "Node1.Node1_1.InfoResolveSubGroupStatFromParent2");
595 ASSERT_NE(info_found,
nullptr);
596 ASSERT_EQ(info_found->name,
"InfoResolveSubGroupStatFromParent2");
599 "Node1.Node1_1.Node1_1_1.InfoResolveSubGroupStatFromParent3");
600 ASSERT_NE(info_found,
nullptr);
601 ASSERT_EQ(info_found->name,
"InfoResolveSubGroupStatFromParent3");
605TEST(StatsGroupTest, ResolveStatSubGroupOnSubGroup)
611 info.
setName(
"InfoResolveStatSubGroupOnSubGroup");
614 auto info_found = node1.
resolveStat(
"InfoResolveStatSubGroupOnSubGroup");
615 ASSERT_EQ(info_found,
nullptr);
619TEST(StatsGroupTest, ResolveStatMerged)
625 info.
setName(
"InfoResolveStatMerged");
628 info2.
setName(
"InfoResolveStatMerged2");
633 auto info_found = root.
resolveStat(
"InfoResolveStatMerged");
634 ASSERT_NE(info_found,
nullptr);
635 ASSERT_EQ(info_found->name,
"InfoResolveStatMerged");
637 info_found = root.
resolveStat(
"InfoResolveStatMerged2");
638 ASSERT_NE(info_found,
nullptr);
639 ASSERT_EQ(info_found->name,
"InfoResolveStatMerged2");
643TEST(StatsGroupTest, ResolveStatMergedSubGroup)
650 info.
setName(
"InfoResolveStatMergedSubGroup");
656 auto info_found = root.
resolveStat(
"Node1.InfoResolveStatMergedSubGroup");
657 ASSERT_NE(info_found,
nullptr);
658 ASSERT_EQ(info_found->name,
"InfoResolveStatMergedSubGroup");
bool zero() const override
void reset() override
Reset the stat to the default state.
void visit(statistics::Output &visitor) override
Visitor entry for outputing statistics data.
void prepare() override
Prepare the stat for dumping.
bool check() const override
Check that this stat has been set up properly and is ready for use.
const Info * resolveStat(std::string name) const
Resolve a stat by its name within this group.
void mergeStatGroup(Group *block)
Merge the contents (stats & children) of a block to this block.
void setName(const std::string &name, bool old_style=true)
Set the name of this statistic.
TEST(StatsGroupTest, ConstructNoParent)
Test that the constructor without a parent doesn't do anything.
const std::map< std::string, Group * > & getStatGroups() const
Get all child groups associated with this object.
const std::vector< Info * > & getStats() const
Get all stats associated with this object.
virtual void regStats()
Callback to set stat parameters.
void addStatGroup(const char *name, Group *block)
Add a stat block as a child of this block.
virtual void preDumpStats()
Callback before stats are dumped.
void addStat(statistics::Info *info)
Register a stat with this group.
virtual void resetStats()
Callback to reset stats.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
const std::string & name()