diff options
author | Christopher Dombroski <cdombroski@google.com> | 2022-02-02 11:47:37 -0800 |
---|---|---|
committer | Christopher Dombroski <cdombroski@google.com> | 2022-02-02 11:47:37 -0800 |
commit | 49f5f6df0e04d0b0d6b224389392f0a0353b73fe (patch) | |
tree | 6c5af010403fe5f3939c108e067a24c1c9b40de7 | |
parent | f26df263bd2ddc063422a26c3c4fdc716d8c8c81 (diff) | |
download | platform_testing-49f5f6df0e04d0b0d6b224389392f0a0353b73fe.tar.gz |
STS split kernel and platfom SPL for dynamic skips
Bug: 217276391
Test: run STS
Change-Id: I09719eca84271fed302e7cf9caddb5387c83e6d7
4 files changed, 151 insertions, 17 deletions
diff --git a/libraries/sts-common-util/device-side/src/com/android/sts/common/util/StsExtraBusinessLogicTestCase.java b/libraries/sts-common-util/device-side/src/com/android/sts/common/util/StsExtraBusinessLogicTestCase.java index 0eede1609..f50c60702 100644 --- a/libraries/sts-common-util/device-side/src/com/android/sts/common/util/StsExtraBusinessLogicTestCase.java +++ b/libraries/sts-common-util/device-side/src/com/android/sts/common/util/StsExtraBusinessLogicTestCase.java @@ -16,13 +16,14 @@ package com.android.sts.common.util; -import com.android.compatibility.common.util.ExtraBusinessLogicTestCase; - import android.os.Build; import android.util.Log; import androidx.test.InstrumentationRegistry; +import com.android.compatibility.common.util.ExtraBusinessLogicTestCase; +import com.android.compatibility.common.util.PropertyUtil; + import org.junit.Rule; import org.junit.runner.Description; @@ -33,6 +34,7 @@ import java.util.List; public class StsExtraBusinessLogicTestCase extends ExtraBusinessLogicTestCase implements StsLogic { private LocalDate deviceSpl = null; + private LocalDate kernelSpl = null; @Rule public DescriptionProvider descriptionProvider = new DescriptionProvider(); protected StsExtraBusinessLogicTestCase() { @@ -41,6 +43,7 @@ public class StsExtraBusinessLogicTestCase extends ExtraBusinessLogicTestCase im @Override public List<String> getExtraBusinessLogics() { + // set in test/sts/tools/sts-tradefed/res/config/sts-base-dynamic-*.xml String stsDynamicPlan = InstrumentationRegistry.getArguments().getString("sts-dynamic-plan"); switch (stsDynamicPlan) { @@ -60,13 +63,36 @@ public class StsExtraBusinessLogicTestCase extends ExtraBusinessLogicTestCase im } @Override - public LocalDate getDeviceSpl() { + public LocalDate getPlatformSpl() { if (deviceSpl == null) { deviceSpl = SplUtils.localDateFromSplString(Build.VERSION.SECURITY_PATCH); } return deviceSpl; } + @Override + public LocalDate getKernelSpl() { + if (kernelSpl == null) { + // set in: + // test/sts/tools/sts-tradefed/src/com/android/tradefed/targetprep/multi/KernelSPL.java + String kernelSplString = + PropertyUtil.getProperty("persist.sts.build_version_kernel_security_patch"); + if (kernelSplString == null) { + return null; + } + kernelSpl = SplUtils.localDateFromSplString(kernelSplString); + } + return kernelSpl; + } + + @Override + public boolean shouldUseKernelSpl() { + // set in test/sts/tools/sts-tradefed/res/config/sts-base-use-kernel-spl.xml + String useKernelSplString = + InstrumentationRegistry.getArguments().getString("sts-use-kernel-spl"); + return Boolean.parseBoolean(useKernelSplString); + } + /** * Specify the latest release bulletin. Control this from the command-line with the following: * --test-arg @@ -74,6 +100,7 @@ public class StsExtraBusinessLogicTestCase extends ExtraBusinessLogicTestCase im */ @Override public LocalDate getReleaseBulletinSpl() { + // set manually with command-line args at runtime String releaseBulletinSpl = InstrumentationRegistry.getArguments().getString("release-bulletin-spl"); if (releaseBulletinSpl == null) { diff --git a/libraries/sts-common-util/host-side/src/com/android/sts/common/tradefed/testtype/StsExtraBusinessLogicHostTestBase.java b/libraries/sts-common-util/host-side/src/com/android/sts/common/tradefed/testtype/StsExtraBusinessLogicHostTestBase.java index c7fad5b9e..68132f93e 100644 --- a/libraries/sts-common-util/host-side/src/com/android/sts/common/tradefed/testtype/StsExtraBusinessLogicHostTestBase.java +++ b/libraries/sts-common-util/host-side/src/com/android/sts/common/tradefed/testtype/StsExtraBusinessLogicHostTestBase.java @@ -34,6 +34,7 @@ public class StsExtraBusinessLogicHostTestBase extends ExtraBusinessLogicHostTes implements StsLogic { private LocalDate deviceSpl = null; + private LocalDate kernelSpl = null; @Rule public DescriptionProvider descriptionProvider = new DescriptionProvider(); public StsExtraBusinessLogicHostTestBase() { @@ -43,6 +44,7 @@ public class StsExtraBusinessLogicHostTestBase extends ExtraBusinessLogicHostTes @Override public List<String> getExtraBusinessLogics() { + // set in test/sts/tools/sts-tradefed/res/config/sts-base-dynamic-*.xml String stsDynamicPlan = getBuild().getBuildAttributes().get("sts-dynamic-plan"); switch (stsDynamicPlan) { case "incremental": @@ -60,7 +62,7 @@ public class StsExtraBusinessLogicHostTestBase extends ExtraBusinessLogicHostTes } @Override - public LocalDate getDeviceSpl() { + public LocalDate getPlatformSpl() { if (deviceSpl == null) { try { String splString = getDevice().getProperty("ro.build.version.security_patch"); @@ -72,12 +74,35 @@ public class StsExtraBusinessLogicHostTestBase extends ExtraBusinessLogicHostTes return deviceSpl; } + @Override + public LocalDate getKernelSpl() { + if (kernelSpl == null) { + // set in: + // test/sts/tools/sts-tradefed/src/com/android/tradefed/targetprep/multi/KernelSPL.java + String kernelSplString = + getBuild().getBuildAttributes().get("cts:build_version_kernel_security_patch"); + if (kernelSplString == null) { + return null; + } + kernelSpl = SplUtils.localDateFromSplString(kernelSplString); + } + return kernelSpl; + } + + @Override + public boolean shouldUseKernelSpl() { + // set in test/sts/tools/sts-tradefed/res/config/sts-base-use-kernel-spl.xml + String useKernelSplString = getBuild().getBuildAttributes().get("sts-use-kernel-spl"); + return Boolean.parseBoolean(useKernelSplString); + } + /** * Specify the latest release bulletin. Control this from the command-line with the following * command line argument: --build-attribute "release-bulletin-spl=2021-06" */ @Override public LocalDate getReleaseBulletinSpl() { + // set manually with command-line args at runtime String releaseBulletinSpl = getBuild().getBuildAttributes().get("release-bulletin-spl"); if (releaseBulletinSpl == null) { return null; diff --git a/libraries/sts-common-util/util/src/com/android/sts/common/util/BusinessLogicSetStore.java b/libraries/sts-common-util/util/src/com/android/sts/common/util/BusinessLogicSetStore.java new file mode 100644 index 000000000..ea63f2326 --- /dev/null +++ b/libraries/sts-common-util/util/src/com/android/sts/common/util/BusinessLogicSetStore.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2022 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 com.android.sts.common.util; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** Business-Logic GCL-accessible utility for sets. */ +public class BusinessLogicSetStore { + + private static Map<String, Set<String>> sets = new HashMap<>(); + + public boolean hasSet(String setName) { + return sets.containsKey(setName); + } + + public void putSet(String setName, String... elements) { + Set<String> set = sets.get(setName); + if (set == null) { + set = new HashSet<>(); + sets.put(setName, set); + } + + for (String element : elements) { + set.add(element); + } + } + + public static Set<String> getSet(String setName) { + Set<String> set = sets.get(setName); + if (set == null) { + return null; + } + return Collections.unmodifiableSet(set); + } +} diff --git a/libraries/sts-common-util/util/src/com/android/sts/common/util/StsLogic.java b/libraries/sts-common-util/util/src/com/android/sts/common/util/StsLogic.java index 648199c20..35582d331 100644 --- a/libraries/sts-common-util/util/src/com/android/sts/common/util/StsLogic.java +++ b/libraries/sts-common-util/util/src/com/android/sts/common/util/StsLogic.java @@ -16,8 +16,8 @@ package com.android.sts.common.util; -import static org.junit.Assume.*; import static org.junit.Assert.*; +import static org.junit.Assume.*; import android.platform.test.annotations.AsbSecurityTest; @@ -29,6 +29,7 @@ import java.time.LocalDate; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Set; /** Common STS extra business logic for host-side and device-side to implement. */ public interface StsLogic { @@ -37,21 +38,27 @@ public interface StsLogic { // keep in sync with google3: // //wireless/android/partner/apbs/*/config/xtsbgusinesslogic/sts_business_logic.gcl - List<String> STS_EXTRA_BUSINESS_LOGIC_FULL = Arrays.asList(new String[]{ - "uploadSpl", - "uploadModificationTime", - "declaredSpl", + List<String> STS_EXTRA_BUSINESS_LOGIC_FULL = Arrays.asList(new String[] { + "uploadSpl", + "uploadModificationTime", + "uploadKernelBugs", + "declaredSpl", }); - List<String> STS_EXTRA_BUSINESS_LOGIC_INCREMENTAL = Arrays.asList(new String[]{ - "uploadSpl", - "uploadModificationTime", - "declaredSpl", - "incremental", + List<String> STS_EXTRA_BUSINESS_LOGIC_INCREMENTAL = Arrays.asList(new String[] { + "uploadSpl", + "uploadModificationTime", + "uploadKernelBugs", + "declaredSpl", + "incremental", }); Description getTestDescription(); - LocalDate getDeviceSpl(); + LocalDate getPlatformSpl(); + + LocalDate getKernelSpl(); + + boolean shouldUseKernelSpl(); LocalDate getReleaseBulletinSpl(); @@ -73,6 +80,26 @@ public interface StsLogic { return Arrays.stream(bugIds).min().getAsLong() < 157905780; } + default LocalDate getDeviceSpl() { + if (shouldUseKernelSpl()) { + Set<String> bugIds = BusinessLogicSetStore.getSet("kernel_bugs"); + boolean isKernel = false; + for (long bugId : getCveBugIds()) { + isKernel |= bugIds.contains(Long.toString(bugId)); + } + if (isKernel) { + LocalDate kernelSpl = getKernelSpl(); + if (kernelSpl != null) { + return kernelSpl; + } + // could not get the kernel SPL even though we should use it + // falling back to platform SPL + logWarn(LOG_TAG, "could not read kernel SPL, falling back to platform SPL"); + } + } + return getPlatformSpl(); + } + default LocalDate getMinTestSpl() { Map<String, String> map = BusinessLogicMapStore.getMap("security_bulletins"); if (map == null) { @@ -109,8 +136,10 @@ public interface StsLogic { for (long cveBugId : getCveBugIds()) { String modificationMillisString = map.get(Long.toString(cveBugId)); if (modificationMillisString == null) { - logInfo(LOG_TAG, - "Could not find the CVE bug %d in the modification date map", cveBugId); + logInfo( + LOG_TAG, + "Could not find the CVE bug %d in the modification date map", + cveBugId); continue; } LocalDate modificationDate = |