Daniel Carvalho has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/43007 )

Change subject: base-stats: Add unit test for Stats::Units
......................................................................

base-stats: Add unit test for Stats::Units

Add a unit test for base/stats/unit.hh.

Change-Id: I87f729928bb99c7f4d657bca0307955be933d3ed
Signed-off-by: Daniel R. Carvalho <[email protected]>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/43007
Tested-by: kokoro <[email protected]>
Maintainer: Giacomo Travaglini <[email protected]>
Reviewed-by: Hoa Nguyen <[email protected]>
---
M src/base/stats/SConscript
A src/base/stats/units.test.cc
2 files changed, 136 insertions(+), 0 deletions(-)

Approvals:
  Hoa Nguyen: Looks good to me, approved
  Giacomo Travaglini: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/base/stats/SConscript b/src/base/stats/SConscript
index 8f037ba..6981418 100644
--- a/src/base/stats/SConscript
+++ b/src/base/stats/SConscript
@@ -42,3 +42,4 @@

GTest('storage.test', 'storage.test.cc', '../debug.cc', '../str.cc', 'info.cc',
     'storage.cc', '../../sim/cur_tick.cc')
+GTest('units.test', 'units.test.cc')
diff --git a/src/base/stats/units.test.cc b/src/base/stats/units.test.cc
new file mode 100644
index 0000000..e95177d
--- /dev/null
+++ b/src/base/stats/units.test.cc
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2021 Daniel R. Carvalho
+ * 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.
+ */
+
+#include <gtest/gtest-spi.h>
+#include <gtest/gtest.h>
+
+#include "base/stats/units.hh"
+
+TEST(StatsUnitsTest, Cycle)
+{
+    Stats::Units::Cycle *unit = UNIT_CYCLE;
+    ASSERT_EQ(unit->getUnitString(), Stats::Units::Cycle::toString());
+}
+
+TEST(StatsUnitsTest, Tick)
+{
+    Stats::Units::Tick *unit = UNIT_TICK;
+    ASSERT_EQ(unit->getUnitString(), Stats::Units::Tick::toString());
+}
+
+TEST(StatsUnitsTest, Second)
+{
+    Stats::Units::Second *unit = UNIT_SECOND;
+    ASSERT_EQ(unit->getUnitString(), Stats::Units::Second::toString());
+}
+
+TEST(StatsUnitsTest, Bit)
+{
+    Stats::Units::Bit *unit = UNIT_BIT;
+    ASSERT_EQ(unit->getUnitString(), Stats::Units::Bit::toString());
+}
+
+TEST(StatsUnitsTest, Byte)
+{
+    Stats::Units::Byte *unit = UNIT_BYTE;
+    ASSERT_EQ(unit->getUnitString(), Stats::Units::Byte::toString());
+}
+
+TEST(StatsUnitsTest, Watt)
+{
+    Stats::Units::Watt *unit = UNIT_WATT;
+    ASSERT_EQ(unit->getUnitString(), Stats::Units::Watt::toString());
+}
+
+TEST(StatsUnitsTest, Joule)
+{
+    Stats::Units::Joule *unit = UNIT_JOULE;
+    ASSERT_EQ(unit->getUnitString(), Stats::Units::Joule::toString());
+}
+
+TEST(StatsUnitsTest, Volt)
+{
+    Stats::Units::Volt *unit = UNIT_VOLT;
+    ASSERT_EQ(unit->getUnitString(), Stats::Units::Volt::toString());
+}
+
+TEST(StatsUnitsTest, DegreeCelsius)
+{
+    Stats::Units::DegreeCelsius *unit = UNIT_CELSIUS;
+ ASSERT_EQ(unit->getUnitString(), Stats::Units::DegreeCelsius::toString());
+}
+
+TEST(StatsUnitsTest, Count)
+{
+    Stats::Units::Count *unit = UNIT_COUNT;
+    ASSERT_EQ(unit->getUnitString(), Stats::Units::Count::toString());
+}
+
+TEST(StatsUnitsTest, Rate1)
+{
+    Stats::Units::Rate<Stats::Units::Count, Stats::Units::Count> *unit =
+        UNIT_RATE(Stats::Units::Count, Stats::Units::Count);
+    ASSERT_EQ(unit->getUnitString(), "(Count/Count)");
+ ASSERT_EQ(unit->getUnitString(), (Stats::Units::Rate<Stats::Units::Count,
+        Stats::Units::Count>::toString()));
+}
+
+TEST(StatsUnitsTest, Rate2)
+{
+    Stats::Units::Rate<Stats::Units::Tick, Stats::Units::Second> *unit =
+        UNIT_RATE(Stats::Units::Tick, Stats::Units::Second);
+    ASSERT_EQ(unit->getUnitString(), "(Tick/Second)");
+ ASSERT_EQ(unit->getUnitString(), (Stats::Units::Rate<Stats::Units::Tick,
+        Stats::Units::Second>::toString()));
+}
+
+TEST(StatsUnitsTest, RateOfRates)
+{
+    typedef Stats::Units::Rate<Stats::Units::Bit, Stats::Units::Second>
+        BitPerSecond;
+    typedef Stats::Units::Rate<Stats::Units::Count, Stats::Units::Cycle>
+        CountPerCycle;
+    Stats::Units::Rate<BitPerSecond, CountPerCycle> *unit =
+        UNIT_RATE(BitPerSecond, CountPerCycle);
+    ASSERT_EQ(unit->getUnitString(), "((Bit/Second)/(Count/Cycle))");
+    ASSERT_EQ(unit->getUnitString(),
+        (Stats::Units::Rate<BitPerSecond, CountPerCycle>::toString()));
+}
+
+TEST(StatsUnitsTest, Ratio)
+{
+    Stats::Units::Ratio *unit = UNIT_RATIO;
+    ASSERT_EQ(unit->getUnitString(), Stats::Units::Ratio::toString());
+}
+
+TEST(StatsUnitsTest, Unspecified)
+{
+    Stats::Units::Unspecified *unit = UNIT_UNSPECIFIED;
+ ASSERT_EQ(unit->getUnitString(), Stats::Units::Unspecified::toString());
+}



1 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/43007
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I87f729928bb99c7f4d657bca0307955be933d3ed
Gerrit-Change-Number: 43007
Gerrit-PatchSet: 5
Gerrit-Owner: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Hoa Nguyen <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to