Skip to content
Open
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 @@ -145,8 +145,8 @@ public class SessionRequestHandlerUtil {
Pattern.compile(".*\\[(?<moduleParam>.*)]$");

private static final Duration JOB_TEST_TIMEOUT_DIFF = Duration.ofMinutes(1L);
private static final Duration DEFAULT_TRADEFED_JOB_TIMEOUT = Duration.ofDays(15L);
private static final Duration DEFAULT_TRADEFED_START_TIMEOUT = Duration.ofDays(14L);
public static final Duration DEFAULT_TRADEFED_JOB_TIMEOUT = Duration.ofDays(15L);
public static final Duration DEFAULT_TRADEFED_START_TIMEOUT = Duration.ofDays(14L);
private static final Duration DEFAULT_NON_TRADEFED_JOB_TIMEOUT = Duration.ofDays(5L);
private static final Duration DEFAULT_NON_TRADEFED_START_TIMEOUT = Duration.ofDays(4L);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ java_library(
"//src/java/com/google/devtools/mobileharness/shared/util/flags",
"//src/java/com/google/devtools/mobileharness/shared/util/jobconfig:job_info_creator",
"//src/java/com/google/devtools/mobileharness/shared/util/logging:google_logger",
"//src/java/com/google/devtools/mobileharness/shared/util/system",
"//src/java/com/google/devtools/mobileharness/shared/util/time:time_utils",
"//src/java/com/google/wireless/qa/mobileharness/shared/api/decorator/constant:phase_skippable_decorator_constants",
"//src/java/com/google/wireless/qa/mobileharness/shared/api/metadata",
"//src/java/com/google/wireless/qa/mobileharness/shared/model/job",
Expand Down Expand Up @@ -86,6 +88,7 @@ java_library(
"//src/java/com/google/devtools/mobileharness/platform/android/xts/suite/retry:retry_generator",
"//src/java/com/google/devtools/mobileharness/platform/android/xts/suite/subplan:sub_plan",
"//src/java/com/google/devtools/mobileharness/shared/util/file/local",
"//src/java/com/google/devtools/mobileharness/shared/util/system",
"//src/java/com/google/wireless/qa/mobileharness/shared/api/spec:tradefed_test_spec",
"@maven//:com_google_code_findbugs_jsr305",
"@maven//:com_google_guava_guava",
Expand Down Expand Up @@ -123,6 +126,7 @@ java_library(
"//src/java/com/google/devtools/mobileharness/shared/util/flags",
"//src/java/com/google/devtools/mobileharness/shared/util/logging:google_logger",
"//src/java/com/google/devtools/mobileharness/shared/util/path",
"//src/java/com/google/devtools/mobileharness/shared/util/system",
"//src/java/com/google/wireless/qa/mobileharness/shared/api/spec:tradefed_test_spec",
"@maven//:com_google_code_findbugs_jsr305",
"@maven//:com_google_guava_guava",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.devtools.mobileharness.platform.android.xts.suite.retry.RetryGenerator;
import com.google.devtools.mobileharness.platform.android.xts.suite.subplan.SubPlan;
import com.google.devtools.mobileharness.shared.util.file.local.LocalFileUtil;
import com.google.devtools.mobileharness.shared.util.system.SystemUtil;
import com.google.wireless.qa.mobileharness.shared.api.spec.TradefedTestSpec;
import java.nio.file.Path;
import java.util.Map;
Expand All @@ -58,8 +59,14 @@ public class ConsoleJobCreator extends XtsJobCreator {
LocalFileUtil localFileUtil,
PreviousResultLoader previousResultLoader,
RetryGenerator retryGenerator,
ModuleShardingArgsGenerator moduleShardingArgsGenerator) {
super(sessionRequestHandlerUtil, localFileUtil, retryGenerator, moduleShardingArgsGenerator);
ModuleShardingArgsGenerator moduleShardingArgsGenerator,
SystemUtil systemUtil) {
super(
sessionRequestHandlerUtil,
localFileUtil,
retryGenerator,
moduleShardingArgsGenerator,
systemUtil);

this.previousResultLoader = previousResultLoader;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.google.devtools.mobileharness.shared.util.file.local.LocalFileUtil;
import com.google.devtools.mobileharness.shared.util.flags.Flags;
import com.google.devtools.mobileharness.shared.util.path.PathUtil;
import com.google.devtools.mobileharness.shared.util.system.SystemUtil;
import com.google.wireless.qa.mobileharness.shared.api.spec.TradefedTestSpec;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -73,8 +74,14 @@ public class ServerJobCreator extends XtsJobCreator {
PreviousResultLoader previousResultLoader,
RetryGenerator retryGenerator,
ModuleShardingArgsGenerator moduleShardingArgsGenerator,
AtsServerSessionUtil atsServerSessionUtil) {
super(sessionRequestHandlerUtil, localFileUtil, retryGenerator, moduleShardingArgsGenerator);
AtsServerSessionUtil atsServerSessionUtil,
SystemUtil systemUtil) {
super(
sessionRequestHandlerUtil,
localFileUtil,
retryGenerator,
moduleShardingArgsGenerator,
systemUtil);

this.previousResultLoader = previousResultLoader;
this.atsServerSessionUtil = atsServerSessionUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.primitives.Ints.saturatedCast;
import static com.google.devtools.mobileharness.shared.util.time.TimeUtils.toJavaDuration;
import static java.util.stream.Collectors.joining;

import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -53,6 +55,7 @@
import com.google.devtools.mobileharness.shared.util.file.local.LocalFileUtil;
import com.google.devtools.mobileharness.shared.util.flags.Flags;
import com.google.devtools.mobileharness.shared.util.jobconfig.JobInfoCreator;
import com.google.devtools.mobileharness.shared.util.system.SystemUtil;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.wireless.qa.mobileharness.shared.api.decorator.constant.PhaseSkippableDecoratorConstants;
Expand All @@ -68,6 +71,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.util.HashMap;
import java.util.Locale;
Expand Down Expand Up @@ -102,16 +106,32 @@ public abstract class XtsJobCreator {
protected final LocalFileUtil localFileUtil;
private final RetryGenerator retryGenerator;
private final ModuleShardingArgsGenerator moduleShardingArgsGenerator;
private final SystemUtil systemUtil;

protected XtsJobCreator(
SessionRequestHandlerUtil sessionRequestHandlerUtil,
LocalFileUtil localFileUtil,
RetryGenerator retryGenerator,
ModuleShardingArgsGenerator moduleShardingArgsGenerator) {
this(
sessionRequestHandlerUtil,
localFileUtil,
retryGenerator,
moduleShardingArgsGenerator,
new SystemUtil());
}

protected XtsJobCreator(
SessionRequestHandlerUtil sessionRequestHandlerUtil,
LocalFileUtil localFileUtil,
RetryGenerator retryGenerator,
ModuleShardingArgsGenerator moduleShardingArgsGenerator,
SystemUtil systemUtil) {
this.sessionRequestHandlerUtil = sessionRequestHandlerUtil;
this.localFileUtil = localFileUtil;
this.retryGenerator = retryGenerator;
this.moduleShardingArgsGenerator = moduleShardingArgsGenerator;
this.systemUtil = systemUtil;
}

public static boolean isSkippableException(MobileHarnessException e) {
Expand Down Expand Up @@ -717,13 +737,35 @@ private JobInfo createPreconditionJob(
.build())
.collect(toImmutableList());

// Dynamic MCTS downloads large artifacts, requiring standard Tradefed timeouts.
Duration jobTimeout;
Duration testTimeout;
Duration startTimeout;
if (isDynamicMctsEnabled) {
jobTimeout =
(sessionRequestInfo.getJobTimeout().getSeconds() == 0
&& sessionRequestInfo.getJobTimeout().getNanos() == 0)
? SessionRequestHandlerUtil.DEFAULT_TRADEFED_JOB_TIMEOUT
: toJavaDuration(sessionRequestInfo.getJobTimeout());
testTimeout = SessionRequestHandlerUtil.calculateTestTimeout(jobTimeout);
startTimeout =
(sessionRequestInfo.getStartTimeout().getSeconds() == 0
&& sessionRequestInfo.getStartTimeout().getNanos() == 0)
? SessionRequestHandlerUtil.DEFAULT_TRADEFED_START_TIMEOUT
: toJavaDuration(sessionRequestInfo.getStartTimeout());
} else {
jobTimeout = Duration.ofMinutes(5);
testTimeout = Duration.ofMinutes(5);
startTimeout = Duration.ofMinutes(5);
}

JobConfig jobConfig =
JobConfig.newBuilder()
.setName(name)
.setExecMode("local")
.setJobTimeoutSec(300)
.setTestTimeoutSec(300)
.setStartTimeoutSec(300)
.setJobTimeoutSec(saturatedCast(jobTimeout.toSeconds()))
.setTestTimeoutSec(saturatedCast(testTimeout.toSeconds()))
.setStartTimeoutSec(startTimeout.toSeconds())
.setPriority(Priority.HIGH)
.setTestAttempts(1)
.setTests(StringList.newBuilder().addContent(name))
Expand All @@ -737,7 +779,8 @@ private JobInfo createPreconditionJob(
jobConfig,
/* nonstandardFlags= */ ImmutableList.of(),
sessionRequestHandlerUtil.createJobGenDir(name).toString(),
sessionRequestHandlerUtil.createJobTmpDir(name).toString());
sessionRequestHandlerUtil.createJobTmpDir(name).toString(),
systemUtil);

if (decorators.stream()
.anyMatch(d -> DriverDecoratorMetadata.isPhaseSkippableDecorator(d.getDecoratorName()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ java_library(
"//src/devtools/mobileharness/infra/ats/common/proto:xts_common_java_proto",
"//src/devtools/mobileharness/infra/ats/server/proto:service_java_proto",
"//src/java/com/google/devtools/mobileharness/api/model/error",
"//src/java/com/google/devtools/mobileharness/api/model/job/in",
"//src/java/com/google/devtools/mobileharness/infra/ats/common:session_handler_helper",
"//src/java/com/google/devtools/mobileharness/infra/ats/common:session_request_handler_util",
"//src/java/com/google/devtools/mobileharness/infra/ats/common:session_request_info_util",
Expand All @@ -49,6 +50,8 @@ java_library(
"//src/java/com/google/devtools/mobileharness/platform/android/xts/suite/subplan:sub_plan",
"//src/java/com/google/devtools/mobileharness/shared/util/file/local",
"//src/java/com/google/devtools/mobileharness/shared/util/flags/core:testing",
"//src/java/com/google/devtools/mobileharness/shared/util/system",
"//src/java/com/google/devtools/mobileharness/shared/util/time:time_utils",
"//src/java/com/google/wireless/qa/mobileharness/shared/api/decorator/constant:phase_skippable_decorator_constants",
"//src/java/com/google/wireless/qa/mobileharness/shared/api/spec:tradefed_test_spec",
"//src/java/com/google/wireless/qa/mobileharness/shared/model/job",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.devtools.mobileharness.infra.ats.common.jobcreator;

import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.mobileharness.shared.util.time.TimeUtils.toProtoDuration;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -32,6 +33,7 @@
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.mobileharness.api.model.error.MobileHarnessException;
import com.google.devtools.mobileharness.api.model.job.in.Timeout;
import com.google.devtools.mobileharness.infra.ats.common.SessionRequestHandlerUtil;
import com.google.devtools.mobileharness.infra.ats.common.SessionRequestHandlerUtil.TradefedJobInfo;
import com.google.devtools.mobileharness.infra.ats.common.SessionRequestInfoUtil;
Expand All @@ -49,6 +51,7 @@
import com.google.devtools.mobileharness.platform.android.xts.suite.subplan.SubPlan;
import com.google.devtools.mobileharness.shared.util.file.local.LocalFileUtil;
import com.google.devtools.mobileharness.shared.util.flags.core.SetFlags;
import com.google.devtools.mobileharness.shared.util.system.SystemUtil;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
Expand All @@ -65,6 +68,7 @@
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
Expand Down Expand Up @@ -108,6 +112,7 @@ public final class ConsoleJobCreatorTest {
@Bind @Mock private PreviousResultLoader previousResultLoader;
@Bind @Mock private RetryGenerator retryGenerator;
@Bind @Mock private ModuleShardingArgsGenerator moduleShardingArgsGenerator;
@Bind @Mock private SystemUtil systemUtil;

@Inject private ConsoleJobCreator jobCreator;

Expand All @@ -116,6 +121,7 @@ public void setUp() throws Exception {
flags.setAll(ImmutableMap.of("enable_ats_mode", "true", "use_tf_retry", "false"));

Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
when(systemUtil.isBlazeTest()).thenReturn(false);
when(sessionRequestHandlerUtil.getSessionSubDeviceSpecList(any(), anyBoolean()))
.thenReturn(MOCK_SUB_DEVICE_SPEC_LIST);
}
Expand Down Expand Up @@ -760,6 +766,7 @@ public void createXtsNonTradefedJobs_moblyOnly_setupAndTeardownJobsInjected() th
assertThat(setupJob.properties().get(PhaseSkippableDecoratorConstants.PROP_EXECUTION_MODE))
.isEqualTo(PhaseSkippableDecoratorConstants.ExecutionMode.SETUP_ONLY.name());
assertThat(setupJob.type().getDriver()).isEqualTo("NoOpDriver");
assertThat(setupJob.setting().getNewTimeout().jobTimeout()).isEqualTo(Duration.ofMinutes(5));
assertThat(setupJob.subDeviceSpecs().getAllSubDevices().get(0).decorators().getAll())
.containsExactly(
"AndroidCleanAppsDecorator",
Expand Down Expand Up @@ -992,6 +999,11 @@ public void createXtsSetupAndTearDownJob_dynamicMctsEnabled_createsJobsWithoutDe
assertThat(setupJob.properties().get(XtsConstants.XTS_JOB_NAME))
.isEqualTo(XtsConstants.SETUP_JOB_NAME);
assertThat(setupJob.subDeviceSpecs().getAllSubDevices().get(0).decorators().getAll()).isEmpty();
assertThat(setupJob.setting().getNewTimeout().jobTimeout()).isEqualTo(Timeout.MAX_JOB_TIMEOUT);
assertThat(setupJob.setting().getNewTimeout().testTimeout())
.isEqualTo(Timeout.MAX_TEST_TIMEOUT);
assertThat(setupJob.setting().getNewTimeout().startTimeout())
.isEqualTo(Timeout.MAX_JOB_TIMEOUT.minusMinutes(1));

Optional<JobInfo> teardownJobOpt = jobCreator.createXtsTearDownJob(sessionRequestInfo);
assertThat(teardownJobOpt).isPresent();
Expand All @@ -1003,6 +1015,41 @@ public void createXtsSetupAndTearDownJob_dynamicMctsEnabled_createsJobsWithoutDe
.isEqualTo(XtsConstants.TEARDOWN_JOB_NAME);
assertThat(teardownJob.subDeviceSpecs().getAllSubDevices().get(0).decorators().getAll())
.isEmpty();
assertThat(teardownJob.setting().getNewTimeout().jobTimeout())
.isEqualTo(Timeout.MAX_JOB_TIMEOUT);
assertThat(teardownJob.setting().getNewTimeout().testTimeout())
.isEqualTo(Timeout.MAX_TEST_TIMEOUT);
assertThat(teardownJob.setting().getNewTimeout().startTimeout())
.isEqualTo(Timeout.MAX_JOB_TIMEOUT.minusMinutes(1));
}

@Test
public void createXtsSetupAndTearDownJob_dynamicMctsEnabledWithCustomTimeout_usesCustomTimeout()
throws Exception {
SessionRequestInfo sessionRequestInfo =
SessionRequestInfoUtil.buildAndValidate(
SessionRequestInfo.newBuilder()
.setTestPlan("cts")
.setCommandLineArgs("cts")
.setXtsRootDir(XTS_ROOT_DIR_PATH)
.setXtsType("cts")
.setIsXtsDynamicDownloadEnabled(true)
.setJobTimeout(toProtoDuration(Duration.ofHours(2)))
.setStartTimeout(toProtoDuration(Duration.ofHours(1))));

when(sessionRequestHandlerUtil.canCreateNonTradefedJobs(sessionRequestInfo)).thenReturn(false);
when(sessionRequestHandlerUtil.getFilteredTradefedModules(sessionRequestInfo))
.thenReturn(ImmutableList.of("CtsSampleDeviceTestCases"));
when(sessionRequestHandlerUtil.createJobGenDir(any())).thenReturn(Path.of("/tmp/gen"));
when(sessionRequestHandlerUtil.createJobTmpDir(any())).thenReturn(Path.of("/tmp/tmp"));

Optional<JobInfo> setupJobOpt = jobCreator.createXtsSetupJob(sessionRequestInfo);
assertThat(setupJobOpt).isPresent();
JobInfo setupJob = setupJobOpt.get();
assertThat(setupJob.setting().getNewTimeout().jobTimeout()).isEqualTo(Duration.ofHours(2));
assertThat(setupJob.setting().getNewTimeout().testTimeout())
.isEqualTo(Duration.ofHours(2).minusMinutes(1));
assertThat(setupJob.setting().getNewTimeout().startTimeout()).isEqualTo(Duration.ofHours(1));
}

@Test
Expand Down
Loading