Fork me on GitHub
侧边栏

google STS测试failed

【STS测试】failure of android.security.sts.KernelLtsTest#testRequiredKernelLts_WARN

总结:

获取以下信息:

  1. 安全补丁版本spl:2024-12-05
  2. kernel版本5.15.148
  3. 确认spl+6个月是否在【kernel-lifetimes.xml】中对应版本的生命周期之内,如果不在,则报出异常

逻辑:确保安全补丁版本+6个月之后,仍旧在kernel的生命周期之内。也就是kernel版本该升级就升级吧。

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

test_result.html

img

分析

STS套件中 StsHostTestCases.jar 反编译

将 android-sts\testcases\StsHostTestCases.jar 拖到jadx中,会自动反编译。

testRequiredKernelLts_WARN方法的反编译结果如下:

    @Test
    public void testRequiredKernelLts_WARN() throws Exception {
        Assume.assumeFalse("The kernel update requirement failure is acknowledged; overriding test failure.", this.acknowledgedFailure);
        try {
            if (getSpl().isBefore(SplUtils.localDateFromSplString("2024-05-01"))) {//
                testRequiredKernelLtsV1(true);
            }
            testRequiredKernelLtsV2(true, this.monthsWarning, getSpl(), getKernelVersion());//private int monthsWarning = 6;//How many months before enforcement to warn for
        } catch (AssertionError e) {
            AssertionError warning = new AssertionError("This device does not meet the current or upcoming LTS update requirements. This test is a warning that is autowaived in APA and no waiver request is necessary. Optionally, to override the warning, add this argument: --test-arg com.android.compatibility.common.tradefed.testtype.JarHostTest:set-option:android.security.sts.KernelLtsTest:acknowledge_kernel_update_requirement_warning_failure:true", e);
            warning.setStackTrace(new StackTraceElement[0]);
            throw warning;
        }
    }
    private static void testRequiredKernelLtsV2(boolean warn, int monthsWarning, LocalDate deviceSpl, KernelVersion deviceKernel) throws Exception {
        try {
            if (warn) {
                Assume.assumeThat("The LTS v2 policy does not begin warning until SPL 2024-05-01", deviceSpl, Matchers.greaterThanOrEqualTo(SplUtils.localDateFromSplString("2024-05-01")));
            } else {
                Assume.assumeThat("The LTS v2 policy does not begin enforcing until SPL 2024-11-05", deviceSpl, Matchers.greaterThanOrEqualTo(SplUtils.localDateFromSplString("2024-11-05")));
            }
            Assume.assumeThat(String.format("This non-GKI kernel (%s) does not require LTS updates.", deviceKernel.toString()), deviceKernel, Matchers.greaterThanOrEqualTo(new KernelVersion(5, 10, 0)));
            List<KernelRelease> kernelLifetimes = getKernelLifetimes(KernelLtsTest.class.getResourceAsStream("/kernel-lifetimes.xml"));
            TreeMap<Integer, LocalDate> sublevelEols = (TreeMap) kernelLifetimes.stream().filter(k -> {
                return k.kernelVersion.toStringShort().equals(deviceKernel.toStringShort());
            }).filter(k2 -> {
                if (deviceKernel.osRelease.isPresent()) {
                    return ((Integer) deviceKernel.osRelease.get()).equals(k2.kernelVersion.osRelease.get());
                }
                return true;
            }).collect(Collectors.toMap(k3 -> {
                return Integer.valueOf(k3.kernelVersion.subLevel);
            }, k4 -> {
                return k4.eol;
            }, (a, b) -> {
                if (a.compareTo((ChronoLocalDate) b) >= 0) {
                    return a;
                }
                return b;
            }, TreeMap::new));
            if (sublevelEols.isEmpty()) {
                Assert.fail(String.format("Invalid combination of kernel version %s and kernel branch Android version %s is not supported by LTS policy.", deviceKernel, ((Integer) deviceKernel.osRelease.get()).toString()));
            }
            Optional<Integer> floorSublevel = Optional.ofNullable(sublevelEols.floorKey(Integer.valueOf(deviceKernel.subLevel)));
            if (!floorSublevel.map(s -> {
                return new KernelVersion(deviceKernel.version, deviceKernel.patchLevel, ((Integer) floorSublevel.get()).intValue(), deviceKernel.osRelease);
            }).isPresent()) {
                Assert.fail(String.format("Device kernel version (%s) is too old to meet policy requirements and must be updated to a newer version", deviceKernel));
            }
            Optional<Map.Entry<Integer, LocalDate>> kernelEolEntry = Optional.ofNullable(sublevelEols.floorEntry(Integer.valueOf(deviceKernel.subLevel)));
            Optional map = kernelEolEntry.map(s2 -> {
                return (LocalDate) sublevelEols.floorEntry(Integer.valueOf(deviceKernel.subLevel)).getValue();
            });
            Assert.assertFalse(String.format("Cannot find EOL for min_android_release %s.", deviceKernel.osRelease.map((v0) -> {
                return v0.toString();
            }).orElse("unknown")), map.isEmpty());
            LocalDate asbKernelEol = ((LocalDate) map.get()).withDayOfMonth(5);
            if (warn) {
                LocalDate futureSpl = deviceSpl.plusMonths(monthsWarning);//spl+6个月
                if (deviceSpl.isBefore(asbKernelEol) && !futureSpl.isBefore(asbKernelEol)) {
                    Assert.assertTrue(String.format("WARNING, this kernel (%s) will reach end of life (%s) within %s months, enforced for device SPL (%s), for current device SPL (%s). https://docs.partner.android.com/security/bulletins/kernel-lts-faq", deviceKernel, SplUtils.format((LocalDate) map.get()), Integer.valueOf(deviceSpl.until((ChronoLocalDate) map.get()).getMonths()), SplUtils.format(asbKernelEol), SplUtils.format(deviceSpl)), false);
                }//异常log就是这里
            }
            Assert.assertThat(String.format("This kernel fails the kernel LTS update requirement. The kernel version (%s) is EOL (%s) for device SPL (%s) and needs to be updated. https://docs.partner.android.com/security/bulletins/kernel-lts-faq", deviceKernel, map.get(), SplUtils.format(deviceSpl)), deviceSpl, Matchers.lessThan(asbKernelEol));
        } catch (AssertionError | AssumptionViolatedException e) {
            e.setStackTrace(new StackTraceElement[0]);
            throw e;
        }
    }

