From bcff3fdb8cf4eff1035261dee2b09d6af502de80 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Wed, 11 Oct 2017 11:10:28 -0700 Subject: Add some target preparers and add tests One target preparer that just reboot One target preparer that restarts the system server Also added contrib tests as part of google-tradefed-all Test: run_tradefed_tests.sh Change-Id: I2a24e08e7c86199e9cab66a602417c18be0b4c1a --- .../tradefed/targetprep/RebootTargetPreparer.java | 30 ++++++++++++++ .../RestartSystemServerTargetPreparer.java | 46 ++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/com/android/tradefed/targetprep/RebootTargetPreparer.java create mode 100644 src/com/android/tradefed/targetprep/RestartSystemServerTargetPreparer.java (limited to 'src') diff --git a/src/com/android/tradefed/targetprep/RebootTargetPreparer.java b/src/com/android/tradefed/targetprep/RebootTargetPreparer.java new file mode 100644 index 0000000..fb7f3f0 --- /dev/null +++ b/src/com/android/tradefed/targetprep/RebootTargetPreparer.java @@ -0,0 +1,30 @@ +/* + * 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 = "reboot") +public class RebootTargetPreparer implements ITargetPreparer { + @Override + public void setUp(ITestDevice device, IBuildInfo buildInfo) + throws TargetSetupError, BuildError, DeviceNotAvailableException { + device.reboot(); + } +} diff --git a/src/com/android/tradefed/targetprep/RestartSystemServerTargetPreparer.java b/src/com/android/tradefed/targetprep/RestartSystemServerTargetPreparer.java new file mode 100644 index 0000000..18d9027 --- /dev/null +++ b/src/com/android/tradefed/targetprep/RestartSystemServerTargetPreparer.java @@ -0,0 +1,46 @@ +/* + * 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; +import com.android.tradefed.util.IRunUtil; +import com.android.tradefed.util.RunUtil; + +@OptionClass(alias = "restart-system-server") +public class RestartSystemServerTargetPreparer implements ITargetPreparer { + private static final long SLEEP_MILLIS = 5000L; + + private IRunUtil mRunUtil; + + public RestartSystemServerTargetPreparer() { + this(RunUtil.getDefault()); + } + + public RestartSystemServerTargetPreparer(IRunUtil runUtil) { + this.mRunUtil = runUtil; + } + + @Override + public void setUp(ITestDevice device, IBuildInfo buildInfo) + throws TargetSetupError, BuildError, DeviceNotAvailableException { + String pid = device.executeShellCommand("pidof system_server"); + device.executeShellCommand("kill " + pid); + mRunUtil.sleep(SLEEP_MILLIS); + } +} -- cgit v1.2.3