Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 724155222
  • Loading branch information
DeviceInfra authored and copybara-github committed Feb 7, 2025
1 parent 92c8c24 commit f5d4849
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ public Integer call() {
name = "commands",
aliases = {"c"},
description = "List all commands currently waiting to be executed")
public int commands() throws MobileHarnessException, InterruptedException {
public int commands(@Option(names = "all") boolean listAllCommands)
throws MobileHarnessException, InterruptedException {
serverPreparer.prepareOlcServer();
ImmutableList<AtsSessionPluginConfigOutput> sessionPluginConfigOutputs =
atsSessionStub.getAllUnfinishedSessions(
RunCommand.RUN_COMMAND_SESSION_NAME, /* fromCurrentClient= */ true);
RunCommand.RUN_COMMAND_SESSION_NAME, /* fromCurrentClient= */ !listAllCommands);
String result = PluginOutputPrinter.listCommands(sessionPluginConfigOutputs);
consoleUtil.printlnStdout(result);
return ExitCode.OK;
Expand Down Expand Up @@ -139,11 +140,12 @@ public int devices(@Option(names = "all") boolean listAllDevices)
name = "invocations",
aliases = {"i"},
description = "List all invocation threads")
public int invocations() throws MobileHarnessException, InterruptedException {
public int invocations(@Option(names = "all") boolean listAllInvocations)
throws MobileHarnessException, InterruptedException {
serverPreparer.prepareOlcServer();
ImmutableList<AtsSessionPluginConfigOutput> sessionPluginConfigOutputs =
atsSessionStub.getAllUnfinishedSessions(
RunCommand.RUN_COMMAND_SESSION_NAME, /* fromCurrentClient= */ true);
RunCommand.RUN_COMMAND_SESSION_NAME, /* fromCurrentClient= */ !listAllInvocations);
String result = PluginOutputPrinter.listInvocations(sessionPluginConfigOutputs);
consoleUtil.printlnStdout(result);
return ExitCode.OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ java_library(
"//src/java/com/google/devtools/mobileharness/infra/controller/device/config",
"//src/java/com/google/devtools/mobileharness/shared/util/logging:google_logger",
"//src/java/com/google/devtools/mobileharness/shared/util/time:sleeper",
"//src/java/com/google/wireless/qa/mobileharness/shared:exception",
"//src/java/com/google/wireless/qa/mobileharness/shared/api",
"@maven//:com_google_guava_guava",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ void refreshDeviceConfigs() throws MobileHarnessException, InterruptedException
* failed while updating remote testbed directory
*/
@VisibleForTesting
void refreshLabConfig()
throws com.google.wireless.qa.mobileharness.shared.MobileHarnessException {
void refreshLabConfig() throws MobileHarnessException {
Optional<LabConfig> remoteLabConfig = loadLabConfig(hostName);
LabConfig localLabConfig = apiConfig.getLabConfigToStore();
// If lab config exists in device config server, update local ApiConfig with it;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,33 @@
/**
* Types of dumpsys.
*
* @see <a href="https://developer.android.com/studio/command-line/dumpsys">dumpsys</a>
* @see <a href="http://wrightrocket.blogspot.com/2010/12/useful-commands-in-adb-shell.html">Using
* dumpsys commands in the Android adb shell</a>
*/
public enum DumpSysType {
ACCOUNT("account"), // Account information
ACTIVITY("activity"), // Activity information
ALL("all"), // Use it to get a diagnostic output for all system services as command "adb shell
// dumpsys".
BATTERY("battery"), // Battery information
BATTERYSTATS("batterystats"), // Batterystats information
CAMERA("media.camera"), // Camera information
CONNECTIVITY("connectivity"), // Network connectivity
CPUINFO("cpuinfo"), // Processor usage
DISPLAY("display"), // Information of the keyboards, windows and their z order
GFXINFO("gfxinfo"), // GPU rendering information
INPUT(
"input"), // The state of the system’s input devices, such as keyboards and touchscreens, and
// processing of input events. See https://source.android.com/devices/input/diagnostics.html.
MEMINFO("meminfo"), // Memory usage
NONE(""), // Use it to for all types as command "adb shell dumpsys".
NONE(""), // Alias for ALL.
PACKAGE("package"), // Package info of applications
PROCSTATS("procstats"), // statistics of app's runtime, PSS and USS
POWER("power"), // Power manager information
PROCSTATS("procstats"), // statistics of app's runtime, PSS and USS
WIFI("wifi"), // Available access points and current connection
WIFISCANNER("wifiscanner"), // Scanned wifi information
WINDOW("window"), // Display information
INPUT("input"); // The state of the system’s input devices, such as keyboards and touchscreens,
// and processing of input events. See https://source.android.com/devices/input/diagnostics.html
WINDOW("window"); // Display information

private final String dumpSysTypeValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,35 +70,35 @@ public static SubPlan createSubPlanForPreviousResult(
"%s %s %s", module.getAbi(), module.getName(), previousResult.getTestFilter()),
isNonTfModule);
}
// If the previous result has include/exclude filters, for example the previous run was
// running with given subplan file, whose include/exclude filters are stored in the
// previous result.
if (!prevResultIncludeFilters.isEmpty()) {
prevResultIncludeFilters.stream()
.filter(
filter ->
filter.matchModule(
module.getName(), module.getAbi(), /* moduleParameter= */ null))
.forEach(
prevResultIncludeFilter ->
addIncludeFilter(
subPlan, prevResultIncludeFilter.filterString(), isNonTfModule));
}
if (!prevResultExcludeFilters.isEmpty()) {
prevResultExcludeFilters.stream()
.filter(
filter ->
filter.matchModule(
module.getName(), module.getAbi(), /* moduleParameter= */ null))
.forEach(
prevResultExcludeFilter ->
addExcludeFilter(
subPlan, prevResultExcludeFilter.filterString(), isNonTfModule));
}
if (RetryResultHelper.shouldRunModule(module, types, addSubPlanCmd, passedInModules)) {
if (types.contains("not_executed") && !module.getDone()) {
logger.atInfo().log(
"Module [%s %s] was not done in previous run", module.getAbi(), module.getName());
// If the previous result has include/exclude filters, for example the previous run was
// running with given subplan file, previous include/exclude filters should be applied to
// the current run when the module is not done.
if (!prevResultIncludeFilters.isEmpty()) {
prevResultIncludeFilters.stream()
.filter(
filter ->
filter.matchModule(
module.getName(), module.getAbi(), /* moduleParameter= */ null))
.forEach(
prevResultIncludeFilter ->
addIncludeFilter(
subPlan, prevResultIncludeFilter.filterString(), isNonTfModule));
}
if (!prevResultExcludeFilters.isEmpty()) {
prevResultExcludeFilters.stream()
.filter(
filter ->
filter.matchModule(
module.getName(), module.getAbi(), /* moduleParameter= */ null))
.forEach(
prevResultExcludeFilter ->
addExcludeFilter(
subPlan, prevResultExcludeFilter.filterString(), isNonTfModule));
}
// Exclude tests that should not be run
for (TestCase testCase : module.getTestCaseList()) {
for (Test test : testCase.getTestList()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ java_library(
"//src/java/com/google/devtools/common/metrics/stability/converter",
"//src/java/com/google/devtools/mobileharness/api/model/error",
"//src/java/com/google/devtools/mobileharness/shared/model/error:unknown_error",
"//src/java/com/google/wireless/qa/mobileharness/shared:exception",
"//src/java/com/google/wireless/qa/mobileharness/shared/proto:common_java_proto",
"@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 @@ -17,6 +17,7 @@
package com.google.devtools.mobileharness.shared.util.error;

import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.util.Arrays.stream;

import com.google.common.base.Strings;
Expand Down Expand Up @@ -167,12 +168,12 @@ public static ExceptionProto.ExceptionSummary toCommonExceptionSummary(
.setFileName(mhStackTraceElement.getFileName())
.setLineNumber(mhStackTraceElement.getLineNumber())
.build())
.collect(Collectors.toList())))
.collect(toImmutableList())))
.build();
}

/**
* Coverts the ExceptionDetail proto from the devtools/common/metrics/stability version to the MH
* Converts the ExceptionDetail proto from the devtools/common/metrics/stability version to the MH
* version.
*
* <p>Note this conversion will drop the error namespace info.
Expand Down Expand Up @@ -285,15 +286,6 @@ static ErrorId finalizeErrorId(Throwable throwable, @Nullable ErrorId errorId) {
if (throwable instanceof MobileHarnessException) {
MobileHarnessException mhException = (MobileHarnessException) throwable;
errorId = mhException.getErrorId();
} else if (throwable
instanceof com.google.wireless.qa.mobileharness.shared.MobileHarnessException) {
com.google.wireless.qa.mobileharness.shared.MobileHarnessException mhOldException =
(com.google.wireless.qa.mobileharness.shared.MobileHarnessException) throwable;
errorId =
UnknownErrorId.of(
mhOldException.getErrorCode(),
mhOldException.getErrorName(),
mhOldException.getErrorType());
} else if (errorId == null) {
errorId = BasicErrorId.NON_MH_EXCEPTION;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,14 @@ public class Flags {
converter = Flag.BooleanConverter.class)
public Flag<Boolean> enableAtsFileServerUploader = enableAtsFileServerUploaderDefault;

private static final Flag<Boolean> enableFastbootDetectorDefault = Flag.value(true);

@com.beust.jcommander.Parameter(
names = "--enable_fastboot_detector",
description = "Whether to enable fastboot detector. Default is true.",
converter = Flag.BooleanConverter.class)
public Flag<Boolean> enableFastbootDetector = enableFastbootDetectorDefault;

private static final Flag<Boolean> enableFastbootInAndroidRealDeviceDefault = Flag.value(true);

@com.beust.jcommander.Parameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ public void setUp() throws Exception {
/* parseCommandOnly= */ false));
injector.injectMembers(this);
atsConsole.injector = injector;

// Prepares the cts configs file for testing
realLocalFileUtil.copyFileOrDir(TEST_CTS_CONFIG_DIR, xtsRootDirPath);
}

