diff options
author | Christopher Dombroski <cdombroski@google.com> | 2021-09-29 18:11:41 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-09-29 18:11:41 +0000 |
commit | d187951814a375c10b271922d61493af518413bd (patch) | |
tree | ef7cc47a882cda019664bfc93cfbb4c57c1d7f5f | |
parent | 9f9ee630539c7f92ee57c2ddc5109f3b82c411d0 (diff) | |
parent | 038bd4b72e6bc4a5a75deeea680fff6b3bcbcd14 (diff) | |
download | platform_testing-d187951814a375c10b271922d61493af518413bd.tar.gz |
Add Extra Business Logic support am: 038bd4b72e
Original change: https://googleplex-android-review.googlesource.com/c/platform/platform_testing/+/15660584
Change-Id: I15bee472f5bff09d79419829cba6ca9b5fc3a337
4 files changed, 151 insertions, 1 deletions
diff --git a/libraries/compatibility-common-util/src/com/android/compatibility/common/util/BusinessLogicExecutor.java b/libraries/compatibility-common-util/src/com/android/compatibility/common/util/BusinessLogicExecutor.java index b137801d6..8905fce3a 100644 --- a/libraries/compatibility-common-util/src/com/android/compatibility/common/util/BusinessLogicExecutor.java +++ b/libraries/compatibility-common-util/src/com/android/compatibility/common/util/BusinessLogicExecutor.java @@ -140,10 +140,14 @@ public abstract class BusinessLogicExecutor { } String className = method.substring(0, index); Class cls = Class.forName(className); - Object obj = cls.getDeclaredConstructor().newInstance(); + Object obj = null; if (getTestObject() != null && cls.isAssignableFrom(getTestObject().getClass())) { // The given method is a member of the test class, use the known test class instance obj = getTestObject(); + } else { + // Only instantiate a new object if we don't already have one. + // Otherwise the class could have been an interface which isn't instantiatable. + obj = cls.getDeclaredConstructor().newInstance(); } ResolvedMethod rm = getResolvedMethod(cls, method.substring(index + 1), args); return rm.invoke(obj); diff --git a/libraries/compatibility-common-util/src/com/android/compatibility/common/util/BusinessLogicMapStore.java b/libraries/compatibility-common-util/src/com/android/compatibility/common/util/BusinessLogicMapStore.java new file mode 100644 index 000000000..d208d392d --- /dev/null +++ b/libraries/compatibility-common-util/src/com/android/compatibility/common/util/BusinessLogicMapStore.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2021 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.compatibility.common.util; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** Business-Logic GCL-accessible utility for key-value stores. */ +public class BusinessLogicMapStore { + + private static Map<String, Map<String, String>> maps = new HashMap<>(); + + public boolean hasMap(String mapName) { + return maps.containsKey(mapName); + } + + public void putMap(String mapName, String separator, String... keyValuePairs) { + Map<String, String> map = maps.get(mapName); + if (map == null) { + map = new HashMap<>(); + maps.put(mapName, map); + } + + for (String keyValuePair : keyValuePairs) { + String[] tmp = keyValuePair.split(separator, 2); + if (tmp.length != 2) { + throw new IllegalArgumentException( + "Can't split key-value pair for \"" + keyValuePair + "\""); + } + String key = tmp[0]; + String value = tmp[1]; + map.put(key, value); + } + } + + public static Map<String, String> getMap(String mapName) { + Map<String, String> map = maps.get(mapName); + if (map == null) { + return null; + } + return Collections.unmodifiableMap(map); + } +} diff --git a/libraries/compatibility-common-util/src/com/android/compatibility/common/util/DescriptionProvider.java b/libraries/compatibility-common-util/src/com/android/compatibility/common/util/DescriptionProvider.java new file mode 100644 index 000000000..2c58fd7a3 --- /dev/null +++ b/libraries/compatibility-common-util/src/com/android/compatibility/common/util/DescriptionProvider.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2021 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.compatibility.common.util; + +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; + +/** Provide a way for tests to get their description while running. */ +public class DescriptionProvider extends TestWatcher { + private volatile Description description; + + @Override + protected void starting(Description description) { + this.description = description; + } + + public Description getDescription() { + return description; + } +} diff --git a/libraries/compatibility-common-util/src/com/android/compatibility/common/util/MultiLog.java b/libraries/compatibility-common-util/src/com/android/compatibility/common/util/MultiLog.java new file mode 100644 index 000000000..3a63bd4a4 --- /dev/null +++ b/libraries/compatibility-common-util/src/com/android/compatibility/common/util/MultiLog.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2021 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.compatibility.common.util; + +/** Provide an interface for logging on host+device-common code. */ +public interface MultiLog { + + /** + * Log information with whichever logging mechanism is available to the instance. This varies + * from host-side to device-side, so implementations are left to subclasses. + * Host: MultiLogHost + * Device: MultiLogDevice + * See {@link String.format(String, Object...)} for parameter information. + */ + public void logInfo(String logTag, String format, Object... args); + + /** + * Log debugging information to the host or device logs (depending on implementation). + * See {@link String.format(String, Object...)} for parameter information. + * Host: MultiLogHost + * Device: MultiLogDevice + */ + public void logDebug(String logTag, String format, Object... args); + + /** + * Log warnings to the host or device logs (depending on implementation). + * See {@link String.format(String, Object...)} for parameter information. + * Host: MultiLogHost + * Device: MultiLogDevice + */ + public void logWarn(String logTag, String format, Object... args); + + /** + * Log errors to the host or device logs (depending on implementation). + * See {@link String.format(String, Object...)} for parameter information. + * Host: MultiLogHost + * Device: MultiLogDevice + */ + public void logError(String logTag, String format, Object... args); +} |