Skip to content

Internal change #3295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ java_library(
":certification_suite_info",
"//src/java/com/google/devtools/mobileharness/platform/android/xts/suite:suite_common",
"//src/java/com/google/devtools/mobileharness/platform/android/xts/suite:test_suite_info",
"//src/java/com/google/devtools/mobileharness/platform/android/xts/suite:test_suite_info_provider",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.devtools.mobileharness.platform.android.xts.suite.SuiteCommon;
import com.google.devtools.mobileharness.platform.android.xts.suite.TestSuiteInfo;
import com.google.devtools.mobileharness.platform.android.xts.suite.TestSuiteInfoProvider;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -85,7 +86,7 @@ public CertificationSuiteInfo createSuiteInfo(Map<String, String> suiteInfo) {
*/
public Map<String, String> generateSuiteInfoMap(
String xtsRootDir, String xtsType, String suitePlan) {
TestSuiteInfo testSuiteInfo = TestSuiteInfo.getInstance(xtsRootDir, xtsType);
TestSuiteInfo testSuiteInfo = TestSuiteInfoProvider.getTestSuiteInfo(xtsRootDir, xtsType);

Map<String, String> suiteInfoMap = new HashMap<>();
suiteInfoMap.put(SuiteCommon.SUITE_NAME, testSuiteInfo.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ java_library(
"//src/java/com/google/devtools/mobileharness/infra/ats/console:console_info",
"//src/java/com/google/devtools/mobileharness/infra/ats/console/util/command:command_helper",
"//src/java/com/google/devtools/mobileharness/platform/android/xts/suite:test_suite_info",
"//src/java/com/google/devtools/mobileharness/platform/android/xts/suite:test_suite_info_provider",
"//src/java/com/google/devtools/mobileharness/shared/version",
"//src/java/com/google/devtools/mobileharness/shared/version:version_util",
"@maven//:javax_inject_jsr330_api",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.devtools.mobileharness.infra.ats.console.ConsoleInfo;
import com.google.devtools.mobileharness.infra.ats.console.util.command.CommandHelper;
import com.google.devtools.mobileharness.platform.android.xts.suite.TestSuiteInfo;
import com.google.devtools.mobileharness.platform.android.xts.suite.TestSuiteInfoProvider;
import com.google.devtools.mobileharness.shared.version.Version;
import com.google.devtools.mobileharness.shared.version.VersionUtil;
import java.nio.file.Path;
Expand Down Expand Up @@ -51,7 +52,8 @@ public class VersionMessageUtil {
public String getVersionMessage() {
Path xtsRootDir = consoleInfo.getXtsRootDirectoryNonEmpty();
String xtsType = commandHelper.getXtsType();
TestSuiteInfo testSuiteInfo = TestSuiteInfo.getInstance(xtsRootDir.toString(), xtsType);
TestSuiteInfo testSuiteInfo =
TestSuiteInfoProvider.getTestSuiteInfo(xtsRootDir.toString(), xtsType);
String buildNumber =
versionParser.fetchVersion(testSuiteInfo).orElseGet(testSuiteInfo::getBuildNumber);
String labVersion = Version.LAB_VERSION.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ java_library(
deps = [
":abi",
":suite_module_loader",
":test_suite_info",
":test_suite_info_provider",
"//src/devtools/mobileharness/platform/android/xts/proto:configuration_java_proto",
"//src/java/com/google/devtools/mobileharness/api/model/error",
"//src/java/com/google/devtools/mobileharness/api/model/error:exception_factory",
Expand Down Expand Up @@ -84,6 +84,7 @@ java_library(
visibility = [
"//src/java/com/google/devtools/mobileharness/infra/ats/console/result/report:__subpackages__",
"//src/java/com/google/devtools/mobileharness/infra/ats/console/util/version:__pkg__",
"//src/javatests/com/google/devtools/mobileharness/platform/android/xts/suite:__pkg__",
],
deps = [
"//src/java/com/google/devtools/mobileharness/infra/ats/common/plan:jar_file_util",
Expand Down Expand Up @@ -184,3 +185,20 @@ java_library(
"@maven//:javax_inject_jsr330_api",
],
)

java_library(
name = "test_suite_info_provider",
srcs = ["TestSuiteInfoProvider.java"],
visibility = [
"//src/java/com/google/devtools/mobileharness/infra/ats/console/result/report:__subpackages__",
"//src/java/com/google/devtools/mobileharness/infra/ats/console/util/version:__pkg__",
"//src/javatests/com/google/devtools/mobileharness/platform/android/xts/suite:__pkg__",
],
deps = [
":test_suite_info",
"//src/java/com/google/devtools/mobileharness/infra/ats/common/plan:jar_file_util",
"//src/java/com/google/devtools/mobileharness/shared/util/auto:auto_value",
"//src/java/com/google/devtools/mobileharness/shared/util/logging:google_logger",
"@maven//:com_google_guava_guava",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ private File getTestsDir() throws MobileHarnessException {
/** Gets the possible abis from the TestSuiteInfo. */
public Set<String> getAbisForBuildTargetArchFromSuite() {
Set<String> abis = new LinkedHashSet<>();
for (String arch : TestSuiteInfo.getInstance(xtsRootDir, xtsType).getTargetArchs()) {
for (String arch :
TestSuiteInfoProvider.getTestSuiteInfo(xtsRootDir, xtsType).getTargetArchs()) {
abis.addAll(AbiUtil.getAbisForArch(arch));
}
return abis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,12 @@ public class TestSuiteInfo {
private static final String FULLNAME = "fullname";
private static final String VERSION = "version";

@SuppressWarnings("NonFinalStaticField")
private static volatile TestSuiteInfo instance;

private Properties testSuiteInfoProps;
private final JarFileUtil jarFileUtil;
private final String xtsRootDir;
private final String xtsTypeStr;

private TestSuiteInfo(String xtsRootDir, String xtsType, JarFileUtil jarFileUtil) {
TestSuiteInfo(String xtsRootDir, String xtsType, JarFileUtil jarFileUtil) {
this.jarFileUtil = jarFileUtil;
this.xtsRootDir = xtsRootDir;
this.xtsTypeStr = xtsType;
Expand Down Expand Up @@ -96,24 +93,6 @@ private Properties loadSuiteInfoFromInputStream(InputStream testSuiteInfoPropsIn
return props;
}

/**
* Retrieves the singleton instance, which also triggers loading of the related test suite info
* from embedded resource files
*/
public static TestSuiteInfo getInstance(String xtsRootDir, String xtsType) {
if (instance == null) {
synchronized (TestSuiteInfo.class) {
if (instance == null) {
logger.atFine().log(
"Creating %s instance with params [xts root dir: %s, xts type: %s]",
TestSuiteInfo.class.getSimpleName(), xtsRootDir, xtsType);
instance = new TestSuiteInfo(xtsRootDir, xtsType, new JarFileUtil());
}
}
}
return instance;
}

/** Gets the build number of the test suite. */
public String getBuildNumber() {
return testSuiteInfoProps.getProperty(BUILD_NUMBER);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2022 Google LLC
*
* 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
*
* https://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.google.devtools.mobileharness.platform.android.xts.suite;

import com.google.auto.value.AutoValue;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.flogger.FluentLogger;
import com.google.devtools.mobileharness.infra.ats.common.plan.JarFileUtil;
import java.util.concurrent.ExecutionException;

/** A provider for {@link TestSuiteInfo}. */
public final class TestSuiteInfoProvider {

private static final FluentLogger logger = FluentLogger.forEnclosingClass();

@AutoValue
abstract static class CacheKey {
abstract String xtsRootDir();

abstract String xtsType();

static CacheKey create(String xtsRootDir, String xtsType) {
return new AutoValue_TestSuiteInfoProvider_CacheKey(xtsRootDir, xtsType);
}
}

private static final LoadingCache<CacheKey, TestSuiteInfo> cache =
CacheBuilder.newBuilder()
.maximumSize(1000)
.build(
new CacheLoader<CacheKey, TestSuiteInfo>() {
@Override
public TestSuiteInfo load(CacheKey key) {
logger.atFine().log(
"Creating %s instance with params [xts root dir: %s, xts type: %s]",
TestSuiteInfo.class.getSimpleName(), key.xtsRootDir(), key.xtsType());
return new TestSuiteInfo(key.xtsRootDir(), key.xtsType(), new JarFileUtil());
}
});

/**
* Gets the {@link TestSuiteInfo} for the given xTS root directory and xTS type. Cache is used to
* avoid creating the same test suite info multiple times.
*
* @param xtsRootDir the xTS root directory
* @param xtsType the xTS type
* @return the {@link TestSuiteInfo} for the given xTS root directory and xTS type
* @throws IllegalStateException if there is an error loading the test suite info
*/
public static TestSuiteInfo getTestSuiteInfo(String xtsRootDir, String xtsType) {
try {
return cache.get(CacheKey.create(xtsRootDir, xtsType));
} catch (ExecutionException e) {
throw new IllegalStateException(
String.format(
"Error loading test suite info for xts root dir \"%s\" and xts type \"%s\"",
xtsRootDir, xtsType),
e);
}
}

private TestSuiteInfoProvider() {}
}