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 <odanrc@yahoo.com.br> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/38711 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Jason Lowe-Power <power.jg@gmail.com> Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Jason Lowe-Power <power.jg@gmail.com>
This commit is contained in:
committed by
Daniel Carvalho
parent
3f0cd995bf
commit
ccee328334
@@ -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<SimpleFlag *>(i->second);
|
||||
if (f && f->status())
|
||||
if (f && f->enabled())
|
||||
cprintf("%s\n", f->name());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<std::string, Flag *> FlagsMap;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
})
|
||||
;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user