Fix the spl logic to find the max spl that a test can have
Bug: 439923771
Test: ./sts-tradefed
Change-Id: Ib17df4b8c922af7f13ce830836be3a2fe5dfb0fb
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 d81fb9d..5a44444 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
@@ -161,12 +161,12 @@
return platformSpl;
}
- default LocalDate getMinTestSpl() {
+ default LocalDate getTestEnforcingSpl() {
Map<String, String> map = BusinessLogicMapStore.getMap("security_bulletins");
if (map == null) {
throw new IllegalArgumentException("Could not find the security bulletin map");
}
- LocalDate minSpl = null;
+ LocalDate maxSpl = null;
for (long cveBugId : getCveBugIds()) {
String splString = map.get(Long.toString(cveBugId));
if (splString == null) {
@@ -179,13 +179,13 @@
continue;
}
LocalDate spl = SplUtils.localDateFromSplString(splString);
- if (minSpl == null) {
- minSpl = spl;
- } else if (spl.isBefore(minSpl)) {
- minSpl = spl;
+ if (maxSpl == null) {
+ maxSpl = spl;
+ } else if (spl.isAfter(maxSpl)) {
+ maxSpl = spl;
}
}
- return minSpl;
+ return maxSpl;
}
default LocalDate getMinModificationDate() {
@@ -242,13 +242,13 @@
return false;
}
- LocalDate minTestSpl = getMinTestSpl();
- if (minTestSpl == null) {
+ LocalDate maxTestSpl = getTestEnforcingSpl();
+ if (maxTestSpl == null) {
// could not get the test spl - run the test
logWarn(LOG_TAG, "could not get the test SPL");
return false;
}
- if (minTestSpl.isAfter(incrementalCutoffSpl)) {
+ if (maxTestSpl.isAfter(incrementalCutoffSpl)) {
logDebug(LOG_TAG, "the test has a recent SPL");
return false;
}
@@ -264,36 +264,36 @@
return false;
}
- LocalDate minTestSpl = getMinTestSpl();
+ LocalDate maxTestSpl = getTestEnforcingSpl();
if (!isBugSplDataKnownMissing()) {
LocalDate releaseBulletinSpl = getReleaseBulletinSpl();
if (releaseBulletinSpl != null) {
// this is a QA environment
// assert that the test has a known SPL when we expect the data to be fresh
- assertNotNull("Unknown SPL for new CVE", minTestSpl);
+ assertNotNull("Unknown SPL for new CVE", maxTestSpl);
// set the days to be the same so we only compare year-month
- releaseBulletinSpl = releaseBulletinSpl.withDayOfMonth(minTestSpl.getDayOfMonth());
+ releaseBulletinSpl = releaseBulletinSpl.withDayOfMonth(maxTestSpl.getDayOfMonth());
// the test SPL can't be equal to or after the release bulletin SPL
assertFalse(
- "Newer SPL than release bulletin", releaseBulletinSpl.isBefore(minTestSpl));
+ "Newer SPL than release bulletin", releaseBulletinSpl.isBefore(maxTestSpl));
} else {
// we are in a live environment; don't run tests that have their SPL deferred
- if (minTestSpl == null) {
+ if (maxTestSpl == null) {
// can't find the test SPL for this ASB test; skip
return true;
}
}
}
- if (minTestSpl == null) {
+ if (maxTestSpl == null) {
// no SPL for this test; run normally
return false;
}
// skip if the test is newer than the device SPL
LocalDate deviceSpl = getDeviceSpl();
- return minTestSpl.isAfter(deviceSpl);
+ return maxTestSpl.isAfter(deviceSpl);
}
default boolean shouldSkipMainline() {
diff --git a/libraries/sts-common-util/util/tests/src/com/android/sts/common/util/StsLogicTest.java b/libraries/sts-common-util/util/tests/src/com/android/sts/common/util/StsLogicTest.java
index af3d13d..bbc2b15 100644
--- a/libraries/sts-common-util/util/tests/src/com/android/sts/common/util/StsLogicTest.java
+++ b/libraries/sts-common-util/util/tests/src/com/android/sts/common/util/StsLogicTest.java
@@ -36,14 +36,20 @@
private static final long[] PLATFORM_BUG = {1_000_000_000L};
private static final long[] KERNEL_BUG = {2_000_000_000L};
private static final long[] MAINLINE_BUG = {3_000_000_000L};
+ private static final long[] MULTI_SPL_BUGS = {4_000_000_000L, 5_000_000_000L};
static {
new BusinessLogicSetStore()
.putSet(
"kernel_bugs",
Arrays.stream(KERNEL_BUG).mapToObj(Long::toString).toArray(String[]::new));
- new BusinessLogicMapStore().putMap("security_bulletins", null);
- new BusinessLogicMapStore().putMap("sts_modification_times", null);
+ new BusinessLogicMapStore()
+ .putMap(
+ "security_bulletins",
+ "#",
+ Long.toString(MULTI_SPL_BUGS[0]) + "#2022-03-01",
+ Long.toString(MULTI_SPL_BUGS[1]) + "#2022-02-01");
+ new BusinessLogicMapStore().putMap("sts_modification_times", "#");
new BusinessLogicMapStore()
.putMap(
"bugid_mainline_modules",
@@ -166,6 +172,18 @@
logic.shouldSkipMainline());
}
+ @Test
+ public final void testGetTestEnforcingSplOrder() throws Exception {
+ StsLogic logic = new StsLogicMock().setCveBugIds(MULTI_SPL_BUGS);
+ LocalDate expectedSpl = SplUtils.localDateFromSplString("2022-03-01");
+ assertEquals(
+ "Should return the latest SPL when a test has multiple bug IDs with different"
+ + " SPLs.",
+ expectedSpl,
+ logic.getTestEnforcingSpl());
+ }
+
+
private static class StsLogicMock implements StsLogic {
private long[] cveBugIds = PLATFORM_BUG;