关于Cts中一个Thread问题

路人戊戌乙亥 CSDN会员 路人戊戌乙亥 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
4.1.4. Cts测试有一项为testCheckForDuplicateOutput
源码在这里:http://xdecay.com/docs/android-sdk/cts/tests/tests/security/d0/db5/_cloned_secure_random_test_8java_source.php

测试的原理是:不停的创建和关闭进程,直到出现两个Pid相同的进程。

因为Linux的PId数是有限的,系统测试的前提是出现两个Pid相同的进程。
循环过程如下:
a). 创建进程A, 记录下A的Pid为pid-1; 然后立即Kill pid-1;
b). 创建进程B, 记录下B的Pid为pid-2; 然后立即Kill pid-2;
……
直到再次出现pid-1的进程号。

根据鸽巢原理(n个盒子装n+1个球,必然出现一个盒子有两个球的现象),当循环下去必然会再次出现pid-1。

CTS 测试为了加快测试速率,调用了如下的函数(wastePids):
比如 第一次是pid-1, 多次循环之后,出现pid-5000,那么就调用wastePids(1,5000)

源码如下:
    /**
* This is an attempt to get the PIDs to roll over faster. Threads use up
* PIDs on Android and spawning a new thread is much faster than having
* another service spawned as we are doing in this test.
*/
private static void wastePids(int firstPid, int previousPid) {
int distance = (firstPid - previousPid + MAX_PID) % MAX_PID;

// Don't waste PIDs if we're close to wrap-around to improve odds of
// collision.
if ((distance < PID_WASTING_SKIP_LOWER) || (MAX_PID - distance < PID_WASTING_SKIP_UPPER)) {
return;
}

for (int i = 0; i < distance; i++) {
Thread t = new Thread();
t.start();
}
}


按注释翻译而言,应该是通过创建Thread ,将这些Pid占用掉,让Pid尽快复用。

现在不明白的是:这个

        
for (int i = 0; i < distance; i++) {
Thread t = new Thread();
t.start();
}


它会消耗PID吗? Thread怎么可能消耗Pid, 还是我理解错了?
...全文
评论 4
收藏 已收藏
分享
返回顶部
路人戊戌乙亥 CSDN会员
Android 80,490 成员 91,375 内容