// Ensure that basic list operations on ThreadExitFlags work. These are rarely // exercised in practice, since normally only one flag is registered at a time.
// Ensure that ScopedPriorityChange works correctly and interacts properly with // GetNicenessBeforeBoost().
TEST_F(ThreadTest, ScopedPriorityChangeTest) { // This is disabled on VM and SBC because they do not emulate Android's more generous // setpriority() handling.
TEST_DISABLED_ON_VM();
TEST_DISABLED_ON_SBC(); #ifdefined(ART_TARGET_ANDROID)
Thread* self = Thread::Current();
ASSERT_FALSE(self == nullptr);
self->TransitionFromSuspendedToRunnable(); // Start() releases mutator lock. bool started = Runtime::Current()->Start();
CHECK(started);
ScopedObjectAccess soa(self);
mirror::Object* peer = self->GetPeer();
ASSERT_FALSE(peer == nullptr); int initial_niceness = self->GetCachedNiceness(); // Set java.lang.Thread cached niceness and Linux niceness to match. // O.w. ScopedPriorityChage does nothing.
WellKnownClasses::java_lang_Thread_niceness->SetInt<false>(peer, 5); int ret = setpriority(PRIO_PROCESS, 0, 5);
ASSERT_EQ(ret, 0);
ASSERT_EQ(getpriority(PRIO_PROCESS, 0), 5);
ASSERT_EQ(self->GetCachedNiceness(), 5);
ASSERT_EQ(self->GetNicenessBeforeBoost(), Thread::kNotBoosted);
{
ScopedPriorityChange spc(self);
ASSERT_EQ(getpriority(PRIO_PROCESS, 0), 5);
ASSERT_EQ(self->GetNicenessBeforeBoost(), Thread::kNotBoosted);
spc.SetToNormalOrBetter();
ASSERT_EQ(getpriority(PRIO_PROCESS, 0), 0);
ASSERT_EQ(self->GetNicenessBeforeBoost(), 5);
{ // Nested invocations have no effect.
ScopedPriorityChange spc2(self);
spc2.SetToNormalOrBetter();
ASSERT_EQ(getpriority(PRIO_PROCESS, 0), 0);
ASSERT_EQ(self->GetNicenessBeforeBoost(), 5);
}
ASSERT_EQ(getpriority(PRIO_PROCESS, 0), 0);
ASSERT_EQ(self->GetNicenessBeforeBoost(), 5);
}
ASSERT_EQ(getpriority(PRIO_PROCESS, 0), 5);
ASSERT_EQ(self->GetNicenessBeforeBoost(), Thread::kNotBoosted);
WellKnownClasses::java_lang_Thread_niceness->SetInt<false>(peer, initial_niceness);
ret = setpriority(PRIO_PROCESS, 0, initial_niceness);
ASSERT_EQ(ret, 0); #endif// ART_TARGET_ANDROID // Else we are on host where we don't have permission to decrease niceness, // and thus can't effectively test.
}
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.