aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-10-23 16:30:25 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-10-23 16:30:25 +0000
commit2dc8ad90f52749dcf01e421723afbf69009655d7 (patch)
treee57119ea66f84073240ab87c7e7709829cbb7428 /src
parent96ffd7f6ea857cfd67624d8a26e243005de41d82 (diff)
parent4b630907a5e99978ffe9403f6c28f43321a5ad8b (diff)
downloadcontrib-2dc8ad90f52749dcf01e421723afbf69009655d7.tar.gz
Merge "Revert "Add misc target preparers plus testing for contrib""
Diffstat (limited to 'src')
-rw-r--r--src/com/android/tradefed/targetprep/FillStorageTargetPreparer.java62
-rw-r--r--src/com/android/tradefed/targetprep/RestartSystemServerTargetPreparer.java35
-rw-r--r--src/com/android/tradefed/targetprep/RootTargetPreparer.java32
-rw-r--r--src/com/android/tradefed/targetprep/SaveAndRestoreTimeTargetPreparer.java87
-rw-r--r--src/com/android/tradefed/targetprep/SetAndRestoreSystemPropertyTargetPreparer.java68
-rw-r--r--src/com/android/tradefed/targetprep/WriteAndRestoreFileTargetPreparer.java59
6 files changed, 4 insertions, 339 deletions
diff --git a/src/com/android/tradefed/targetprep/FillStorageTargetPreparer.java b/src/com/android/tradefed/targetprep/FillStorageTargetPreparer.java
deleted file mode 100644
index e28faf3..0000000
--- a/src/com/android/tradefed/targetprep/FillStorageTargetPreparer.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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.
- */
-
-package com.android.tradefed.targetprep;
-
-import com.android.tradefed.build.IBuildInfo;
-import com.android.tradefed.config.Option;
-import com.android.tradefed.config.OptionClass;
-import com.android.tradefed.device.DeviceNotAvailableException;
-import com.android.tradefed.device.ITestDevice;
-import com.android.tradefed.log.LogUtil.CLog;
-
-@OptionClass(alias = "fill-storage")
-public class FillStorageTargetPreparer implements ITargetCleaner {
-
- private static final String FILL_STORAGE_FILENAME = "/data/bigfile";
-
- @Option(name = "free-bytes",
- description = "Number of bytes that should be left free on the device.")
- private long mFreeBytesRequested;
-
- private long getDataFreeSpace(ITestDevice device) throws DeviceNotAvailableException {
- String output = device.executeShellCommand("df /data");
- String[] lines = output.split("\n");
- String[] splitLines = lines[1].split("\\s+");
- return Long.parseLong(splitLines[3]) * 1024L;
- }
-
- @Override
- public void setUp(ITestDevice device, IBuildInfo buildInfo)
- throws TargetSetupError, BuildError, DeviceNotAvailableException {
- long freeSpace = getDataFreeSpace(device);
- if (freeSpace > mFreeBytesRequested) {
- long bytesToWrite = freeSpace - mFreeBytesRequested;
- device.executeShellCommand(
- String.format("fallocate -l %d %s", bytesToWrite, FILL_STORAGE_FILENAME));
- CLog.i("Wrote %d bytes to %s", bytesToWrite, FILL_STORAGE_FILENAME);
- } else {
- CLog.i("Not enough free space (%d bytes requested free, %d bytes actually free)",
- mFreeBytesRequested, freeSpace);
- }
- }
-
- @Override
- public void tearDown(ITestDevice device, IBuildInfo buildInfo, Throwable e)
- throws DeviceNotAvailableException {
- device.executeShellCommand("rm -f " + FILL_STORAGE_FILENAME);
- }
-}
diff --git a/src/com/android/tradefed/targetprep/RestartSystemServerTargetPreparer.java b/src/com/android/tradefed/targetprep/RestartSystemServerTargetPreparer.java
index e8cf053..e4bb872 100644
--- a/src/com/android/tradefed/targetprep/RestartSystemServerTargetPreparer.java
+++ b/src/com/android/tradefed/targetprep/RestartSystemServerTargetPreparer.java
@@ -20,12 +20,11 @@ import com.android.tradefed.config.Option;
import com.android.tradefed.config.OptionClass;
import com.android.tradefed.device.DeviceNotAvailableException;
import com.android.tradefed.device.ITestDevice;
-import com.android.tradefed.log.LogUtil.CLog;
import com.android.tradefed.util.IRunUtil;
import com.android.tradefed.util.RunUtil;
@OptionClass(alias = "restart-system-server")
-public class RestartSystemServerTargetPreparer implements ITargetCleaner {
+public class RestartSystemServerTargetPreparer implements ITargetPreparer {
@Option(name = "poll-interval-millis",
description = "Time interval to poll if system server has restarted")
private long mPollIntervalMillis = 3000L;
@@ -33,12 +32,6 @@ public class RestartSystemServerTargetPreparer implements ITargetCleaner {
description = "Max number of tries to poll")
private int mMaxTries = 10;
- @Option(name = "restart-before")
- private boolean mRestartBefore = true;
-
- @Option(name = "restart-after")
- private boolean mRestartAfter = false;
-
private IRunUtil mRunUtil;
public RestartSystemServerTargetPreparer() {
@@ -49,7 +42,9 @@ public class RestartSystemServerTargetPreparer implements ITargetCleaner {
this.mRunUtil = runUtil;
}
- private boolean restartSystemServer(ITestDevice device) throws DeviceNotAvailableException {
+ @Override
+ public void setUp(ITestDevice device, IBuildInfo buildInfo)
+ throws TargetSetupError, BuildError, DeviceNotAvailableException {
device.executeShellCommand("setprop sys.boot_completed 0");
String pid = device.executeShellCommand("pidof system_server");
device.executeShellCommand("kill " + pid);
@@ -61,31 +56,9 @@ public class RestartSystemServerTargetPreparer implements ITargetCleaner {
}
mRunUtil.sleep(mPollIntervalMillis);
}
- return success;
- }
-
- @Override
- public void setUp(ITestDevice device, IBuildInfo buildInfo)
- throws TargetSetupError, BuildError, DeviceNotAvailableException {
- if (!mRestartBefore) {
- return;
- }
- boolean success = restartSystemServer(device);
if (!success) {
throw new TargetSetupError("Gave up on waiting for system server to restart",
device.getDeviceDescriptor());
}
}
-
- @Override
- public void tearDown(ITestDevice device, IBuildInfo buildInfo, Throwable e)
- throws DeviceNotAvailableException {
- if (!mRestartAfter) {
- return;
- }
- boolean success = restartSystemServer(device);
- if (!success) {
- CLog.i("Failed to restart system server on tearDown.");
- }
- }
}
diff --git a/src/com/android/tradefed/targetprep/RootTargetPreparer.java b/src/com/android/tradefed/targetprep/RootTargetPreparer.java
deleted file mode 100644
index 0035376..0000000
--- a/src/com/android/tradefed/targetprep/RootTargetPreparer.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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.
- */
-package com.android.tradefed.targetprep;
-
-import com.android.tradefed.build.IBuildInfo;
-import com.android.tradefed.config.OptionClass;
-import com.android.tradefed.device.DeviceNotAvailableException;
-import com.android.tradefed.device.ITestDevice;
-
-@OptionClass(alias = "root")
-public class RootTargetPreparer implements ITargetPreparer {
- @Override
- public void setUp(ITestDevice device, IBuildInfo buildInfo)
- throws TargetSetupError, BuildError, DeviceNotAvailableException {
- if (!device.enableAdbRoot()) {
- throw new TargetSetupError("Failed to adb root device", device.getDeviceDescriptor());
- }
- }
-}
diff --git a/src/com/android/tradefed/targetprep/SaveAndRestoreTimeTargetPreparer.java b/src/com/android/tradefed/targetprep/SaveAndRestoreTimeTargetPreparer.java
deleted file mode 100644
index 922efa7..0000000
--- a/src/com/android/tradefed/targetprep/SaveAndRestoreTimeTargetPreparer.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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.
- */
-
-package com.android.tradefed.targetprep;
-
-import com.android.tradefed.build.IBuildInfo;
-import com.android.tradefed.config.Option;
-import com.android.tradefed.config.OptionClass;
-import com.android.tradefed.device.DeviceNotAvailableException;
-import com.android.tradefed.device.ITestDevice;
-
-import java.util.concurrent.TimeUnit;
-
-// Remembers the time at the beginning and resets it (plus time elapsed) on cleanup.
-// Can also optionally set the time at the beginning.
-@OptionClass(alias = "save-restore-time")
-public class SaveAndRestoreTimeTargetPreparer implements ITargetCleaner {
-
- @Option(name = "set-time",
- description = "Whether or not to set the time")
- private boolean mSetTime = false;
-
- @Option(name = "time",
- description = "Time to set")
- private long mTimeToSet;
-
- public interface ITimeGetter {
- long getTime();
- }
-
- public static class RealTimeGetter implements ITimeGetter {
- @Override
- public long getTime() {
- return System.nanoTime();
- }
- }
-
- private long mStartNanoTime, mDeviceStartTimeMillis;
- private ITimeGetter mTimeGetter;
-
- public SaveAndRestoreTimeTargetPreparer(ITimeGetter timeGetter) {
- this.mTimeGetter = timeGetter;
- }
-
- public SaveAndRestoreTimeTargetPreparer() {
- this(new RealTimeGetter());
- }
-
- private long getDeviceTime(ITestDevice device) throws DeviceNotAvailableException {
- return Long.parseLong(device.executeShellCommand("date +\"%s\"").trim());
- }
-
- private void setDeviceTime(ITestDevice device, long time) throws DeviceNotAvailableException {
- device.executeShellCommand("date @" + time);
- }
-
- @Override
- public void setUp(ITestDevice device, IBuildInfo buildInfo)
- throws TargetSetupError, BuildError, DeviceNotAvailableException {
- mStartNanoTime = mTimeGetter.getTime();
- mDeviceStartTimeMillis = getDeviceTime(device);
- if (mSetTime) {
- setDeviceTime(device, mTimeToSet);
- }
- }
-
- @Override
- public void tearDown(ITestDevice device, IBuildInfo buildInfo, Throwable e)
- throws DeviceNotAvailableException {
- long elapsedNanos = mTimeGetter.getTime() - mStartNanoTime;
- long newTime = mDeviceStartTimeMillis + TimeUnit.NANOSECONDS.toMillis(elapsedNanos);
- setDeviceTime(device, newTime);
- }
-}
diff --git a/src/com/android/tradefed/targetprep/SetAndRestoreSystemPropertyTargetPreparer.java b/src/com/android/tradefed/targetprep/SetAndRestoreSystemPropertyTargetPreparer.java
deleted file mode 100644
index 5637876..0000000
--- a/src/com/android/tradefed/targetprep/SetAndRestoreSystemPropertyTargetPreparer.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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.
- */
-package com.android.tradefed.targetprep;
-
-import com.android.tradefed.build.IBuildInfo;
-import com.android.tradefed.config.Option;
-import com.android.tradefed.config.OptionClass;
-import com.android.tradefed.device.DeviceNotAvailableException;
-import com.android.tradefed.device.ITestDevice;
-
-import java.util.HashMap;
-import java.util.Map;
-
-@OptionClass(alias = "set-restore-sys-prop")
-public class SetAndRestoreSystemPropertyTargetPreparer implements ITargetCleaner {
-
- @Option(name = "set-property",
- description = "Property to set then restore on cleanup")
- private Map<String, String> mProperties = new HashMap<>();
-
- private Map<String, String> mOldProperties = new HashMap<>();
-
- private void setProperty(ITestDevice device, String prop, String newValue)
- throws DeviceNotAvailableException {
- device.executeShellCommand(String.format("setprop \"%s\" \"%s\"", prop, newValue));
- }
-
- private String getProperty(ITestDevice device, String prop)
- throws DeviceNotAvailableException {
- return device.executeShellCommand(String.format("getprop \"%s\"", prop)).trim();
- }
-
- @Override
- public void setUp(ITestDevice device, IBuildInfo buildInfo)
- throws TargetSetupError, BuildError, DeviceNotAvailableException {
- for (String prop : mProperties.keySet()) {
- String oldValue = getProperty(device, prop);
- mOldProperties.put(prop, oldValue);
- String newValue = mProperties.get(prop);
- setProperty(device, prop, newValue);
- if (!getProperty(device, prop).equals(newValue)) {
- throw new TargetSetupError("Failed to set property " + prop,
- device.getDeviceDescriptor());
- }
- }
- }
-
- @Override
- public void tearDown(ITestDevice device, IBuildInfo buildInfo, Throwable e)
- throws DeviceNotAvailableException {
- for (Map.Entry<String, String> entry : mOldProperties.entrySet()) {
- setProperty(device, entry.getKey(), entry.getValue());
- }
- }
-}
diff --git a/src/com/android/tradefed/targetprep/WriteAndRestoreFileTargetPreparer.java b/src/com/android/tradefed/targetprep/WriteAndRestoreFileTargetPreparer.java
deleted file mode 100644
index 53cb3ba..0000000
--- a/src/com/android/tradefed/targetprep/WriteAndRestoreFileTargetPreparer.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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.
- */
-package com.android.tradefed.targetprep;
-
-import com.android.tradefed.build.IBuildInfo;
-import com.android.tradefed.config.Option;
-import com.android.tradefed.config.OptionClass;
-import com.android.tradefed.device.DeviceNotAvailableException;
-import com.android.tradefed.device.ITestDevice;
-
-import java.io.File;
-
-@OptionClass(alias = "write-restore-file")
-public class WriteAndRestoreFileTargetPreparer implements ITargetCleaner {
- @Option(name = "file-name",
- description = "Name of file to write")
- private String mFileName;
-
- @Option(name = "contents",
- description = "Contents to write to file")
- private String mContents;
-
- private File mOldContents;
-
- @Override
- public void setUp(ITestDevice device, IBuildInfo buildInfo)
- throws TargetSetupError, BuildError, DeviceNotAvailableException {
- if (device.doesFileExist(mFileName)) {
- mOldContents = device.pullFile(mFileName);
- }
- if (!device.pushString(mContents, mFileName)) {
- throw new TargetSetupError("Failed to push string to file",
- device.getDeviceDescriptor());
- }
- }
-
- @Override
- public void tearDown(ITestDevice device, IBuildInfo buildInfo, Throwable e)
- throws DeviceNotAvailableException {
- if (mOldContents == null) {
- device.executeShellCommand(String.format("rm -f %s", mFileName));
- } else {
- device.pushFile(mOldContents, mFileName);
- }
- }
-}