Skip to content
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 @@ -76,6 +76,7 @@ java_library(
srcs = ["NewMultiCommandRequestHandler.java"],
visibility = ["//src/javatests/com/google/devtools/mobileharness/infra/ats/server/sessionplugin:__pkg__"],
deps = [
"//src/devtools/mobileharness/api/model/proto:test_java_proto",
"//src/devtools/mobileharness/infra/ats/common/proto:xts_common_java_proto",
"//src/devtools/mobileharness/infra/ats/console/result/proto:report_java_proto",
"//src/devtools/mobileharness/infra/ats/server/proto:service_java_proto",
Expand Down Expand Up @@ -111,7 +112,6 @@ java_library(
"//src/java/com/google/wireless/qa/mobileharness/shared/constant:dimension",
"//src/java/com/google/wireless/qa/mobileharness/shared/model/job",
"//src/java/com/google/wireless/qa/mobileharness/shared/proto:job_config_java_proto",
"//src/java/com/google/wireless/qa/mobileharness/shared/proto:job_java_proto",
"@maven//:com_google_code_findbugs_jsr305",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.google.devtools.mobileharness.api.model.error.InfraErrorId;
import com.google.devtools.mobileharness.api.model.error.MobileHarnessException;
import com.google.devtools.mobileharness.api.model.error.MobileHarnessExceptionFactory;
import com.google.devtools.mobileharness.api.model.proto.Test.TestResult;
import com.google.devtools.mobileharness.infra.ats.common.SessionRequestHandlerUtil;
import com.google.devtools.mobileharness.infra.ats.common.SessionRequestInfo;
import com.google.devtools.mobileharness.infra.ats.common.SessionResultHandlerUtil;
Expand Down Expand Up @@ -86,7 +87,6 @@
import com.google.wireless.qa.mobileharness.shared.constant.Dimension.Name;
import com.google.wireless.qa.mobileharness.shared.model.job.JobInfo;
import com.google.wireless.qa.mobileharness.shared.model.job.TestInfo;
import com.google.wireless.qa.mobileharness.shared.proto.Job.TestResult;
import com.google.wireless.qa.mobileharness.shared.proto.JobConfig;
import com.google.wireless.qa.mobileharness.shared.proto.JobConfig.DeviceList;
import com.google.wireless.qa.mobileharness.shared.proto.JobConfig.Driver;
Expand Down Expand Up @@ -1071,7 +1071,7 @@ private void handleXtsResultProcessing(
sessionRequestInfo);
if (processResult.isPresent() && processResult.get().hasSummary()) {
long failedModuleCount =
processResult.get().getSummary().getModulesTotal()
(long) processResult.get().getSummary().getModulesTotal()
- processResult.get().getSummary().getModulesDone();
commandDetailBuilder
.setPassedTestCount(processResult.get().getSummary().getPassed())
Expand Down Expand Up @@ -1147,9 +1147,9 @@ private void handleSlateResultProcessing(
genFile, testLogDir, ImmutableList.of("-rf"));
}

if (testInfo.result().get() == TestResult.PASS) {
if (testInfo.resultWithCause().get().type() == TestResult.PASS) {
passedTestCount++;
} else if (testInfo.result().get() != TestResult.SKIP) {
} else if (testInfo.resultWithCause().get().type() != TestResult.SKIP) {
failedTestCount++;
}
}
Expand All @@ -1172,8 +1172,8 @@ private void handleSlateResultProcessing(
jobs.stream()
.filter(
jobInfo ->
jobInfo.result().get() != TestResult.PASS
&& jobInfo.result().get() != TestResult.SKIP)
jobInfo.resultWithCause().get().type() != TestResult.PASS
&& jobInfo.resultWithCause().get().type() != TestResult.SKIP)
.count())
.setTotalTestCount(passedTestCount + failedTestCount);
}
Expand Down Expand Up @@ -1268,22 +1268,21 @@ private Optional<String> getFailedTestErrorMessage(ImmutableList<JobInfo> jobs)
.flatMap(jobInfo -> jobInfo.tests().getAll().values().stream())
.filter(
testInfo ->
testInfo.result().get() != TestResult.PASS
&& testInfo.result().get() != TestResult.SKIP)
testInfo.resultWithCause().get().type() != TestResult.PASS
&& testInfo.resultWithCause().get().type() != TestResult.SKIP)
.collect(toImmutableList());
if (!failedTests.isEmpty()) {
TestInfo failedTest = failedTests.get(0);
return Optional.of(
failedTest
.result()
.toNewResult()
.resultWithCause()
.get()
.causeException()
.map(Throwable::getMessage)
.orElse(
String.format(
"Test %s failed with result %s.",
failedTest.locator().getId(), failedTest.result().get())));
failedTest.locator().getId(), failedTest.resultWithCause().get().type())));
}
return Optional.empty();
}
Expand All @@ -1293,22 +1292,21 @@ private Optional<String> getFailedJobErrorMessage(ImmutableList<JobInfo> jobs) {
jobs.stream()
.filter(
jobInfo ->
jobInfo.result().get() != TestResult.PASS
&& jobInfo.result().get() != TestResult.SKIP)
jobInfo.resultWithCause().get().type() != TestResult.PASS
&& jobInfo.resultWithCause().get().type() != TestResult.SKIP)
.collect(toImmutableList());
if (!failedJobs.isEmpty()) {
JobInfo failedJob = failedJobs.get(0);
return Optional.of(
failedJob
.result()
.toNewResult()
.resultWithCause()
.get()
.causeException()
.map(Throwable::getMessage)
.orElse(
String.format(
"Job %s failed with result %s.",
failedJob.locator().getId(), failedJob.result().get())));
failedJob.locator().getId(), failedJob.resultWithCause().get().type())));
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,13 @@ public void onJobEnd(JobEndEvent event) {
// If no running info, it should be a test not assigned.
notFinishedTests.add(testName);
} else if (testInfos.size() == 1) {
switch (testInfos.get(0).result().get()) {
case UNKNOWN:
// If only run once and result is UNKNOWN, it should be a test not finished.
notFinishedTests.add(testName);
break;
case PASS:
// If only run once and result is PASS, it should be a passed test.
passedTests.add(testName);
break;
case SKIP:
// If only run once and result is SKIP, it should be a skipped test.
skippedTests.add(testName);
break;
default:
// Otherwise it's a failed test.
failedTests.add(testName);
}
(switch (testInfos.get(0).resultWithCause().get().type()) {
case UNKNOWN -> notFinishedTests;
case PASS -> passedTests;
case SKIP -> skippedTests;
default -> failedTests;
})
.add(testName);
} else {
int passedNumber = 0;
int skippedNumber = 0;
Expand Down Expand Up @@ -180,7 +170,9 @@ private String getResults(List<String> testNames, ListMultimap<String, TestInfo>
result.append(", NOT_ASSIGNED: ").append(resultNum[5]);
}
} else {
result.append(" ").append(Iterables.getOnlyElement(testInfos).result().get());
result
.append(" ")
.append(Iterables.getOnlyElement(testInfos).resultWithCause().get().type());
}
result.append("\n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ java_library(
],
deps = [
":subdevice_synchronization_driver",
"//src/devtools/mobileharness/api/model/proto:test_java_proto",
"//src/java/com/google/devtools/mobileharness/api/model/error",
"//src/java/com/google/devtools/mobileharness/infra/controller/test:test_context",
"//src/java/com/google/devtools/mobileharness/shared/util/logging:google_logger",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import com.google.devtools.mobileharness.api.model.error.ExtErrorId;
import com.google.devtools.mobileharness.api.model.error.MobileHarnessException;
import com.google.devtools.mobileharness.api.model.error.MobileHarnessExceptions;
import com.google.devtools.mobileharness.api.model.proto.Test.TestResult;
import com.google.devtools.mobileharness.infra.controller.test.TestContext.TestContextCallable;
import com.google.wireless.qa.mobileharness.shared.api.device.Device;
import com.google.wireless.qa.mobileharness.shared.api.driver.Driver;
import com.google.wireless.qa.mobileharness.shared.model.job.TestInfo;
import com.google.wireless.qa.mobileharness.shared.proto.Job.TestResult;
import com.google.wireless.qa.mobileharness.shared.proto.Job.TestStatus;
import java.time.Duration;
import java.util.Collection;
Expand Down Expand Up @@ -63,10 +63,9 @@ private static ListenableFuture<Void> startSubDeviceStack(
logger.atInfo().log(
"Starting decorator stack on device %s", driver.getDevice().getDeviceId());
driver.run(testInfo);
if (!testInfo.result().get().equals(TestResult.UNKNOWN)
if (testInfo.resultWithCause().get().type() != TestResult.UNKNOWN
&& !stack.syncer().isReadyToSync()) {
throw new com.google.devtools.mobileharness.api.model.error
.MobileHarnessException(
throw new MobileHarnessException(
ExtErrorId.TESTBED_DEVICE_DECORATOR_SETUP_ERROR,
"Failure occurred in decorator setup on device "
+ driver.getDevice().getDeviceId());
Expand All @@ -77,22 +76,7 @@ private static ListenableFuture<Void> startSubDeviceStack(
logger.atSevere().log(
"Exception found in setting up device %s; cancelling: %s",
driver.getDevice().getDeviceId(), e.getMessage());
Exception finalException;
// TODO: Can remove when the MH exception from the driver is updated.
if (e instanceof MobileHarnessException
&& !(e
instanceof
com.google.devtools.mobileharness.api.model.error.MobileHarnessException)) {
// Convert old MobileHarnessException to new one.
MobileHarnessException mhException = (MobileHarnessException) e;
finalException =
new com.google.devtools.mobileharness.api.model.error.MobileHarnessException(
ExtErrorId.TESTBED_DEVICE_DECORATOR_SETUP_ERROR,
"<Device " + driver.getDevice().getDeviceId() + "> ",
mhException);
} else {
finalException = e;
}
Exception finalException = e;
stack.syncer().preSyncError(finalException);
throw finalException;
}
Expand Down Expand Up @@ -135,7 +119,7 @@ public static boolean isCompatible(Device subdevice, List<String> decorators) {
}

public static void checkCompatible(Device subdevice, List<String> decorators)
throws com.google.devtools.mobileharness.api.model.error.MobileHarnessException {
throws MobileHarnessException {
if (!isCompatible(subdevice, decorators)) {
Set<String> invalidDecoratorTypes = new HashSet<>(decorators);
invalidDecoratorTypes.removeAll(subdevice.getDecoratorTypes());
Expand All @@ -147,7 +131,7 @@ public static void checkCompatible(Device subdevice, List<String> decorators)
subdevice.getDeviceId(),
invalidDecoratorTypes,
subdevice.getDeviceTypes());
throw new com.google.devtools.mobileharness.api.model.error.MobileHarnessException(
throw new MobileHarnessException(
ExtErrorId.TESTBED_DEVICE_DECORATOR_NOT_COMPATIBLE_ERROR, msg);
}
}
Expand All @@ -163,8 +147,7 @@ public static void checkCompatible(Device subdevice, List<String> decorators)
*/
public static void runParallelSubDeviceStacks(
TestInfo testInfo, Collection<SubDeviceDecoratorStack> subDeviceStacks, Driver mainDriver)
throws com.google.devtools.mobileharness.api.model.error.MobileHarnessException,
InterruptedException {
throws MobileHarnessException, InterruptedException {
ListeningExecutorService executor =
MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(subDeviceStacks.size()));
Set<ListenableFuture<Void>> runFutures = new HashSet<>();
Expand Down Expand Up @@ -207,7 +190,13 @@ public static void runParallelSubDeviceStacks(
// propagate test result to subdevice testInfos.
// Release the threads into teardown.
for (SubDeviceDecoratorStack stack : subDeviceStacks) {
stack.testInfo().result().set(testInfo.result().get());
var mainResult = testInfo.resultWithCause().get();
var subResult = stack.testInfo().resultWithCause();
if (mainResult.type() == TestResult.PASS) {
subResult.setPass();
} else if (mainResult.type() != TestResult.UNKNOWN) {
subResult.setNonPassing(mainResult.type(), mainResult.causeProtoNonEmpty());
}
stack.syncer().releaseSync();
}

Expand All @@ -228,7 +217,7 @@ public static void runParallelSubDeviceStacks(
MobileHarnessExceptions.rethrow(
e.getCause(), ExtErrorId.TESTBED_RUN_SUB_PARRALLEL_DEVICE_STACK_ERROR);
} finally {
allFuture.cancel(true /* mayInterruptIfRunning */);
allFuture.cancel(/* mayInterruptIfRunning= */ false);
// We still need to wait for the futures to complete after cancelling them.
remainingTestTime = testInfo.timer().remainingTimeJava();
executor.awaitTermination(remainingTestTime.toMillis(), MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ java_library(
srcs = ["MoblyDecoratorAdapter.java"],
deps = [
":composite_device_decorator",
"//src/devtools/mobileharness/api/model/proto:test_java_proto",
"//src/java/com/google/devtools/mobileharness/api/model/error",
"//src/java/com/google/devtools/mobileharness/platform/testbed:runner_util",
"//src/java/com/google/devtools/mobileharness/platform/testbed/config:base",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.common.flogger.FluentLogger;
import com.google.devtools.mobileharness.api.model.error.ExtErrorId;
import com.google.devtools.mobileharness.api.model.error.MobileHarnessException;
import com.google.devtools.mobileharness.api.model.proto.Test.TestResult;
import com.google.devtools.mobileharness.platform.testbed.SubDeviceDecoratorStack;
import com.google.devtools.mobileharness.platform.testbed.config.SubDeviceInfo;
import com.google.devtools.mobileharness.platform.testbed.config.SubDeviceKey;
Expand Down Expand Up @@ -112,7 +113,14 @@ private void syncAdapterInfoToTestInfo(
// Update mhSubTestInfo attributes
mhSubTestInfo.remoteGenFiles().addAll(moblySubTestInfo.remoteGenFiles().getAll());
mhSubTestInfo.status().set(moblySubTestInfo.status().get());
mhSubTestInfo.result().set(moblySubTestInfo.result().get());
var moblyResult = moblySubTestInfo.resultWithCause().get();
if (moblyResult.type() == TestResult.PASS) {
mhSubTestInfo.resultWithCause().setPass();
} else {
mhSubTestInfo
.resultWithCause()
.setNonPassing(moblyResult.type(), moblyResult.causeProtoNonEmpty());
}
mhSubTestInfo.log().append(moblySubTestInfo.log().get(0));
mhSubTestInfo.properties().addAll(moblySubTestInfo.properties().getAll());
mhSubTestInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ public final class AtsServerSessionPluginTest {
@Mock private TestInfos testInfos;
@Mock private TestLocator testLocator;
@Mock private SubDeviceSpecs subDeviceSpecs;
@Mock private com.google.wireless.qa.mobileharness.shared.model.job.out.Result testResult;
private Properties testProperties;

@Captor private ArgumentCaptor<UnaryOperator<RequestDetail>> unaryOperatorCaptor;
Expand Down Expand Up @@ -276,10 +275,6 @@ public void setup() throws Exception {
when(testInfo.jobInfo()).thenReturn(jobInfo);
when(testInfo.locator()).thenReturn(testLocator);
when(testLocator.getId()).thenReturn("test_id");
when(jobInfo.result()).thenReturn(testResult);
when(testInfo.result()).thenReturn(testResult);
when(testResult.get())
.thenReturn(com.google.wireless.qa.mobileharness.shared.proto.Job.TestResult.PASS);
testProperties = new Properties(timing);
SubDeviceSpec subDeviceSpec1 =
SubDeviceSpec.createForTesting(
Expand Down Expand Up @@ -928,13 +923,8 @@ public void onJobEnded_nonTradefedJobEnded_atsModuleRunResultFileWritten() throw
jobProperties.add(Job.IS_XTS_NON_TF_JOB, "true");
when(jobInfo.properties()).thenReturn(jobProperties);

com.google.devtools.mobileharness.api.model.job.out.Result result =
mock(com.google.devtools.mobileharness.api.model.job.out.Result.class);
when(result.get())
.thenReturn(
ResultTypeWithCause.create(
com.google.devtools.mobileharness.api.model.proto.Test.TestResult.PASS,
/* cause= */ null));
Result result = mock(Result.class);
when(result.get()).thenReturn(ResultTypeWithCause.create(TestResult.PASS, /* cause= */ null));
when(testInfo.resultWithCause()).thenReturn(result);
when(testInfo.getGenFileDir()).thenReturn("/tmp/test_gen_file_dir");

Expand Down Expand Up @@ -964,12 +954,11 @@ public void onJobEnded_nonTradefedJobEndedWithError_atsModuleRunResultFileWritte
jobProperties.add(Job.IS_XTS_NON_TF_JOB, "true");
when(jobInfo.properties()).thenReturn(jobProperties);

com.google.devtools.mobileharness.api.model.job.out.Result result =
mock(com.google.devtools.mobileharness.api.model.job.out.Result.class);
Result result = mock(Result.class);
when(result.get())
.thenReturn(
ResultTypeWithCause.create(
com.google.devtools.mobileharness.api.model.proto.Test.TestResult.ERROR,
TestResult.ERROR,
new MobileHarnessException(
InfraErrorId.DM_RESERVE_BUSY_DEVICE, "Device is not available.")));
when(testInfo.resultWithCause()).thenReturn(result);
Expand Down Expand Up @@ -1505,9 +1494,8 @@ public void onSessionEnded_handleResultProcessingThrowException_setErrorState()
doThrow(exception)
.when(sessionResultHandlerUtil)
.processResult(any(), any(), any(), any(), any(), any());
assertThrows(
IllegalStateException.class,
() -> plugin.onSessionEnded(new SessionEndedEvent(sessionInfo, null)));
SessionEndedEvent sessionEndedEvent = new SessionEndedEvent(sessionInfo, null);
assertThrows(IllegalStateException.class, () -> plugin.onSessionEnded(sessionEndedEvent));
// sessionInfo.setSessionPluginOutput() is called 4 times: 2 in onSessionStarting, 1 in
// onJobEnded, 1 in onSessionEnded (finally block).
// OnSessionStarting() after creating tradefed jobs. Second time in OnJobEnded()
Expand Down
Loading
Loading