Mbed Host Tests
module_reset_mps2.py
Go to the documentation of this file.
1 """
2 mbed SDK
3 Copyright (c) 2011-2015 ARM Limited
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 
17 Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
18 """
19 
20 import os
21 import time
22 
23 from .host_test_plugins import HostTestPluginBase
24 
25 # Note: This plugin is not fully functional, needs improvements
26 
28  """! Plugin used to reset ARM_MPS2 platform
29 
30  @details Supports:
31  reboot.txt - startup from standby state, reboots when in run mode.
32  """
33 
34  # Plugin interface
35  name = 'HostTestPluginResetMethod_MPS2'
36  type = 'ResetMethod'
37  capabilities = ['reboot.txt']
38  required_parameters = ['disk']
39 
40  def __init__(self):
41  """ ctor
42  """
43  HostTestPluginBase.__init__(self)
44 
45  def touch_file(self, path):
46  """ Touch file and set timestamp to items
47  """
48  with open(path, 'a'):
49  os.utime(path, None)
50 
51  def setup(self, *args, **kwargs):
52  """ Prepare / configure plugin to work.
53  This method can receive plugin specific parameters by kwargs and
54  ignore other parameters which may affect other plugins.
55  """
56  return True
57 
58  def execute(self, capability, *args, **kwargs):
59  """! Executes capability by name
60 
61  @param capability Capability name
62  @param args Additional arguments
63  @param kwargs Additional arguments
64 
65  @details Each capability e.g. may directly just call some command line program or execute building pythonic function
66 
67  @return Capability call return value
68  """
69  result = False
70  if not kwargs['disk']:
71  self.print_plugin_errorprint_plugin_error("Error: disk not specified")
72  return False
73 
74  destination_disk = kwargs.get('disk', None)
75 
76  # This optional parameter can be used if TargetID is provided (-t switch)
77  target_id = kwargs.get('target_id', None)
78  pooling_timeout = kwargs.get('polling_timeout', 60)
79  if self.check_parameterscheck_parameters(capability, *args, **kwargs) is True:
80 
81  if capability == 'reboot.txt':
82  reboot_file_path = os.path.join(destination_disk, capability)
83  reboot_fh = open(reboot_file_path, "w")
84  reboot_fh.close()
85  # Make sure the file is written to the board before continuing
86  if os.name == 'posix':
87  self.run_commandrun_command('sync -f %s' % reboot_file_path, shell=True)
88  time.sleep(3) # sufficient delay for device to boot up
89  result, destination_disk = self.check_mount_point_readycheck_mount_point_ready(destination_disk, target_id=target_id, timeout=pooling_timeout)
90  return result
91 
93  """ Returns plugin available in this module
94  """
def run_command(self, cmd, shell=True)
Runs command from command line.
def check_mount_point_ready(self, destination_disk, init_delay=0.2, loop_delay=0.25, target_id=None, timeout=60)
Waits until destination_disk is ready and can be accessed by e.g.
def print_plugin_error(self, text)
Interface helper methods - overload only if you need to have custom behaviour.
def check_parameters(self, capability, *args, **kwargs)
This function should be ran each time we call execute() to check if none of the required parameters i...
def execute(self, capability, *args, **kwargs)
Executes capability by name.