@After
Expand Down Expand Up @@ -182,9 +185,6 @@ public void tearDown() throws Exception {

@Test
public void listDevicesAndModules_expectedOutput() throws Exception {
// Prepares the cts configs file for testing
realLocalFileUtil.copyFileOrDir(TEST_CTS_CONFIG_DIR, xtsRootDirPath);

when(lineReader.readLine(anyString()))
.thenReturn("list devices")
.thenReturn("list devices all")
Expand Down Expand Up @@ -232,6 +232,18 @@ public void listResults() throws Exception {
+ " SQ3A.220705.003.A1 redfin");
}

@Test
public void listCommands() throws Exception {
when(lineReader.readLine(anyString()))
.thenReturn("run cts")
.thenReturn("list commands")
.thenReturn("exit");

atsConsole.run();

verify(lineReader).printAbove("Command n/a: [0m:00] cts");
}

@Test
public void listSubPlans() throws Exception {
String subPlanFilePath1 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class ClientApiTest {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();

@Rule public final SetFlagsOss flags = new SetFlagsOss();
@Rule public final CaptureLogs captureLogs = new CaptureLogs("", /* printFailedLogs= */ true);
@Rule public final CaptureLogs captureLogs = new CaptureLogs();
@Rule public final PrintTestName printTestName = new PrintTestName();

@Bind @GlobalInternalEventBus private EventBus globalInternalEventBus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
public class ProxyModeIntegrationTest {

@Rule public final SetFlagsOss flags = new SetFlagsOss();
@Rule public final CaptureLogs captureLogs = new CaptureLogs("", /* printFailedLogs= */ true);
@Rule public final CaptureLogs captureLogs = new CaptureLogs();
@Rule public final PrintTestName printTestName = new PrintTestName();

@Bind @GlobalInternalEventBus private final EventBus globalInternalEventBus = new EventBus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ public void parsingLocale_exception() throws MobileHarnessException {
}

@Test
public void getLocale_ok()
throws MobileHarnessException,
InterruptedException,
com.google.wireless.qa.mobileharness.shared.MobileHarnessException {
public void getLocale_ok() throws MobileHarnessException, InterruptedException {
String expectOutput =
"config:"
+ " en-rUS-ldltr-sw411dp-w411dp-h659dp-normal-notlong-notround-lowdr-nowidecg-port-notnight-420dpi-finger-keysexposed-nokeys-navhidden-nonav-1794x1080-v28";
Expand All @@ -106,10 +103,7 @@ public void getLocale_ok()
}

@Test
public void getLocale_emptyException()
throws MobileHarnessException,
InterruptedException,
com.google.wireless.qa.mobileharness.shared.MobileHarnessException {
public void getLocale_emptyException() throws MobileHarnessException, InterruptedException {
String emptyOutput = "";
when(adb.runShellWithRetry(eq(SERIAL), eq(ADB_SHELL_GET_CONFIG), any(Duration.class)))
.thenReturn(emptyOutput);
Expand All @@ -118,10 +112,7 @@ public void getLocale_emptyException()
}

@Test
public void getLocale_missingException()
throws MobileHarnessException,
InterruptedException,
com.google.wireless.qa.mobileharness.shared.MobileHarnessException {
public void getLocale_missingException() throws MobileHarnessException, InterruptedException {
String missingOutput = "config: ";
when(adb.runShellWithRetry(eq(SERIAL), eq(ADB_SHELL_GET_CONFIG), any(Duration.class)))
.thenReturn(missingOutput);
Expand All @@ -130,10 +121,7 @@ public void getLocale_missingException()
}

@Test
public void getLocale_invalidException()
throws MobileHarnessException,
InterruptedException,
com.google.wireless.qa.mobileharness.shared.MobileHarnessException {
public void getLocale_invalidException() throws MobileHarnessException, InterruptedException {
String invalidOutput = "config: ss";
when(adb.runShellWithRetry(eq(SERIAL), eq(ADB_SHELL_GET_CONFIG), any(Duration.class)))
.thenReturn(invalidOutput);
Expand All @@ -142,10 +130,7 @@ public void getLocale_invalidException()
}

@Test
public void getLocale_notFoundException()
throws MobileHarnessException,
InterruptedException,
com.google.wireless.qa.mobileharness.shared.MobileHarnessException {
public void getLocale_notFoundException() throws MobileHarnessException, InterruptedException {
String notFoundOutput = "not found";
when(adb.runShellWithRetry(eq(SERIAL), eq(ADB_SHELL_GET_CONFIG), any(Duration.class)))
.thenReturn(notFoundOutput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ java_library(
"//src/java/com/google/devtools/deviceinfra/platform/android/lightning/internal/sdk/adb",
"//src/java/com/google/devtools/mobileharness/api/model/error",
"//src/java/com/google/devtools/mobileharness/platform/android/app:activity",
"//src/java/com/google/wireless/qa/mobileharness/shared:exception",
"//src/javatests/com/google/devtools/mobileharness/builddefs:truth",
"@maven//:junit_junit",
"@maven//:org_mockito_mockito_core",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public final class RetryGeneratorTest {
.addModuleInfo(MODULE_5_V7A)
.addIncludeFilter("armeabi-v7a Module5 TestClass3#Test1")
.addIncludeFilter("armeabi-v7a Module5 TestClass1#Test1")
.addExcludeFilter("arm64-v8a Module1 TestClass1#Test3")
.addExcludeFilter("armeabi-v7a Module5 TestClass4#Test1")
.addExcludeFilter("armeabi-v7a FakeModule FakeTestClass#Test1")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public class CaptureLogs extends FinishWithFailureTestWatcher {
private final ByteArrayOutputStream logOutputStream = new ByteArrayOutputStream();
private Handler logHandler;

/** Equivalent to {@linkplain #CaptureLogs(String, boolean) CaptureLogs("", true)}. */
public CaptureLogs() {
this(/* loggerName= */ "", /* printFailedLogs= */ true);
}

/**
* The constructor.
*
Expand Down Expand Up @@ -74,6 +79,6 @@ protected void onFinished(@Nullable Throwable testFailure, Description descripti
printFailedLogs ? testFailure : null,
() ->
ImmutableMap.of(
String.format("logs from logger\"%s\"", capturedLogger.getName()), getLogs()));
String.format("logs from logger \"%s\"", capturedLogger.getName()), getLogs()));
}
}

0 comments on commit f5d4849

Please sign in to comment.