Skip to content

Commit

Permalink
Merge tag 'android-14.0.0_r11' of https://android.googlesource.com/pl…
Browse files Browse the repository at this point in the history
…atform/libcore into HEAD

Android 14.0.0 release 11
  • Loading branch information
xboxfanj committed Oct 17, 2023
2 parents e79bd01 + 65a0af4 commit 01b3a5d
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 21 deletions.
3 changes: 3 additions & 0 deletions TEST_MAPPING
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
{
"name": "CtsLibcoreTestCases",
"options": [
{
"instrumentation-arg": "core-test-mode:=presubmit"
},
{
"exclude-filter": "com.android.org.conscrypt.java.security.AlgorithmParameterGeneratorTestDH"
},
Expand Down
5 changes: 4 additions & 1 deletion expectations/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ expectations_visibility = [
java_library {
name: "libcore-expectations-knownfailures-jar",
visibility: expectations_visibility,
java_resources: ["knownfailures.txt"],
java_resources: [
"knownfailures.txt",
"skippedCtsTest.txt",
],
sdk_version: "core_current",
// Make sure that this will be added to the sdk snapshot for S.
min_sdk_version: "S",
Expand Down
67 changes: 67 additions & 0 deletions expectations/skippedCtsTest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[
{
bug: 287231726,
description: "This test doesn't test public APIs.",
result: EXEC_FAILED,
names: [
"libcore.libcore.icu.DateIntervalFormatTest",
"libcore.libcore.icu.ICUTest",
"libcore.libcore.icu.LocaleDataTest",
"libcore.sun.misc.SharedSecretsTest"
]
},
{
bug: 287231726,
description: "The test asserts buggy or non-breaking behaviors, but the behavior has been fixed / changed in the future ART module version.",
result: EXEC_FAILED,
names: [
"libcore.java.lang.ClassTest#test_toGenericString",
"libcore.java.util.CurrencyTest#test_localeExtension",
"libcore.java.text.OldDecimalFormatSymbolsTest#test_RIHarmony_compatible",
"libcore.java.text.OldNumberFormatTest#test_getCurrencyInstanceLjava_util_Locale",
"org.apache.harmony.tests.java.util.ArrayDequeTest#test_forEachRemaining_CME",
"org.apache.harmony.tests.java.util.ArrayDequeTest#test_iterator",
"org.apache.harmony.tests.java.lang.Character_UnicodeBlockTest#test_ofC",
"org.apache.harmony.tests.java.lang.Character_UnicodeBlockTest#test_ofI",
"org.apache.harmony.tests.java.util.PriorityQueueTest#test_remove_Ljava_lang_Object_not_Compatible",
"org.apache.harmony.tests.java.util.PriorityQueueTest#test_spliterator_CME",
"org.apache.harmony.regex.tests.java.util.regex.PatternTest#testSplitAsStream"
]
},
{
bug: 287231726,
description: "The test depends on locale, but manufacturers / CLDR improves the locale data over time",
result: EXEC_FAILED,
names: [
"libcore.java.text.DecimalFormatTest#testLocaleGroupingSeparator",
"libcore.java.text.DecimalFormatTest#testSetGroupingSeparator"
]
},
{
bug: 286802267,
description: "The test depends on internal APIs.",
result: EXEC_FAILED,
names: [
"test.java.time.TestClock_System#test_OffsetLimits",
"test.java.time.TestClock_System#test_OffsetRegular"
]
},
{
bug: 286802267,
description: "The test asserts buggy or non-breaking behaviors, but the behavior has been fixed / changed in the future ART module version.",
result: EXEC_FAILED,
names: [
"tck.java.time.TCKYear#factory_parse_fail",
"tck.java.time.format.TCKDateTimeParseResolver#test_resolveAmPm"
]
},
{
bug: 286802267,
description: "The test depends on locale, but manufacturers / CLDR improves the locale data over time",
result: EXEC_FAILED,
names: [
"test.java.time.format.TestUnicodeExtension#test_localizedBy",
"test.java.util.TestFormatter#test"
]
}
]
4 changes: 2 additions & 2 deletions luni/src/test/java/libcore/java/net/URLConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3136,7 +3136,7 @@ private void checkNoFallbackOnFailedHandshake(SSLSocketFactory clientSocketFacto
}

@Test public void noSslFallback_specifiedProtocols() throws Exception {
String[] enabledProtocols = { "TLSv1.3", "TLSv1.2", "TLSv1.1" };
String[] enabledProtocols = { "TLSv1.2", "TLSv1.1" };
TestSSLContext testSSLContext = createDefaultTestSSLContext();
SSLSocketFactory serverSocketFactory =
new LimitedProtocolsSocketFactory(
Expand All @@ -3150,7 +3150,7 @@ private void checkNoFallbackOnFailedHandshake(SSLSocketFactory clientSocketFacto

@Test public void noSslFallback_defaultProtocols() throws Exception {
// Will need to be updated if the enabled protocols in Android's SSLSocketFactory change
String[] expectedEnabledProtocols = { "TLSv1.3", "TLSv1.2", "TLSv1.1", "TLSv1" };
String[] expectedEnabledProtocols = { "TLSv1.2", "TLSv1.1", "TLSv1" };

TestSSLContext testSSLContext = createDefaultTestSSLContext();
SSLSocketFactory serverSocketFactory = testSSLContext.serverContext.getSocketFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ private static SSLContext getContext() throws Exception {
trustManagers = TestTrustManager.wrap(trustManagers);
}

SSLContext ctx = SSLContext.getInstance("TLSv1");
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(keyManagers, trustManagers, null);
return ctx;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2220,7 +2220,7 @@ public void testSplitAsStream() {
}

private int getExpectedEmptyStringSplitLength() {
if (VMRuntime.getSdkVersion() >= VersionCodes.UPSIDE_DOWN_CAKE
if (VMRuntime.getSdkVersion() > VersionCodes.TIRAMISU
&& Compatibility.isChangeEnabled(
Pattern.SPLIT_AS_STREAM_RETURNS_SINGLE_EMPTY_STRING)) {
// The length is 1 because the javadoc says "If this pattern does not match any
Expand Down
34 changes: 33 additions & 1 deletion ojluni/src/main/java/java/util/PriorityQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@

package java.util;

import android.compat.Compatibility;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;

import dalvik.annotation.compat.VersionCodes;
import dalvik.system.VMRuntime;

import java.util.function.Consumer;
import java.util.function.Predicate;
import jdk.internal.misc.SharedSecrets;
Expand Down Expand Up @@ -327,7 +334,18 @@ public boolean offer(E e) {
int i = size;
if (i >= queue.length)
grow(i + 1);
siftUp(i, e);
if (i == 0) {
// Android-changed: Keep old behavior on Android 13 or below. http://b/289878283
boolean usePreAndroidUBehavior = VMRuntime.getSdkVersion() < VersionCodes.UPSIDE_DOWN_CAKE
|| !Compatibility.isChangeEnabled(PRIORITY_QUEUE_OFFER_NON_COMPARABLE_ONE_ELEMENT);
if (usePreAndroidUBehavior) {
queue[0] = e;
} else {
siftUp(i, e);
}
} else {
siftUp(i, e);
}
size = i + 1;
return true;
}
Expand Down Expand Up @@ -970,4 +988,18 @@ public void forEach(Consumer<? super E> action) {
if (expectedModCount != modCount)
throw new ConcurrentModificationException();
}

// Android-added: Backward-compatible flag for offer() API.
/**
* Since Android 14, {@link PriorityQueue#offer(E)} requires all elements to be comparable if
* there was no comparator. Previously, the first element being added did not need to be
* comparable.
*
* This flag is enabled for apps targeting Android 14+.
*
* @hide
*/
@ChangeId
@EnabledSince(targetSdkVersion = VersionCodes.UPSIDE_DOWN_CAKE)
public static final long PRIORITY_QUEUE_OFFER_NON_COMPARABLE_ONE_ELEMENT = 289878283L;
}
27 changes: 22 additions & 5 deletions ojluni/src/test/java/util/PriorityQueue/AddNonComparable.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

import android.compat.Compatibility;

import dalvik.annotation.compat.VersionCodes;
import dalvik.system.VMRuntime;

public class AddNonComparable {

static <E> void test(Queue<E> queue, Supplier<E> supplier,
Expand All @@ -58,11 +63,23 @@ static <E> void test(Queue<E> queue, Supplier<E> supplier,

@Test
public void queues() {
test(new PriorityQueue<>(), NonComparable::new,
(q, e) -> {
assertEquals(q.size(), 0);
assertTrue(e instanceof ClassCastException);
});
// Android-added: test old behavior in < U.
boolean testPreAndroidUBehavior = VMRuntime.getSdkVersion() < VersionCodes.UPSIDE_DOWN_CAKE
|| !Compatibility.isChangeEnabled(PriorityQueue.PRIORITY_QUEUE_OFFER_NON_COMPARABLE_ONE_ELEMENT);

if (testPreAndroidUBehavior) {
test(new PriorityQueue<>(), NonComparable::new,
(q, e) -> {
assertEquals(q.size(), 1);
assertTrue(e == null);
});
} else {
test(new PriorityQueue<>(), NonComparable::new,
(q, e) -> {
assertEquals(q.size(), 0);
assertTrue(e instanceof ClassCastException);
});
}
test(new PriorityQueue<>(), AComparable::new,
(q, e) -> {
assertEquals(q.size(), 1);
Expand Down
13 changes: 12 additions & 1 deletion ojluni/src/test/java/util/concurrent/tck/PriorityQueueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
import junit.framework.Test;
import junit.framework.TestSuite;

import android.compat.Compatibility;

import dalvik.annotation.compat.VersionCodes;
import dalvik.system.VMRuntime;

public class PriorityQueueTest extends JSR166TestCase {
public static void main(String[] args) {
main(suite(), args);
Expand Down Expand Up @@ -226,10 +231,16 @@ public void testOffer() {
*/
public void testOfferNonComparable() {
PriorityQueue q = new PriorityQueue(1);
// Android-added: test old behavior in < U.
boolean preAndroidUBehavior = VMRuntime.getSdkVersion() < VersionCodes.UPSIDE_DOWN_CAKE
|| !Compatibility.isChangeEnabled(PriorityQueue.PRIORITY_QUEUE_OFFER_NON_COMPARABLE_ONE_ELEMENT);
try {
q.offer(new Object());
shouldThrow();
if (!preAndroidUBehavior) {
shouldThrow();
}
} catch (ClassCastException success) {
assertFalse(preAndroidUBehavior);
assertTrue(q.isEmpty());
assertEquals(0, q.size());
assertNull(q.poll());
Expand Down
20 changes: 11 additions & 9 deletions ojluni/src/test/java/util/regex/PatternStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@

package test.java.util.regex;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

import android.compat.Compatibility;
import dalvik.annotation.compat.VersionCodes;
import dalvik.system.VMRuntime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -50,8 +52,8 @@
import org.openjdk.testlib.java.util.stream.LambdaTestHelpers;
import org.openjdk.testlib.java.util.stream.OpTestCase;
import org.openjdk.testlib.java.util.stream.TestData;

import static org.testng.Assert.*;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import static java.util.regex.Pattern.SPLIT_AS_STREAM_RETURNS_SINGLE_EMPTY_STRING;

Expand Down Expand Up @@ -147,11 +149,11 @@ public void testPatternSplitAsStream(String description, String input, Pattern p
// Derive expected result from pattern.split
List<String> expected = Arrays.asList(pattern.split(input));

// Android-added: Keep old behavior on Android 13 or below. http://b/286499139
if(input.isEmpty()
&& !(VMRuntime.getSdkVersion() >= VersionCodes.UPSIDE_DOWN_CAKE
&& Compatibility.isChangeEnabled(
Pattern.SPLIT_AS_STREAM_RETURNS_SINGLE_EMPTY_STRING))) {
// Android-added: Keep old behavior on Android 13 or below. http://b/286499139
if (input.isEmpty()
&& !(VMRuntime.getSdkVersion() > VersionCodes.TIRAMISU
&& Compatibility.isChangeEnabled(
Pattern.SPLIT_AS_STREAM_RETURNS_SINGLE_EMPTY_STRING))) {
expected = Collections.emptyList();
}

Expand Down
47 changes: 47 additions & 0 deletions test-rules/src/main/java/libcore/test/annotation/NonCts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2023 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 libcore.test.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Test with this annotation doesn't run in CTS.
*
* Note that every annotation element below should be associated to a field in
* {@link vogar.expect.Expectation}, because it will be de- and serialized by
* {@link vogar.expect.ExpectationStore} for back-porting to an older branch.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface NonCts {
/**
* Optional bug id showing why this test fails / shouldn't run in MTS.
*
* The associated field is {@link vogar.expect.Expectation#bug}.
*/
long bug() default -1;

/**
* Reason why the test shouldn't run in CTS.
*
* The associated field is {@link vogar.expect.Expectation#description}.
*/
String reason();
}
41 changes: 41 additions & 0 deletions test-rules/src/main/java/libcore/test/annotation/NonMts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2023 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 libcore.test.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Test with this annotation doesn't run in MTS.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface NonMts {

/** Optional bug id showing why this test fails / shouldn't run in MTS. */
long bug() default -1;

/** Reason why the test shouldn't run in MTS. */
String reason();

/**
* If this value is specified, the test will run on Sdk version equal to or above this value.
*/
int disabledUntilSdk() default Integer.MAX_VALUE;
}
Loading

0 comments on commit 01b3a5d

Please sign in to comment.