GTS 中 testNumberOfHeadedApplications fail 详解

阅读: 评论:0

GTS 中 testNumberOfHeadedApplications  fail 详解

GTS 中 testNumberOfHeadedApplications fail 详解

来源:

 

GTS 中 测试case armeabi-v7a GtsPlacementTestCases 的时候会出现下面的异常,本文总结一下。

对于第 1 个case,可以看 GTS 中testCoreGmsAppsPermissionsWhitelisted fail 详解,本文主要总结第 2 个case。

 

先来看下出现异常的 host log:

07-30 23:30:11 I/ModuleListener: [16/20] le.s.PreloadHeadedAppsTest#testNumberOfHeadedApplications fail:
java.lang.AssertionError: Number of total preloaded apps exceeded: actual 9 > max 7at org.junit.Assert.fail(Assert.java:88)at org.junit.Assert.assertTrue(Assert.java:41)le.s.PreloadHeadedAppsTest.assertAppCount(PreloadHeadedAppsTest.java:330)le.s.PreloadHeadedAppsTest.assertRulePasses(PreloadHeadedAppsTest.java:325)le.stNumberOfHeadedApplications(PreloadHeadedAppsTest.java:123)at flect.Method.invoke(Native Method)at org.del.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)at org.junit.del.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.del.FrameworkMethod.invokeExplosively(FrameworkMethod.java:52)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:148)at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:142)at urrent.FutureTask.run(FutureTask.java:266)at java.lang.Thread.run(Thread.java:764)

 

来看下code:

    @Testpublic void testNumberOfHeadedApplications() throws Exception {// 获取所有的launch appsSet<String> packageNames = getLaunchableApps();// 排除掉gms 的appsexemptWhitelistedGmsApps(packageNames);// 排除掉部分特殊categories 的appsexemptAppsByCategories(packageNames);// 排除特殊appsexemptAppsWithoutIntent(packageNames);Pair<Integer, Integer> numApps = countUserAndSystemApps(packageNames);assertRulePasses(calculatePreloadRule(), ((Integer) numApps.first).intValue(), ((Integer) numApps.second).intValue());}

如上面注释,首先会获取所有launch 的apps,也就是category 为 android.intent.category.LAUNCHER,详细看下面的code:

    private Set<String> getLaunchableApps() throws Exception {Intent intent = new Intent("android.intent.action.MAIN");intent.addCategory("android.intent.category.LAUNCHER");List<ResolveInfo> infos = this.mPackageManager.queryIntentActivities(intent, 0);Set<String> packageNames = new HashSet();for (ResolveInfo r : infos) {packageNames.add(r.activityInfo.packageName);}packageNames.addAll(getLauncherLikeApps());this.mReportLog.addValues(KEY_LAUNCHABLE_APPS, Arrays.asList((String[]) Array(new String[packageNames.size()])), ResultType.NEUTRAL, ResultUnit.NONE);String str = TAG;StringBuilder stringBuilder = new StringBuilder();stringBuilder.append("Launchable apps: ");stringBuilder.append(packageNames);Log.d(str, String());return packageNames;}

注意:

其中会有mReportLog 这个变量,后面会讲解到,目前先理解为会将一些log 信息存放到一个文件中,这里launch 的app,会存在在key 为launchable_apps 下面。

 

接着上面code,获取launch 的apps 之后,会将一些特殊的apps 从list 中remove 掉,这些包括几个gms apps、特殊的categories的apps、特殊apps 。最终的packageNames 会经过函数countUserAndSystemApps() 计算出user apps 和system apps,这个计算函数是这个case 的关键了,如果计算出错,那么很容易出现本文说的这个case fail 现象。来看下code:

    private Pair<Integer, Integer> countUserAndSystemApps(Set<String> packageNames) {List user = new ArrayList();List system = new ArrayList();for (String name : packageNames) {if (PackageUtil.isSystemApp(name)) {system.add(name);} else {user.add(name);}}this.mReportLog.addValues(USER_APPS_KEY, user, ResultType.NEUTRAL, ResultUnit.NONE);String str = TAG;StringBuilder stringBuilder = new StringBuilder();stringBuilder.append("User apps: ");stringBuilder.append(user);Log.d(str, String());this.mReportLog.addValues(SYSTEM_APPS_KEY, system, ResultType.NEUTRAL, ResultUnit.NONE);str = TAG;stringBuilder = new StringBuilder();stringBuilder.append("System apps: ");stringBuilder.append(system);Log.d(str, String());return new Pair(Integer.valueOf(user.size()), Integer.valueOf(system.size()));}

主要通过PackageUtil。isSystemApp() 来确认是否为system apps,并将这个log 保存在mReportLog 中,key 分别是user_apps 和system_apps。

 

接着看code,在计算完成后会将计算的结果给numApps:

Pair<Integer, Integer> numApps = countUserAndSystemApps(packageNames);

然后开始进入assert:

assertRulePasses(calculatePreloadRule(), ((Integer) numApps.first).intValue(), ((Integer) numApps.second).intValue());
    private void assertRulePasses(PreloadRule rule, int numUser, int numSystem) throws Exception {if (rule.mShouldCountSystem) {assertAppCount(APP_COUNT_EXCEED_MSG, "system", numSystem, rule.mNumSystem);}assertAppCount(APP_COUNT_EXCEED_MSG, "total", numUser + numSystem, rule.numTotal());}

这个assert 为false 就出现了最开始的log,要求的是numUser + numSystem 必须要 <= rule.numTotal()

而这里的rule 是通过上面的calculatePreloadRule() 得来的:

    private PreloadRule calculatePreloadRule() throws Exception {List<String> sizeLimits = Values(STORAGE_LIMIT_SIZES_KEY);List<String> maxUserApps = Values(MAX_ALLOWED_USER_APPS_KEY);List<String> maxSystemApps = Values(MAX_ALLOWED_SYSTEM_APPS_KEY);StorageStatsManager ssm = (StorageStatsManager) SystemService(StorageStatsManager.class);Assert.assertNotNull("StorageStatsManager should not be null", ssm);long totalBytesOnVolume = TotalBytes(StorageManager.UUID_DEFAULT);boolean shouldCountSystem = false;int i = 0;while (i < sizeLimits.size() && totalBytesOnVolume > new Long((String) (i)).longValue()) {i++;}if (i == sizeLimits.size()) {i--;shouldCountSystem = true;}this.mReportLog.addValue(KEY_SIZE_LIMIT, (String) (i), ResultType.NEUTRAL, ResultUnit.NONE);return new PreloadRule(Integer.valueOf((String) (i)).intValue(), Integer.valueOf((String) (i)).intValue(), shouldCountSystem);}

这段code 大致就是说上面获取的user apps 和system apps 必须要跟GTS 的配置信息一致。配置信息如下:

    <entry key="max_allowed_user_apps"><value>0</value><value>0</value><value>7</value></entry><entry key="max_allowed_system_apps"><value>7</value><value>7</value><value>7</value></entry>

显然,system apps 要求是7个,而这个assert 也是true的(不然assertRulePasses()最开始的case 就会报错),结合log 可以判断出user apps 要求是 0 个,但是countUserAndSystemApps() 计算出来的却是 2 个。这多出来的 2 个就是该case 出现fail 的根本原因。

 

如何知道多出来的 2 个user apps 是什么呢?这就要看mReportLog 中存了什么了,来看下这个变量是什么:

    private DeviceReportLog mReportLog;
    public void setUp() throws Exception {this.mContext = Instrumentation().getTargetContext();this.mPackageManager = PackageManager();this.mDcds = new DynamicConfigDeviceSide("GtsPlacementTestCases");this.mReportLog = new DeviceReportLog("GtsPlacementTestCases", STREAM_NAME);}
    public DeviceReportLog(String reportLogName, String streamName) {this(reportLogName, streamName, new ExternalStorageDirectory(), "report-log-files"));}public DeviceReportLog(String reportLogName, String streamName, File logDirectory) {super(reportLogName, streamName);try {if (ExternalStorageState().equals("mounted")) {if (ists() || logDirectory.mkdirs()) {if (ists()) {if (logDirectory.isDirectory()) {}}StringBuilder stringBuilder = new StringBuilder();stringBuilder.append(this.mReportLogName);stringBuilder.append(".reportlog.json");this.store = new ReportLogDeviceInfoStore(new File(logDirectory, String()), this.mStreamName);this.store.open();return;}throw new IOException("Cannot create directory for device info files");}throw new IOException("External storage is not mounted");} catch (Exception e) {Log.e(TAG, "Could not create report log file.", e);}}

