// Tests may be run in parallel so this helper class ensures // that we generate a unique test flag each time to avoid // tests stepping on each other class TestFlag { public: // Takes control of the tmp_file pointer.
TestFlag(ScratchFile* tmp_file, FlagType flag_type) {
tmp_file_.reset(tmp_file);
class FlagsTests : public CommonRuntimeTest { protected:
FlagsTests() { this->use_boot_image_ = true; // Make the Runtime creation cheaper.
}
// We need to initialize the flag after the ScratchDir is created // but before we configure the runtime options (so that we can get // the right name for the config). // // So we do it in SetUpRuntimeOptions. virtualvoid SetUpRuntimeOptions(RuntimeOptions* options) {
test_flag_.reset(new TestFlag(new ScratchFile(), FlagType::kDeviceConfig));
CommonRuntimeTest::SetUpRuntimeOptions(options);
}
class FlagsTestsWithCmdLine : public FlagsTestsWithCmdLineBase { public:
FlagsTestsWithCmdLine() : FlagsTestsWithCmdLineBase(FlagType::kDeviceConfig) {
}
};
class FlagsTestsCmdLineOnly : public FlagsTestsWithCmdLineBase { public:
FlagsTestsCmdLineOnly() : FlagsTestsWithCmdLineBase(FlagType::kCmdlineOnly) {
}
};
// Validate that when no flag is set, the default is taken and none of the other // locations are populated
TEST_F(FlagsTests, ValidateDefaultValue) {
FlagBase::ReloadAllFlags("test");
// Validate that the server side config is picked when it is set.
TEST_F(FlagsTestsWithCmdLine, FlagsTestsGetValueServerSetting) { // On older releases (e.g. nougat) the system properties have very strict // limitations (e.g. for length) and setting the properties will fail. // On modern platforms this should not be the case, so condition the test // based on the success of setting the properties. if (!android::base::SetProperty(test_flag_->SystemProperty(), "2")) {
LOG(ERROR) << "Release does not support property setting, skipping test: "
<< test_flag_->SystemProperty(); return;
}
if (!android::base::SetProperty(test_flag_->ServerSetting(), "3")) {
LOG(ERROR) << "Release does not support property setting, skipping test: "
<< test_flag_->ServerSetting(); return;
}
// Validate that the system property value is picked when the server one is not set.
TEST_F(FlagsTestsWithCmdLine, FlagsTestsGetValueSysProperty) { if (!android::base::SetProperty(test_flag_->SystemProperty(), "2")) {
LOG(ERROR) << "Release does not support property setting, skipping test: "
<< test_flag_->SystemProperty(); return;
}
// Validate that the cmdline value is picked when no properties are set.
TEST_F(FlagsTestsWithCmdLine, FlagsTestsGetValueCmdline) {
FlagBase::ReloadAllFlags("test");
// Validate that cmdline only flags don't read system properties.
TEST_F(FlagsTestsCmdLineOnly, CmdlineOnlyFlags) { if (!android::base::SetProperty(test_flag_->SystemProperty(), "2")) {
LOG(ERROR) << "Release does not support property setting, skipping test: "
<< test_flag_->SystemProperty(); return;
}
if (!android::base::SetProperty(test_flag_->ServerSetting(), "3")) {
LOG(ERROR) << "Release does not support property setting, skipping test: "
<< test_flag_->ServerSetting(); return;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.