From ccee3283341454c4480eadd568b010857a044d1a Mon Sep 17 00:00:00 2001 From: "Daniel R. Carvalho" Date: Fri, 25 Dec 2020 17:49:09 -0300 Subject: [PATCH] base: Rename Flag status to enabled The semantic of "The status of a flag is true/false" may be confusing. Rename `status` to `enabled`, so that queries become "Is this flag enabled?". Change-Id: I8cdd76766d80d65007a9f204abcf71b18211ab42 Signed-off-by: Daniel R. Carvalho Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/38711 Tested-by: kokoro Reviewed-by: Jason Lowe-Power Reviewed-by: Andreas Sandberg Maintainer: Jason Lowe-Power --- src/base/debug.cc | 6 +- src/base/debug.hh | 16 ++-- src/base/debug.test.cc | 148 ++++++++++++++++++----------------- src/python/pybind11/debug.cc | 6 +- 4 files changed, 89 insertions(+), 87 deletions(-) diff --git a/src/base/debug.cc b/src/base/debug.cc index 83a446124..925c16ff5 100644 --- a/src/base/debug.cc +++ b/src/base/debug.cc @@ -137,13 +137,13 @@ CompoundFlag::disable() } bool -CompoundFlag::status() const +CompoundFlag::enabled() const { if (_kids.empty()) return false; for (auto& k : _kids) { - if (!k->status()) + if (!k->enabled()) return false; } @@ -188,7 +188,7 @@ dumpDebugFlags() FlagsMap::iterator end = allFlags().end(); for (; i != end; ++i) { SimpleFlag *f = dynamic_cast(i->second); - if (f && f->status()) + if (f && f->enabled()) cprintf("%s\n", f->name()); } } diff --git a/src/base/debug.hh b/src/base/debug.hh index 4226de7a7..2d463814b 100644 --- a/src/base/debug.hh +++ b/src/base/debug.hh @@ -70,9 +70,9 @@ class Flag virtual void enable() = 0; virtual void disable() = 0; - virtual bool status() const = 0; + virtual bool enabled() const = 0; - operator bool() const { return status(); } + operator bool() const { return enabled(); } static void globalEnable(); static void globalDisable(); @@ -82,17 +82,17 @@ class SimpleFlag : public Flag { protected: bool _tracing = false; // tracing is enabled and flag is on - bool _status = false; // flag status + bool _enabled = false; // flag enablement status - void sync() override { _tracing = _globalEnable && _status; } + void sync() override { _tracing = _globalEnable && _enabled; } public: SimpleFlag(const char *name, const char *desc) : Flag(name, desc) {} - bool status() const override { return _tracing; } + bool enabled() const override { return _tracing; } - void enable() override { _status = true; sync(); } - void disable() override { _status = false; sync(); } + void enable() override { _enabled = true; sync(); } + void disable() override { _enabled = false; sync(); } }; class CompoundFlag : public Flag @@ -113,7 +113,7 @@ class CompoundFlag : public Flag void enable() override; void disable() override; - bool status() const override; + bool enabled() const override; }; typedef std::map FlagsMap; diff --git a/src/base/debug.test.cc b/src/base/debug.test.cc index b1c013028..3f7b2f42d 100644 --- a/src/base/debug.test.cc +++ b/src/base/debug.test.cc @@ -61,114 +61,116 @@ TEST(DebugFlagDeathTest, UniqueNames) } /** Test enabling and disabling simple flags, as well as the global enabler. */ -TEST(DebugSimpleFlagTest, Status) +TEST(DebugSimpleFlagTest, Enabled) { Debug::Flag::globalDisable(); - Debug::SimpleFlag flag("SimpleFlagStatusTest", ""); + Debug::SimpleFlag flag("SimpleFlagEnabledTest", ""); // By default flags are initialized disabled - ASSERT_FALSE(flag.status()); + ASSERT_FALSE(flag.enabled()); // Flags must be globally enabled before individual flags are enabled flag.enable(); - ASSERT_FALSE(flag.status()); + ASSERT_FALSE(flag.enabled()); Debug::Flag::globalEnable(); - ASSERT_TRUE(flag.status()); + ASSERT_TRUE(flag.enabled()); // Verify that the global enabler works Debug::Flag::globalDisable(); - ASSERT_FALSE(flag.status()); + ASSERT_FALSE(flag.enabled()); Debug::Flag::globalEnable(); - ASSERT_TRUE(flag.status()); + ASSERT_TRUE(flag.enabled()); // Test disabling the flag with global enabled flag.disable(); - ASSERT_FALSE(flag.status()); + ASSERT_FALSE(flag.enabled()); } /** - * Tests that manipulate the status of the compound flag to change the status - * of the kids. + * Tests that manipulate the enablement status of the compound flag to change + * the corresponding status of the kids. */ -TEST(DebugCompoundFlagTest, Status) +TEST(DebugCompoundFlagTest, Enabled) { Debug::Flag::globalDisable(); - Debug::SimpleFlag flag_a("CompoundFlagStatusTestKidA", ""); - Debug::SimpleFlag flag_b("CompoundFlagStatusTestKidB", ""); - Debug::CompoundFlag flag("CompoundFlagStatusTest", "", {&flag_a, &flag_b}); + Debug::SimpleFlag flag_a("CompoundFlagEnabledTestKidA", ""); + Debug::SimpleFlag flag_b("CompoundFlagEnabledTestKidB", ""); + Debug::CompoundFlag flag("CompoundFlagEnabledTest", "", + {&flag_a, &flag_b}); // By default flags are initialized disabled - ASSERT_FALSE(flag.status()); + ASSERT_FALSE(flag.enabled()); // Flags must be globally enabled before individual flags are enabled flag.enable(); - ASSERT_FALSE(flag_a.status()); - ASSERT_FALSE(flag_b.status()); - ASSERT_FALSE(flag.status()); + ASSERT_FALSE(flag_a.enabled()); + ASSERT_FALSE(flag_b.enabled()); + ASSERT_FALSE(flag.enabled()); Debug::Flag::globalEnable(); for (auto &kid : flag.kids()) { - ASSERT_TRUE(kid->status()); + ASSERT_TRUE(kid->enabled()); } - ASSERT_TRUE(flag_a.status()); - ASSERT_TRUE(flag_b.status()); - ASSERT_TRUE(flag.status()); + ASSERT_TRUE(flag_a.enabled()); + ASSERT_TRUE(flag_b.enabled()); + ASSERT_TRUE(flag.enabled()); // Test disabling the flag with global enabled flag.disable(); for (auto &kid : flag.kids()) { - ASSERT_FALSE(kid->status()); + ASSERT_FALSE(kid->enabled()); } - ASSERT_FALSE(flag_a.status()); - ASSERT_FALSE(flag_b.status()); - ASSERT_FALSE(flag.status()); + ASSERT_FALSE(flag_a.enabled()); + ASSERT_FALSE(flag_b.enabled()); + ASSERT_FALSE(flag.enabled()); } -/** Test that the conversion operator matches the status. */ +/** Test that the conversion operator matches the enablement status. */ TEST(DebugFlagTest, ConversionOperator) { Debug::Flag::globalEnable(); Debug::SimpleFlag flag("FlagConversionOperatorTest", ""); - ASSERT_EQ(flag, flag.status()); + ASSERT_EQ(flag, flag.enabled()); flag.enable(); - ASSERT_EQ(flag, flag.status()); + ASSERT_EQ(flag, flag.enabled()); flag.disable(); } /** - * Tests that manipulate the kids to change the status of the compound flag. + * Tests that manipulate the kids to change the enablement status of the + * compound flag. */ -TEST(DebugCompoundFlagTest, StatusKids) +TEST(DebugCompoundFlagTest, EnabledKids) { Debug::Flag::globalEnable(); - Debug::SimpleFlag flag_a("CompoundFlagStatusKidsTestKidA", ""); - Debug::SimpleFlag flag_b("CompoundFlagStatusKidsTestKidB", ""); - Debug::CompoundFlag flag("CompoundFlagStatusKidsTest", "", + Debug::SimpleFlag flag_a("CompoundFlagEnabledKidsTestKidA", ""); + Debug::SimpleFlag flag_b("CompoundFlagEnabledKidsTestKidB", ""); + Debug::CompoundFlag flag("CompoundFlagEnabledKidsTest", "", {&flag_a, &flag_b}); // Test enabling only flag A - ASSERT_FALSE(flag_a.status()); - ASSERT_FALSE(flag_b.status()); - ASSERT_FALSE(flag.status()); + ASSERT_FALSE(flag_a.enabled()); + ASSERT_FALSE(flag_b.enabled()); + ASSERT_FALSE(flag.enabled()); flag_a.enable(); - ASSERT_TRUE(flag_a.status()); - ASSERT_FALSE(flag_b.status()); - ASSERT_FALSE(flag.status()); + ASSERT_TRUE(flag_a.enabled()); + ASSERT_FALSE(flag_b.enabled()); + ASSERT_FALSE(flag.enabled()); // Test that enabling both flags enables the compound flag - ASSERT_TRUE(flag_a.status()); - ASSERT_FALSE(flag_b.status()); - ASSERT_FALSE(flag.status()); + ASSERT_TRUE(flag_a.enabled()); + ASSERT_FALSE(flag_b.enabled()); + ASSERT_FALSE(flag.enabled()); flag_b.enable(); - ASSERT_TRUE(flag_a.status()); - ASSERT_TRUE(flag_b.status()); - ASSERT_TRUE(flag.status()); + ASSERT_TRUE(flag_a.enabled()); + ASSERT_TRUE(flag_b.enabled()); + ASSERT_TRUE(flag.enabled()); // Test that disabling one of the flags disables the compound flag flag_a.disable(); - ASSERT_FALSE(flag_a.status()); - ASSERT_TRUE(flag_b.status()); - ASSERT_FALSE(flag.status()); + ASSERT_FALSE(flag_a.enabled()); + ASSERT_TRUE(flag_b.enabled()); + ASSERT_FALSE(flag.enabled()); } /** Search for existent and non-existent flags. */ @@ -182,19 +184,19 @@ TEST(DebugFlagTest, FindFlag) // enabled too Debug::Flag *flag; EXPECT_TRUE(flag = Debug::findFlag("FlagFindFlagTestA")); - ASSERT_FALSE(flag_a.status()); + ASSERT_FALSE(flag_a.enabled()); flag->enable(); - ASSERT_TRUE(flag_a.status()); + ASSERT_TRUE(flag_a.enabled()); EXPECT_TRUE(flag = Debug::findFlag("FlagFindFlagTestB")); - ASSERT_FALSE(flag_b.status()); + ASSERT_FALSE(flag_b.enabled()); flag->enable(); - ASSERT_TRUE(flag_b.status()); + ASSERT_TRUE(flag_b.enabled()); // Search for a non-existent flag EXPECT_FALSE(Debug::findFlag("FlagFindFlagTestC")); } -/** Test changing flag status. */ +/** Test changing flag enabled. */ TEST(DebugFlagTest, ChangeFlag) { Debug::Flag::globalEnable(); @@ -203,24 +205,24 @@ TEST(DebugFlagTest, ChangeFlag) // Enable the found flags and verify that the original flags are // enabled too - ASSERT_FALSE(flag_a.status()); + ASSERT_FALSE(flag_a.enabled()); EXPECT_TRUE(Debug::changeFlag("FlagChangeFlagTestA", true)); - ASSERT_TRUE(flag_a.status()); + ASSERT_TRUE(flag_a.enabled()); EXPECT_TRUE(Debug::changeFlag("FlagChangeFlagTestA", false)); - ASSERT_FALSE(flag_a.status()); + ASSERT_FALSE(flag_a.enabled()); // Disable and enable a flag - ASSERT_FALSE(flag_b.status()); + ASSERT_FALSE(flag_b.enabled()); EXPECT_TRUE(Debug::changeFlag("FlagChangeFlagTestB", false)); - ASSERT_FALSE(flag_b.status()); + ASSERT_FALSE(flag_b.enabled()); EXPECT_TRUE(Debug::changeFlag("FlagChangeFlagTestB", true)); - ASSERT_TRUE(flag_b.status()); + ASSERT_TRUE(flag_b.enabled()); // Change a non-existent flag ASSERT_FALSE(Debug::changeFlag("FlagChangeFlagTestC", true)); } -/** Test changing flag status with aux functions. */ +/** Test changing flag enabled with aux functions. */ TEST(DebugFlagTest, SetClearDebugFlag) { Debug::Flag::globalEnable(); @@ -228,18 +230,18 @@ TEST(DebugFlagTest, SetClearDebugFlag) Debug::SimpleFlag flag_b("FlagSetClearDebugFlagTestB", ""); // Enable and disable a flag - ASSERT_FALSE(flag_a.status()); + ASSERT_FALSE(flag_a.enabled()); setDebugFlag("FlagSetClearDebugFlagTestA"); - ASSERT_TRUE(flag_a.status()); + ASSERT_TRUE(flag_a.enabled()); clearDebugFlag("FlagSetClearDebugFlagTestA"); - ASSERT_FALSE(flag_a.status()); + ASSERT_FALSE(flag_a.enabled()); // Disable and enable a flag - ASSERT_FALSE(flag_b.status()); + ASSERT_FALSE(flag_b.enabled()); clearDebugFlag("FlagSetClearDebugFlagTestB"); - ASSERT_FALSE(flag_b.status()); + ASSERT_FALSE(flag_b.enabled()); setDebugFlag("FlagSetClearDebugFlagTestB"); - ASSERT_TRUE(flag_b.status()); + ASSERT_TRUE(flag_b.enabled()); // Change a non-existent flag setDebugFlag("FlagSetClearDebugFlagTestC"); @@ -257,7 +259,7 @@ TEST(DebugFlagTest, NoDumpDebugFlags) dumpDebugFlags(); std::string output = testing::internal::GetCapturedStdout(); EXPECT_EQ(output, ""); - ASSERT_FALSE(flag.status()); + ASSERT_FALSE(flag.enabled()); } /** Test dumping enabled debug flags with a larger set of flags. */ @@ -275,11 +277,11 @@ TEST(DebugFlagTest, DumpDebugFlags) {&flag_e}); // Enable a few flags - ASSERT_FALSE(flag_a.status()); - ASSERT_FALSE(flag_b.status()); - ASSERT_FALSE(flag_c.status()); - ASSERT_FALSE(flag_d.status()); - ASSERT_FALSE(flag_e.status()); + ASSERT_FALSE(flag_a.enabled()); + ASSERT_FALSE(flag_b.enabled()); + ASSERT_FALSE(flag_c.enabled()); + ASSERT_FALSE(flag_d.enabled()); + ASSERT_FALSE(flag_e.enabled()); flag_a.enable(); flag_c.enable(); compound_flag_b.enable(); diff --git a/src/python/pybind11/debug.cc b/src/python/pybind11/debug.cc index 84673f1f3..1284d56b8 100644 --- a/src/python/pybind11/debug.cc +++ b/src/python/pybind11/debug.cc @@ -94,9 +94,9 @@ pybind_init_debug(py::module &m_native) .def_property_readonly("desc", &Debug::Flag::desc) .def("enable", &Debug::Flag::enable) .def("disable", &Debug::Flag::disable) - .def_property("status", + .def_property("enabled", [](const Debug::Flag *flag) { - return flag->status(); + return flag->enabled(); }, [](Debug::Flag *flag, bool state) { if (state) { @@ -106,7 +106,7 @@ pybind_init_debug(py::module &m_native) } }) .def("__bool__", [](const Debug::Flag *flag) { - return flag->status(); + return flag->enabled(); }) ; -- 2.30.2