summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Uhler <ruhler@google.com>2018-09-14 14:52:13 +0100
committerRichard Uhler <ruhler@google.com>2018-09-14 14:52:13 +0100
commite9451112d77f2fef908e29683b5fe61c02eaab12 (patch)
tree0eced61eb02b7b5ccf7291ac291c3f250b8060a8
parent5ed02df4df31373d7ff7c7deb9686f9508c031df (diff)
Fix checkstyle errors in SystemMemoryTest
Test: java -jar ../../../../prebuilts/checkstyle/checkstyle.jar -c ../../../../prebuilts/checkstyle/android-style.xml `find . -name *.java` Test: atest -v system-memory-test Change-Id: I4fedf4f27d8995af090361680b85512b6e48bdac
-rw-r--r--tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Cujs.java8
-rw-r--r--tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/MemoryTest.java34
-rw-r--r--tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Metrics.java49
3 files changed, 51 insertions, 40 deletions
diff --git a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Cujs.java b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Cujs.java
index 579d9723977f..1b638747ee09 100644
--- a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Cujs.java
+++ b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Cujs.java
@@ -11,7 +11,7 @@
* 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
+ * limitations under the License.
*/
package com.android.tests.sysmem.host;
@@ -24,10 +24,10 @@ import com.android.tradefed.device.ITestDevice;
* host.
*/
public class Cujs {
- private ITestDevice device;
+ private ITestDevice mDevice;
public Cujs(ITestDevice device) {
- this.device = device;
+ this.mDevice = device;
}
/**
@@ -38,6 +38,6 @@ public class Cujs {
// TODO: Consider exercising the system in other interesting ways as
// well.
String command = "am instrument -w com.android.tests.sysmem.device/.Cujs";
- device.executeShellCommand(command);
+ mDevice.executeShellCommand(command);
}
}
diff --git a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/MemoryTest.java b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/MemoryTest.java
index bbec0654b7ea..cfd598da1a5f 100644
--- a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/MemoryTest.java
+++ b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/MemoryTest.java
@@ -11,7 +11,7 @@
* 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
+ * limitations under the License.
*/
package com.android.tests.sysmem.host;
@@ -22,46 +22,54 @@ import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner.TestLogData;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner.TestMetrics;
import com.android.tradefed.testtype.IDeviceTest;
-import java.io.IOException;
+
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
+import java.io.IOException;
+
+/**
+ * Runs a system memory test.
+ */
@RunWith(DeviceJUnit4ClassRunner.class)
public class MemoryTest implements IDeviceTest {
@Rule public TestMetrics testMetrics = new TestMetrics();
@Rule public TestLogData testLogs = new TestLogData();
- private ITestDevice testDevice;
- private int iterations = 0; // Number of times cujs have been run.
- private Metrics metrics;
- private Cujs cujs;
+ private ITestDevice mTestDevice;
+ private int mIterations = 0; // Number of times cujs have been run.
+ private Metrics mMetrics;
+ private Cujs mCujs;
@Override
public void setDevice(ITestDevice device) {
- testDevice = device;
- metrics = new Metrics(device, testMetrics, testLogs);
- cujs = new Cujs(device);
+ mTestDevice = device;
+ mMetrics = new Metrics(device, testMetrics, testLogs);
+ mCujs = new Cujs(device);
}
@Override
public ITestDevice getDevice() {
- return testDevice;
+ return mTestDevice;
}
// Invoke a single iteration of running the cujs.
private void runCujs() throws DeviceNotAvailableException {
- cujs.run();
- iterations++;
+ mCujs.run();
+ mIterations++;
}
// Sample desired memory.
private void sample()
throws DeviceNotAvailableException, IOException, Metrics.MetricsException {
- metrics.sample(String.format("%03d", iterations));
+ mMetrics.sample(String.format("%03d", mIterations));
}
+ /**
+ * Runs the memory tests.
+ */
@Test
public void run() throws Exception {
sample(); // Sample before running cujs
diff --git a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Metrics.java b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Metrics.java
index 616983e39c50..70bc22c485e1 100644
--- a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Metrics.java
+++ b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Metrics.java
@@ -11,7 +11,7 @@
* 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
+ * limitations under the License.
*/
package com.android.tests.sysmem.host;
@@ -22,6 +22,7 @@ import com.android.tradefed.result.FileInputStreamSource;
import com.android.tradefed.result.LogDataType;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner.TestLogData;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner.TestMetrics;
+
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
@@ -33,15 +34,15 @@ import java.util.Scanner;
*/
class Metrics {
- private ITestDevice device;
- private TestMetrics metrics;
- private TestLogData logs;
+ private ITestDevice mDevice;
+ private TestMetrics mMetrics;
+ private TestLogData mLogs;
/**
* Exception thrown in case of error sampling metrics.
*/
public static class MetricsException extends Exception {
- public MetricsException(String msg) {
+ MetricsException(String msg) {
super(msg);
}
@@ -59,22 +60,22 @@ class Metrics {
* @param metrics where to log the high level metrics when taking a sample
* @param logs where to log detailed breakdowns when taking a sample
*/
- public Metrics(ITestDevice device, TestMetrics metrics, TestLogData logs) {
- this.device = device;
- this.metrics = metrics;
- this.logs = logs;
+ Metrics(ITestDevice device, TestMetrics metrics, TestLogData logs) {
+ this.mDevice = device;
+ this.mMetrics = metrics;
+ this.mLogs = logs;
}
/**
* Writes the given <code>text</code> to a log with the given label.
*/
private void logText(String label, String text) throws IOException {
- File file = File.createTempFile(label, "txt");
- PrintStream ps = new PrintStream(file);
- ps.print(text);
- try (FileInputStreamSource dataStream = new FileInputStreamSource(file)) {
- logs.addTestLog(label, LogDataType.TEXT, dataStream);
- }
+ File file = File.createTempFile(label, "txt");
+ PrintStream ps = new PrintStream(file);
+ ps.print(text);
+ try (FileInputStreamSource dataStream = new FileInputStreamSource(file)) {
+ mLogs.addTestLog(label, LogDataType.TEXT, dataStream);
+ }
}
/**
@@ -82,11 +83,11 @@ class Metrics {
*/
private int getPidForProcess(String name)
throws DeviceNotAvailableException, IOException, MetricsException {
- String psout = device.executeShellCommand("ps -A -o PID,CMD");
+ String psout = mDevice.executeShellCommand("ps -A -o PID,CMD");
Scanner sc = new Scanner(psout);
try {
// ps output is of the form:
- // PID CMD
+ // PID CMD
// 1 init
// 2 kthreadd
// ...
@@ -117,20 +118,22 @@ class Metrics {
*/
void sample(String label) throws DeviceNotAvailableException, IOException, MetricsException {
// adb root access is required to get showmap
- device.enableAdbRoot();
+ mDevice.enableAdbRoot();
int pid = getPidForProcess("system_server");
// Read showmap for system server and add it as a test log
- String showmap = device.executeShellCommand("showmap " + pid);
+ String showmap = mDevice.executeShellCommand("showmap " + pid);
logText(label + ".system_server.showmap", showmap);
// Extract VSS, PSS and RSS from the showmap and output them as metrics.
// The last lines of the showmap output looks something like:
+ // CHECKSTYLE:OFF Generated code
// virtual shared shared private private
// size RSS PSS clean dirty clean dirty swap swapPSS # object
//-------- -------- -------- -------- -------- -------- -------- -------- -------- ---- ------------------------------
// 928480 113016 24860 87348 7916 3632 14120 1968 1968 1900 TOTAL
+ // CHECKSTYLE:ON Generated code
try {
int pos = showmap.lastIndexOf("----");
Scanner sc = new Scanner(showmap.substring(pos));
@@ -139,16 +142,16 @@ class Metrics {
long rss = sc.nextLong();
long pss = sc.nextLong();
- metrics.addTestMetric(String.format("%s.system_server.vss", label), Long.toString(vss));
- metrics.addTestMetric(String.format("%s.system_server.rss", label), Long.toString(rss));
- metrics.addTestMetric(String.format("%s.system_server.pss", label), Long.toString(pss));
+ mMetrics.addTestMetric(label + ".system_server.vss", Long.toString(vss));
+ mMetrics.addTestMetric(label + ".system_server.rss", Long.toString(rss));
+ mMetrics.addTestMetric(label + ".system_server.pss", Long.toString(pss));
} catch (InputMismatchException e) {
throw new MetricsException("unexpected showmap format", e);
}
// Run debuggerd -j to get GC stats for system server and add it as a
// test log
- String debuggerd = device.executeShellCommand("debuggerd -j " + pid);
+ String debuggerd = mDevice.executeShellCommand("debuggerd -j " + pid);
logText(label + ".system_server.debuggerd", debuggerd);
// TODO: Experiment with other additional metrics.