From 43fe81bc2c186e49b25762450003276a7ed0002d Mon Sep 17 00:00:00 2001 From: Dan Egnor Date: Fri, 7 May 2010 09:32:54 -0700 Subject: [PATCH] Add unit test for passing thread priority & cgroup through Binder. This test actually exposes some bugs -- the test passes as written, but certain parts are commented out with references to the bugs in question. Bug: 2665914 Bug: 2665954 Change-Id: I61220e0efadc4edbb6ad419d26fa1f0f50bbc24c --- core/tests/coretests/Android.mk | 4 +- core/tests/coretests/AndroidManifest.xml | 14 +- .../os/BinderThreadPriorityService.java | 62 ++++++++ .../android/os/BinderThreadPriorityTest.java | 146 ++++++++++++++++++ .../os/IBinderThreadPriorityService.aidl | 24 +++ 5 files changed, 239 insertions(+), 11 deletions(-) create mode 100644 core/tests/coretests/src/android/os/BinderThreadPriorityService.java create mode 100644 core/tests/coretests/src/android/os/BinderThreadPriorityTest.java create mode 100644 core/tests/coretests/src/android/os/IBinderThreadPriorityService.aidl diff --git a/core/tests/coretests/Android.mk b/core/tests/coretests/Android.mk index c067b8008a3e6..245c67cf40021 100644 --- a/core/tests/coretests/Android.mk +++ b/core/tests/coretests/Android.mk @@ -7,9 +7,9 @@ LOCAL_MODULE_TAGS := tests # Include all test java files. LOCAL_SRC_FILES := \ $(call all-java-files-under, src) \ + $(call all-Iaidl-files-under, src) \ $(call all-java-files-under, DisabledTestApp/src) \ - $(call all-java-files-under, EnabledTestApp/src) \ - src/android/os/IAidlTest.aidl + $(call all-java-files-under, EnabledTestApp/src) LOCAL_STATIC_JAVA_LIBRARIES += android-common diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml index 30855d17ffe3a..a77717fde8a64 100644 --- a/core/tests/coretests/AndroidManifest.xml +++ b/core/tests/coretests/AndroidManifest.xml @@ -1179,8 +1179,11 @@ - + android:process=":messengerService" /> + + + @@ -1198,13 +1201,6 @@ android:authorities="android.app.SuggestionProvider"> - - - - = -20; prio--) { + Process.setThreadPriority(prio); + + // Local + assertEquals(prio, Process.getThreadPriority(Process.myTid())); + assertEquals(expectedSchedulerGroup(prio), getSchedulerGroup()); + + // Remote + assertEquals(prio, mService.getThreadPriority()); + assertEquals(expectedSchedulerGroup(prio), mService.getThreadSchedulerGroup()); + } + } + + public void testCallBackFromServiceWithPriority() throws Exception { + for (int prio = -20; prio <= 19; prio++) { + final int expected = prio; + mService.setPriorityAndCallBack(prio, new ServiceStub() { + public void callBack(IBinderThreadPriorityService cb) { + assertEquals(expected, Process.getThreadPriority(Process.myTid())); + assertEquals(expectedSchedulerGroup(expected), getSchedulerGroup()); + } + }); + + assertEquals(mSavedPriority, Process.getThreadPriority(Process.myTid())); + + // BROKEN -- see bug 2665954 -- scheduler group doesn't get reset + // properly after a back-call with a different priority. + // assertEquals(expectedSchedulerGroup(mSavedPriority), getSchedulerGroup()); + } + } +} diff --git a/core/tests/coretests/src/android/os/IBinderThreadPriorityService.aidl b/core/tests/coretests/src/android/os/IBinderThreadPriorityService.aidl new file mode 100644 index 0000000000000..b30f04c8e2879 --- /dev/null +++ b/core/tests/coretests/src/android/os/IBinderThreadPriorityService.aidl @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.os; + +interface IBinderThreadPriorityService { + int getThreadPriority(); + String getThreadSchedulerGroup(); + void callBack(IBinderThreadPriorityService recurse); + void setPriorityAndCallBack(int priority, IBinderThreadPriorityService recurse); +}