code 比较简单,最后就是保存在/sdcard/portlog.json 中(最后的测试报告里面也应该会有这个文件),大概如下:

    "launchable_apps":[&#le.ssaging",&#lite","com.alfacart.apps",&#le.utube.mango",&#alfamind","com.fajarsiddiq.snapshop","com.qiku.android.filebrowser","com.android.music",&#lkomselcm","com.ime","com.acts","com.alfamart.alfagift","com.finallyclean.booster.cleaner","com.caf.fmradio",&#le.android.apps.searchlite","com.android.vending","com.hola.weather","com.android.gallery3d","com.android.calculator2","com.android.chrome","com.android.video",&#le.android.apps.mapslite","com.android.camera","com.mhn.ponta",&#le.android.apps.assistant","com.android.settings","com.qiku.android.launcher3","com.android.soundrecorder",&#le.android.calendar"],"user_apps":["com.fajarsiddiq.snapshop",&#lkomselcm","com.alfamart.alfagift","com.mhn.ponta"],"system_apps":["com.alfacart.apps",&#alfamind","com.qiku.android.filebrowser","com.finallyclean.booster.cleaner","com.android.video"],"size_limit":"8000000000"}]}

或多或少是可以看出点东西,例如上面的log 文件就可以看出有几个user apps,这个是需要确认为何出现?什么时候安装?

 

结论:

通过测试报告中的portlog.json 文件分析user_apps 和system_apps 是否与dynamic 文件中配置相符。

 

更多GTS 测试的case 见:

CTS/GTS 常见问题汇总

 

 

 

本文发布于:2024-02-04 23:34:38,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170718925560774.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23