libcutils test: make set_sched_policy optional

set_sched_policy checks that operations related to the kernel config
CONFIG_CGROUP_SCHEDTUNE are working properly, but this config is not
required so devices without this were failing the test.

This CL splits set_sched_policy into two tests so that the policy and
timerslack tests can be skipped individually when devices don't support
them.

Bug: 113185515, 112550681
Test: libcutils_test{32,64} now pass on aosp_x86_64 emulator
Change-Id: I31638b61e033f0c96b63428a8d27d27dbc36bce3
This commit is contained in:
David Pursell 2018-08-28 09:18:41 -07:00
parent 7bb77d321d
commit 6fd4b9b6b5

View file

@ -67,6 +67,21 @@ static void AssertPolicy(SchedPolicy expected_policy) {
}
TEST(SchedPolicy, set_sched_policy) {
if (!schedboost_enabled()) {
// schedboost_enabled() (i.e. CONFIG_CGROUP_SCHEDTUNE) is optional;
// it's only needed on devices using energy-aware scheduler.
GTEST_LOG_(INFO) << "skipping test that requires CONFIG_CGROUP_SCHEDTUNE";
return;
}
ASSERT_EQ(0, set_sched_policy(0, SP_BACKGROUND));
AssertPolicy(SP_BACKGROUND);
ASSERT_EQ(0, set_sched_policy(0, SP_FOREGROUND));
AssertPolicy(SP_FOREGROUND);
}
TEST(SchedPolicy, set_sched_policy_timerslack) {
if (!hasCapSysNice()) {
GTEST_LOG_(INFO) << "skipping test that requires CAP_SYS_NICE";
return;
@ -82,11 +97,9 @@ TEST(SchedPolicy, set_sched_policy) {
const unsigned int BG_FG_SLACK_FACTOR = 100;
ASSERT_EQ(0, set_sched_policy(0, SP_BACKGROUND));
AssertPolicy(SP_BACKGROUND);
auto bgSleepTime = medianSleepTime();
ASSERT_EQ(0, set_sched_policy(0, SP_FOREGROUND));
AssertPolicy(SP_FOREGROUND);
auto fgSleepTime = medianSleepTime();
ASSERT_GT(bgSleepTime, fgSleepTime * BG_FG_SLACK_FACTOR);
}