getSpl()

获取安全补丁版本。

    private LocalDate getSpl() throws DeviceNotAvailableException {
        String deviceSplString = getDevice().getProperty("ro.build.version.security_patch");
        return SplUtils.localDateFromSplString(deviceSplString);
    }

log显示版本为:

12-24 17:18:59 D/NativeDevice: Using property ro.build.version.security_patch=2024-12-05 from cache.

getKernelVersion()

    private KernelVersion getKernelVersion() throws DeviceNotAvailableException {
        return KernelVersion.parse(getDevice().executeShellCommand("uname -r"));
    }

host log中显示kernel version为5.15.148,和test result中的log对上了。

12-24 17:19:46 D/RunUtil: Running command [adb, -s, f025a2e2, shell, uname, -a] with timeout: 2m 0s
12-24 17:19:46 I/InvocationExecution: Device f025a2e2 kernel information: 'Linux localhost 5.15.148-qki-consolidate-android13-8-ge0552cd669ef-dirty #1 SMP PREEMPT Sat Dec 21 02:40:09 UTC 2024 aarch64 Toybox'

kernel-lifetimes.xml

套件版本:Suite / Build 14_sts-r33 / 12602753

也就是说5.15.148的kernel版本,生命有效期在2025-05-01,而spl(2024-12-05)+ 6 个月已经超过了该有效期。需要升级啦!

img

posted @ 2025-06-05 09:57  yooooooo  阅读(55)  评论(0)    收藏  举报