Gem5Device: Add a gem5 device for Android
- Implementation of a gem5 device which allows simulated systems to be
used in the place of a real device. Currently, only Android is
supported.
- The gem5 simulation is started automatically based on a command line
passed in via the agenda. The correct telnet port to connect on is
extracted from the standard error from the gem5 process.
- Resuming from gem5 checkpoints is supported, and can be specified as
part of the gem5 system description. Additionally, the agenda option
checkpoint_post_boot can be used to create a checkpoint
automatically once the system has booted. This can then by used for
subsequent runs to avoid booting the system a second time.
- The Gem5Device waits for Android to finish booting, before sending
commands to the simulated device. Additionally, the device supports
a sleep option, which will sleep in the simulated system for a
number of seconds, prior to running the workload. This ensures that
the system can quieten down, prior to running the workload.
- The Gem5Device relies of VirtIO to pull files into the simulated
environment, and therefire diod support is required on the host
system. Additionally, VirtIO 9P support is required in the guest
system kernel.
- The m5 writefile binary and gem5 pseudo instruction are used to
extract files from the simulated environment.
2015-11-02 10:15:34 +00:00
|
|
|
# Copyright 2014-2015 ARM Limited
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Original implementation by Rene de Jong. Updated by Sascha Bischoff.
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
|
2015-11-13 11:42:21 +00:00
|
|
|
from wlauto import AndroidDevice, Parameter
|
|
|
|
from wlauto.common.gem5.device import BaseGem5Device
|
|
|
|
from wlauto.exceptions import DeviceError
|
Gem5Device: Add a gem5 device for Android
- Implementation of a gem5 device which allows simulated systems to be
used in the place of a real device. Currently, only Android is
supported.
- The gem5 simulation is started automatically based on a command line
passed in via the agenda. The correct telnet port to connect on is
extracted from the standard error from the gem5 process.
- Resuming from gem5 checkpoints is supported, and can be specified as
part of the gem5 system description. Additionally, the agenda option
checkpoint_post_boot can be used to create a checkpoint
automatically once the system has booted. This can then by used for
subsequent runs to avoid booting the system a second time.
- The Gem5Device waits for Android to finish booting, before sending
commands to the simulated device. Additionally, the device supports
a sleep option, which will sleep in the simulated system for a
number of seconds, prior to running the workload. This ensures that
the system can quieten down, prior to running the workload.
- The Gem5Device relies of VirtIO to pull files into the simulated
environment, and therefire diod support is required on the host
system. Additionally, VirtIO 9P support is required in the guest
system kernel.
- The m5 writefile binary and gem5 pseudo instruction are used to
extract files from the simulated environment.
2015-11-02 10:15:34 +00:00
|
|
|
|
|
|
|
|
2015-11-13 11:42:21 +00:00
|
|
|
class Gem5AndroidDevice(BaseGem5Device, AndroidDevice):
|
Gem5Device: Add a gem5 device for Android
- Implementation of a gem5 device which allows simulated systems to be
used in the place of a real device. Currently, only Android is
supported.
- The gem5 simulation is started automatically based on a command line
passed in via the agenda. The correct telnet port to connect on is
extracted from the standard error from the gem5 process.
- Resuming from gem5 checkpoints is supported, and can be specified as
part of the gem5 system description. Additionally, the agenda option
checkpoint_post_boot can be used to create a checkpoint
automatically once the system has booted. This can then by used for
subsequent runs to avoid booting the system a second time.
- The Gem5Device waits for Android to finish booting, before sending
commands to the simulated device. Additionally, the device supports
a sleep option, which will sleep in the simulated system for a
number of seconds, prior to running the workload. This ensures that
the system can quieten down, prior to running the workload.
- The Gem5Device relies of VirtIO to pull files into the simulated
environment, and therefire diod support is required on the host
system. Additionally, VirtIO 9P support is required in the guest
system kernel.
- The m5 writefile binary and gem5 pseudo instruction are used to
extract files from the simulated environment.
2015-11-02 10:15:34 +00:00
|
|
|
"""
|
|
|
|
Implements gem5 Android device.
|
|
|
|
|
|
|
|
This class allows a user to connect WA to a simulation using gem5. The
|
|
|
|
connection to the device is made using the telnet connection of the
|
|
|
|
simulator, and is used for all commands. The simulator does not have ADB
|
|
|
|
support, and therefore we need to fall back to using standard shell
|
|
|
|
commands.
|
|
|
|
|
|
|
|
Files are copied into the simulation using a VirtIO 9P device in gem5. Files
|
|
|
|
are copied out of the simulated environment using the m5 writefile command
|
|
|
|
within the simulated system.
|
|
|
|
|
|
|
|
When starting the workload run, the simulator is automatically started by
|
|
|
|
Workload Automation, and a connection to the simulator is established. WA
|
|
|
|
will then wait for Android to boot on the simulated system (which can take
|
|
|
|
hours), prior to executing any other commands on the device. It is also
|
|
|
|
possible to resume from a checkpoint when starting the simulation. To do
|
|
|
|
this, please append the relevant checkpoint commands from the gem5
|
|
|
|
simulation script to the gem5_discription argument in the agenda.
|
|
|
|
|
|
|
|
Host system requirements:
|
|
|
|
* VirtIO support. We rely on diod on the host system. This can be
|
|
|
|
installed on ubuntu using the following command:
|
|
|
|
|
|
|
|
sudo apt-get install diod
|
|
|
|
|
|
|
|
Guest requirements:
|
|
|
|
* VirtIO support. We rely on VirtIO to move files into the simulation.
|
|
|
|
Please make sure that the following are set in the kernel
|
|
|
|
configuration:
|
|
|
|
|
|
|
|
CONFIG_NET_9P=y
|
|
|
|
|
|
|
|
CONFIG_NET_9P_VIRTIO=y
|
|
|
|
|
|
|
|
CONFIG_9P_FS=y
|
|
|
|
|
|
|
|
CONFIG_9P_FS_POSIX_ACL=y
|
|
|
|
|
|
|
|
CONFIG_9P_FS_SECURITY=y
|
|
|
|
|
|
|
|
CONFIG_VIRTIO_BLK=y
|
|
|
|
|
|
|
|
* m5 binary. Please make sure that the m5 binary is on the device and
|
|
|
|
can by found in the path.
|
|
|
|
* Busybox. Due to restrictions, we assume that busybox is installed in
|
|
|
|
the guest system, and can be found in the path.
|
|
|
|
"""
|
|
|
|
|
|
|
|
name = 'gem5_android'
|
|
|
|
platform = 'android'
|
|
|
|
|
|
|
|
parameters = [
|
|
|
|
Parameter('core_names', default=[], override=True),
|
|
|
|
Parameter('core_clusters', default=[], override=True),
|
|
|
|
]
|
|
|
|
|
|
|
|
# Overwritten from Device. For documentation, see corresponding method in
|
|
|
|
# Device.
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
2015-11-13 11:42:21 +00:00
|
|
|
self.logger = logging.getLogger('Gem5AndroidDevice')
|
|
|
|
AndroidDevice.__init__(self, **kwargs)
|
|
|
|
BaseGem5Device.__init__(self, **kwargs)
|
Gem5Device: Add a gem5 device for Android
- Implementation of a gem5 device which allows simulated systems to be
used in the place of a real device. Currently, only Android is
supported.
- The gem5 simulation is started automatically based on a command line
passed in via the agenda. The correct telnet port to connect on is
extracted from the standard error from the gem5 process.
- Resuming from gem5 checkpoints is supported, and can be specified as
part of the gem5 system description. Additionally, the agenda option
checkpoint_post_boot can be used to create a checkpoint
automatically once the system has booted. This can then by used for
subsequent runs to avoid booting the system a second time.
- The Gem5Device waits for Android to finish booting, before sending
commands to the simulated device. Additionally, the device supports
a sleep option, which will sleep in the simulated system for a
number of seconds, prior to running the workload. This ensures that
the system can quieten down, prior to running the workload.
- The Gem5Device relies of VirtIO to pull files into the simulated
environment, and therefire diod support is required on the host
system. Additionally, VirtIO 9P support is required in the guest
system kernel.
- The m5 writefile binary and gem5 pseudo instruction are used to
extract files from the simulated environment.
2015-11-02 10:15:34 +00:00
|
|
|
|
2015-11-13 11:42:21 +00:00
|
|
|
def login_to_device(self):
|
|
|
|
pass
|
Gem5Device: Add a gem5 device for Android
- Implementation of a gem5 device which allows simulated systems to be
used in the place of a real device. Currently, only Android is
supported.
- The gem5 simulation is started automatically based on a command line
passed in via the agenda. The correct telnet port to connect on is
extracted from the standard error from the gem5 process.
- Resuming from gem5 checkpoints is supported, and can be specified as
part of the gem5 system description. Additionally, the agenda option
checkpoint_post_boot can be used to create a checkpoint
automatically once the system has booted. This can then by used for
subsequent runs to avoid booting the system a second time.
- The Gem5Device waits for Android to finish booting, before sending
commands to the simulated device. Additionally, the device supports
a sleep option, which will sleep in the simulated system for a
number of seconds, prior to running the workload. This ensures that
the system can quieten down, prior to running the workload.
- The Gem5Device relies of VirtIO to pull files into the simulated
environment, and therefire diod support is required on the host
system. Additionally, VirtIO 9P support is required in the guest
system kernel.
- The m5 writefile binary and gem5 pseudo instruction are used to
extract files from the simulated environment.
2015-11-02 10:15:34 +00:00
|
|
|
|
2015-11-13 11:42:21 +00:00
|
|
|
def wait_for_boot(self):
|
Gem5Device: Add a gem5 device for Android
- Implementation of a gem5 device which allows simulated systems to be
used in the place of a real device. Currently, only Android is
supported.
- The gem5 simulation is started automatically based on a command line
passed in via the agenda. The correct telnet port to connect on is
extracted from the standard error from the gem5 process.
- Resuming from gem5 checkpoints is supported, and can be specified as
part of the gem5 system description. Additionally, the agenda option
checkpoint_post_boot can be used to create a checkpoint
automatically once the system has booted. This can then by used for
subsequent runs to avoid booting the system a second time.
- The Gem5Device waits for Android to finish booting, before sending
commands to the simulated device. Additionally, the device supports
a sleep option, which will sleep in the simulated system for a
number of seconds, prior to running the workload. This ensures that
the system can quieten down, prior to running the workload.
- The Gem5Device relies of VirtIO to pull files into the simulated
environment, and therefire diod support is required on the host
system. Additionally, VirtIO 9P support is required in the guest
system kernel.
- The m5 writefile binary and gem5 pseudo instruction are used to
extract files from the simulated environment.
2015-11-02 10:15:34 +00:00
|
|
|
self.logger.info("Waiting for Android to boot...")
|
|
|
|
while True:
|
|
|
|
try:
|
2015-11-13 11:42:21 +00:00
|
|
|
booted = (1 == int('0' + self.gem5_shell('getprop sys.boot_completed', check_exit_code=False)))
|
|
|
|
anim_finished = (1 == int('0' + self.gem5_shell('getprop service.bootanim.exit', check_exit_code=False)))
|
|
|
|
if booted and anim_finished:
|
Gem5Device: Add a gem5 device for Android
- Implementation of a gem5 device which allows simulated systems to be
used in the place of a real device. Currently, only Android is
supported.
- The gem5 simulation is started automatically based on a command line
passed in via the agenda. The correct telnet port to connect on is
extracted from the standard error from the gem5 process.
- Resuming from gem5 checkpoints is supported, and can be specified as
part of the gem5 system description. Additionally, the agenda option
checkpoint_post_boot can be used to create a checkpoint
automatically once the system has booted. This can then by used for
subsequent runs to avoid booting the system a second time.
- The Gem5Device waits for Android to finish booting, before sending
commands to the simulated device. Additionally, the device supports
a sleep option, which will sleep in the simulated system for a
number of seconds, prior to running the workload. This ensures that
the system can quieten down, prior to running the workload.
- The Gem5Device relies of VirtIO to pull files into the simulated
environment, and therefire diod support is required on the host
system. Additionally, VirtIO 9P support is required in the guest
system kernel.
- The m5 writefile binary and gem5 pseudo instruction are used to
extract files from the simulated environment.
2015-11-02 10:15:34 +00:00
|
|
|
break
|
|
|
|
except (DeviceError, ValueError):
|
|
|
|
pass
|
|
|
|
time.sleep(60)
|
|
|
|
|
|
|
|
self.logger.info("Android booted")
|
|
|
|
|
2015-11-13 11:42:21 +00:00
|
|
|
def install(self, filepath, timeout=3 * 3600): # pylint: disable=W0221
|
Gem5Device: Add a gem5 device for Android
- Implementation of a gem5 device which allows simulated systems to be
used in the place of a real device. Currently, only Android is
supported.
- The gem5 simulation is started automatically based on a command line
passed in via the agenda. The correct telnet port to connect on is
extracted from the standard error from the gem5 process.
- Resuming from gem5 checkpoints is supported, and can be specified as
part of the gem5 system description. Additionally, the agenda option
checkpoint_post_boot can be used to create a checkpoint
automatically once the system has booted. This can then by used for
subsequent runs to avoid booting the system a second time.
- The Gem5Device waits for Android to finish booting, before sending
commands to the simulated device. Additionally, the device supports
a sleep option, which will sleep in the simulated system for a
number of seconds, prior to running the workload. This ensures that
the system can quieten down, prior to running the workload.
- The Gem5Device relies of VirtIO to pull files into the simulated
environment, and therefire diod support is required on the host
system. Additionally, VirtIO 9P support is required in the guest
system kernel.
- The m5 writefile binary and gem5 pseudo instruction are used to
extract files from the simulated environment.
2015-11-02 10:15:34 +00:00
|
|
|
""" Install an APK or a normal executable """
|
|
|
|
ext = os.path.splitext(filepath)[1].lower()
|
|
|
|
if ext == '.apk':
|
|
|
|
return self.install_apk(filepath, timeout)
|
|
|
|
else:
|
|
|
|
return self.install_executable(filepath)
|
|
|
|
|
2015-11-13 11:42:21 +00:00
|
|
|
def install_apk(self, filepath, timeout=3 * 3600): # pylint: disable=W0221
|
Gem5Device: Add a gem5 device for Android
- Implementation of a gem5 device which allows simulated systems to be
used in the place of a real device. Currently, only Android is
supported.
- The gem5 simulation is started automatically based on a command line
passed in via the agenda. The correct telnet port to connect on is
extracted from the standard error from the gem5 process.
- Resuming from gem5 checkpoints is supported, and can be specified as
part of the gem5 system description. Additionally, the agenda option
checkpoint_post_boot can be used to create a checkpoint
automatically once the system has booted. This can then by used for
subsequent runs to avoid booting the system a second time.
- The Gem5Device waits for Android to finish booting, before sending
commands to the simulated device. Additionally, the device supports
a sleep option, which will sleep in the simulated system for a
number of seconds, prior to running the workload. This ensures that
the system can quieten down, prior to running the workload.
- The Gem5Device relies of VirtIO to pull files into the simulated
environment, and therefire diod support is required on the host
system. Additionally, VirtIO 9P support is required in the guest
system kernel.
- The m5 writefile binary and gem5 pseudo instruction are used to
extract files from the simulated environment.
2015-11-02 10:15:34 +00:00
|
|
|
"""
|
|
|
|
Install an APK on the gem5 device
|
|
|
|
|
|
|
|
The APK is pushed to the device. Then the file and folder permissions
|
|
|
|
are changed to ensure that the APK can be correctly installed. The APK
|
|
|
|
is then installed on the device using 'pm'.
|
|
|
|
"""
|
|
|
|
self._check_ready()
|
|
|
|
self.logger.info("Installing {}".format(filepath))
|
|
|
|
ext = os.path.splitext(filepath)[1].lower()
|
|
|
|
if ext == '.apk':
|
|
|
|
filename = os.path.basename(filepath)
|
|
|
|
on_device_path = os.path.join('/data/local/tmp', filename)
|
|
|
|
self.push_file(filepath, on_device_path)
|
|
|
|
# We need to make sure that the folder permissions are set
|
|
|
|
# correctly, else the APK does not install correctly.
|
|
|
|
self.gem5_shell('busybox chmod 775 /data/local/tmp')
|
|
|
|
self.gem5_shell('busybox chmod 774 {}'.format(on_device_path))
|
|
|
|
self.logger.debug("Actually installing the APK: {}".format(on_device_path))
|
|
|
|
return self.gem5_shell("pm install {}".format(on_device_path))
|
|
|
|
else:
|
|
|
|
raise DeviceError('Can\'t install {}: unsupported format.'.format(filepath))
|
|
|
|
|
|
|
|
def install_executable(self, filepath, with_name=None):
|
|
|
|
""" Install an executable """
|
|
|
|
executable_name = os.path.basename(filepath)
|
|
|
|
on_device_file = self.path.join(self.working_directory, executable_name)
|
|
|
|
on_device_executable = self.path.join(self.binaries_directory, executable_name)
|
|
|
|
self.push_file(filepath, on_device_file)
|
|
|
|
self.execute('busybox cp {} {}'.format(on_device_file, on_device_executable))
|
|
|
|
self.execute('busybox chmod 0777 {}'.format(on_device_executable))
|
|
|
|
return on_device_executable
|
|
|
|
|
|
|
|
def uninstall(self, package):
|
|
|
|
self._check_ready()
|
|
|
|
self.gem5_shell("pm uninstall {}".format(package))
|
|
|
|
|
|
|
|
def dump_logcat(self, outfile, filter_spec=None):
|
|
|
|
""" Extract logcat from simulation """
|
|
|
|
self.logger.info("Extracting logcat from the simulated system")
|
|
|
|
filename = outfile.split('/')[-1]
|
|
|
|
command = 'logcat -d > {}'.format(filename)
|
|
|
|
self.gem5_shell(command)
|
|
|
|
self.pull_file("{}".format(filename), outfile)
|
|
|
|
|
|
|
|
def clear_logcat(self):
|
|
|
|
"""Clear (flush) logcat log."""
|
|
|
|
if self._logcat_poller:
|
|
|
|
return self._logcat_poller.clear_buffer()
|
|
|
|
else:
|
|
|
|
return self.gem5_shell('logcat -c')
|
|
|
|
|
|
|
|
def disable_selinux(self):
|
|
|
|
""" Disable SELinux. Overridden as parent implementation uses ADB """
|
|
|
|
api_level = int(self.gem5_shell('getprop ro.build.version.sdk').strip())
|
|
|
|
|
|
|
|
# SELinux was added in Android 4.3 (API level 18). Trying to
|
|
|
|
# 'getenforce' in earlier versions will produce an error.
|
|
|
|
if api_level >= 18:
|
|
|
|
se_status = self.execute('getenforce', as_root=True).strip()
|
|
|
|
if se_status == 'Enforcing':
|
|
|
|
self.execute('setenforce 0', as_root=True)
|
|
|
|
|
|
|
|
def get_properties(self, context): # pylint: disable=R0801
|
|
|
|
""" Get the property files from the device """
|
2015-11-13 11:42:21 +00:00
|
|
|
BaseGem5Device.get_properties(self, context)
|
2015-11-10 13:28:25 +00:00
|
|
|
props = self._get_android_properties(context)
|
2015-11-13 11:42:21 +00:00
|
|
|
return props
|
Gem5Device: Add a gem5 device for Android
- Implementation of a gem5 device which allows simulated systems to be
used in the place of a real device. Currently, only Android is
supported.
- The gem5 simulation is started automatically based on a command line
passed in via the agenda. The correct telnet port to connect on is
extracted from the standard error from the gem5 process.
- Resuming from gem5 checkpoints is supported, and can be specified as
part of the gem5 system description. Additionally, the agenda option
checkpoint_post_boot can be used to create a checkpoint
automatically once the system has booted. This can then by used for
subsequent runs to avoid booting the system a second time.
- The Gem5Device waits for Android to finish booting, before sending
commands to the simulated device. Additionally, the device supports
a sleep option, which will sleep in the simulated system for a
number of seconds, prior to running the workload. This ensures that
the system can quieten down, prior to running the workload.
- The Gem5Device relies of VirtIO to pull files into the simulated
environment, and therefire diod support is required on the host
system. Additionally, VirtIO 9P support is required in the guest
system kernel.
- The m5 writefile binary and gem5 pseudo instruction are used to
extract files from the simulated environment.
2015-11-02 10:15:34 +00:00
|
|
|
|
|
|
|
def disable_screen_lock(self):
|
|
|
|
"""
|
|
|
|
Attempts to disable he screen lock on the device.
|
|
|
|
|
|
|
|
Overridden here as otherwise we have issues with too many backslashes.
|
|
|
|
"""
|
|
|
|
lockdb = '/data/system/locksettings.db'
|
|
|
|
sqlcommand = "update locksettings set value=\'0\' where name=\'screenlock.disabled\';"
|
|
|
|
self.execute('sqlite3 {} "{}"'.format(lockdb, sqlcommand), as_root=True)
|
|
|
|
|
|
|
|
def capture_screen(self, filepath):
|
2015-11-13 11:42:21 +00:00
|
|
|
if BaseGem5Device.capture_screen(self, filepath):
|
|
|
|
return
|
Gem5Device: Add a gem5 device for Android
- Implementation of a gem5 device which allows simulated systems to be
used in the place of a real device. Currently, only Android is
supported.
- The gem5 simulation is started automatically based on a command line
passed in via the agenda. The correct telnet port to connect on is
extracted from the standard error from the gem5 process.
- Resuming from gem5 checkpoints is supported, and can be specified as
part of the gem5 system description. Additionally, the agenda option
checkpoint_post_boot can be used to create a checkpoint
automatically once the system has booted. This can then by used for
subsequent runs to avoid booting the system a second time.
- The Gem5Device waits for Android to finish booting, before sending
commands to the simulated device. Additionally, the device supports
a sleep option, which will sleep in the simulated system for a
number of seconds, prior to running the workload. This ensures that
the system can quieten down, prior to running the workload.
- The Gem5Device relies of VirtIO to pull files into the simulated
environment, and therefire diod support is required on the host
system. Additionally, VirtIO 9P support is required in the guest
system kernel.
- The m5 writefile binary and gem5 pseudo instruction are used to
extract files from the simulated environment.
2015-11-02 10:15:34 +00:00
|
|
|
|
|
|
|
# If we didn't manage to do the above, call the parent class.
|
2015-11-10 12:52:50 +00:00
|
|
|
self.logger.warning("capture_screen: falling back to parent class implementation")
|
2015-11-13 11:42:21 +00:00
|
|
|
AndroidDevice.capture_screen(self, filepath)
|