Methods Summary |
---|
public static java.lang.String | expectedSchedulerGroup(int prio)
return prio < Process.THREAD_PRIORITY_BACKGROUND ? "/" : "/bg_non_interactive";
|
public static java.lang.String | getSchedulerGroup()
String fn = "/proc/" + Process.myPid() + "/task/" + Process.myTid() + "/cgroup";
try {
String cgroup = FileUtils.readTextFile(new File(fn), 1024, null);
for (String line : cgroup.split("\n")) {
String fields[] = line.trim().split(":");
if (fields.length == 3 && fields[1].equals("cpu")) return fields[2];
}
} catch (IOException e) {
Log.e(TAG, "Can't read: " + fn, e);
}
return null; // Unknown
|
protected void | setUp()
super.setUp();
getContext().bindService(
new Intent(getContext(), BinderThreadPriorityService.class),
mConnection, Context.BIND_AUTO_CREATE);
synchronized (this) {
if (mService == null) {
try {
wait(30000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
assertNotNull("Gave up waiting for BinderThreadPriorityService", mService);
}
}
mSavedPriority = Process.getThreadPriority(Process.myTid());
Process.setThreadPriority(mSavedPriority); // To realign priority & cgroup, if needed
assertEquals(expectedSchedulerGroup(mSavedPriority), getSchedulerGroup());
Log.i(TAG, "Saved priority: " + mSavedPriority);
|
protected void | tearDown()
// HACK -- see bug 2665914 -- setThreadPriority() doesn't always set the
// scheduler group reliably unless we start out with background priority.
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
Process.setThreadPriority(mSavedPriority);
assertEquals(mSavedPriority, Process.getThreadPriority(Process.myTid()));
assertEquals(expectedSchedulerGroup(mSavedPriority), getSchedulerGroup());
getContext().unbindService(mConnection);
super.tearDown();
|
public void | testCallBackFromServiceWithPriority()
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());
}
|
public void | testPassPriorityToService()
for (int prio = 19; prio >= -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());
}
|