Skip to content
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

Internal change #3162

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 @@ -87,6 +87,7 @@
import com.google.wireless.qa.mobileharness.shared.api.device.AndroidDevice;
import com.google.wireless.qa.mobileharness.shared.api.spec.AndroidRealDeviceSpec;
import com.google.wireless.qa.mobileharness.shared.constant.Dimension;
import com.google.wireless.qa.mobileharness.shared.constant.Dimension.Name;
import com.google.wireless.qa.mobileharness.shared.constant.PropertyName.Test.AndroidSetWifiDecorator;
import com.google.wireless.qa.mobileharness.shared.controller.stat.DeviceStat;
import com.google.wireless.qa.mobileharness.shared.model.job.TestInfo;
Expand All @@ -102,6 +103,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.SortedMap;
Expand Down Expand Up @@ -517,6 +519,13 @@ private void addRealDeviceBasicDimensionsAndProperties() throws InterruptedExcep
} catch (MobileHarnessException e) {
logger.atInfo().log("%s", e.getMessage());
}
try {
device.addDimension(
Name.CPU_FREQ_IN_GHZ,
String.format(Locale.US, "%.1f", systemSpecUtil.getMaxCpuFrequency(deviceId) / 1000000f));
} catch (MobileHarnessException e) {
logger.atInfo().log("%s", e.getMessage());
}
try {
device.addDimension(Dimension.Name.MAC_ADDRESS, systemSpecUtil.getMacAddress(deviceId));
} catch (MobileHarnessException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ public enum AndroidErrorId implements ErrorId {
ANDROID_SYSTEM_SPEC_QUERY_SECURE_BOOT_STATUS_ERROR(101_017, ErrorType.INFRA_ISSUE),
ANDROID_SYSTEM_SPEC_GET_SUBSCRIPTION_INFO_ERROR(101_018, ErrorType.INFRA_ISSUE),
ANDROID_SYSTEM_SPEC_GET_SIGNAL_STRENGTHS_ERROR(101_019, ErrorType.INFRA_ISSUE),
ANDROID_SYSTEM_SPEC_GET_CPU_MAX_FREQ_ERROR(101_020, ErrorType.INFRA_ISSUE),
ANDROID_SYSTEM_SPEC_NO_VALID_CPU_MAX_FREQ(101_021, ErrorType.INFRA_ISSUE),

// UsbUtil: 101_201 ~ 101_250
ANDROID_USB_UTIL_RESET_USB_ERROR(101_201, ErrorType.DEPENDENCY_ISSUE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public class AndroidSystemSpecUtil {
/** ADB shell command for getting cpu info. */
@VisibleForTesting static final String ADB_SHELL_GET_CPU_INFO = "cat /proc/cpuinfo";

@VisibleForTesting
static final String ADB_SHELL_GET_CPU_MAX_FREQ =
"cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";

/** ADB shell command for listing all features of device. */
@VisibleForTesting static final String ADB_SHELL_LIST_FEATURES = "pm list features";

Expand Down Expand Up @@ -378,6 +382,31 @@ public int getNumberOfCpus(String serial) throws MobileHarnessException, Interru
AndroidErrorId.ANDROID_SYSTEM_SPEC_NO_CPU_FOUND, "No CPUs found:\n" + output);
}

/**
* Gets the max CPU frequency in Hertz.
*
* @param serial the serial number of the device
* @throws MobileHarnessException if some error occurs in executing system commands, or cpu info
* not found
*/
public int getMaxCpuFrequency(String serial) throws MobileHarnessException, InterruptedException {
String output;
try {
output = adb.runShellWithRetry(serial, ADB_SHELL_GET_CPU_MAX_FREQ);
} catch (MobileHarnessException e) {
throw new MobileHarnessException(
AndroidErrorId.ANDROID_SYSTEM_SPEC_GET_CPU_MAX_FREQ_ERROR, e.getMessage(), e);
}
try {
return Integer.parseInt(output.trim());
} catch (NumberFormatException e) {
throw new MobileHarnessException(
AndroidErrorId.ANDROID_SYSTEM_SPEC_NO_VALID_CPU_MAX_FREQ,
"Expected max cpu frequency, but was " + output,
e);
}
}

/**
* Gets the system features for device.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ public enum Name {
CHROME_VERSION,
/** The current development codename, or the string "REL" if this is a release build. */
CODENAME,
/** Max CPU frequency in Ghz. Precision is 1 decimal place. */
CPU_FREQ_IN_GHZ,
/**
* The disk status of the device. The common value is OK. If free space is less than 1.0G, this
* value will be LOW.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,26 @@ public void getNumberOfCpus() throws Exception {
.isEqualTo(AndroidErrorId.ANDROID_SYSTEM_SPEC_NO_CPU_FOUND);
}

@Test
public void getMaxCpuFrequency_validFrequency_returnsFrequencyInHz() throws Exception {
when(adb.runShellWithRetry(SERIAL, AndroidSystemSpecUtil.ADB_SHELL_GET_CPU_MAX_FREQ))
.thenReturn("1804800\n");

assertThat(systemSpecUtil.getMaxCpuFrequency(SERIAL)).isEqualTo(1804800);
}

@Test
public void getMaxCpuFrequency_noFrequency_throwsException() throws Exception {
when(adb.runShellWithRetry(SERIAL, AndroidSystemSpecUtil.ADB_SHELL_GET_CPU_MAX_FREQ))
.thenReturn("");

assertThat(
assertThrows(
MobileHarnessException.class, () -> systemSpecUtil.getMaxCpuFrequency(SERIAL))
.getErrorId())
.isEqualTo(AndroidErrorId.ANDROID_SYSTEM_SPEC_NO_VALID_CPU_MAX_FREQ);
}

@Test
public void getSystemFeatures_commaDelimitter() throws Exception {
when(adb.runShellWithRetry(SERIAL, AndroidSystemSpecUtil.ADB_SHELL_LIST_FEATURES))
Expand Down
Loading