]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/host_tests_plugins/host_test_plugins.py
3 Copyright (c) 2011-2013 ARM Limited
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
9 http://www.apache.org/licenses/LICENSE-2.0
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.
18 from os
import access
, F_OK
19 from sys
import stdout
20 from time
import sleep
21 from subprocess
import call
24 class HostTestPluginBase
:
25 """ Base class for all plug-ins used with host tests.
27 ###########################################################################
29 ###########################################################################
31 ###########################################################################
32 # Interface attributes defining plugin name, type etc.
33 ###########################################################################
34 name
= "HostTestPluginBase" # Plugin name, can be plugin class name
35 type = "BasePlugin" # Plugin type: ResetMethod, Copymethod etc.
36 capabilities
= [] # Capabilities names: what plugin can achieve
37 # (e.g. reset using some external command line tool)
38 stable
= False # Determine if plugin is stable and can be used
40 ###########################################################################
42 ###########################################################################
43 def setup(self
, *args
, **kwargs
):
44 """ Configure plugin, this function should be called before plugin execute() method is used.
48 def execute(self
, capabilitity
, *args
, **kwargs
):
49 """ Executes capability by name.
50 Each capability e.g. may directly just call some command line
51 program or execute building pythonic function
55 ###########################################################################
56 # Interface helper methods - overload only if you need to have custom behaviour
57 ###########################################################################
58 def print_plugin_error(self
, text
):
59 """ Function prints error in console and exits always with False
61 print "Plugin error: %s::%s: %s"% (self
.name
, self
.type, text
)
64 def print_plugin_info(self
, text
, NL
=True):
65 """ Function prints notification in console and exits always with True
68 print "Plugin info: %s::%s: %s"% (self
.name
, self
.type, text
)
70 print "Plugin info: %s::%s: %s"% (self
.name
, self
.type, text
),
73 def print_plugin_char(self
, char
):
74 """ Function prints char on stdout
80 def check_mount_point_ready(self
, destination_disk
, init_delay
=0.2, loop_delay
=0.25):
81 """ Checks if destination_disk is ready and can be accessed by e.g. copy commands
82 @init_delay - Initial delay time before first access check
83 @loop_delay - pooling delay for access check
85 if not access(destination_disk
, F_OK
):
86 self
.print_plugin_info("Waiting for mount point '%s' to be ready..."% destination_disk
, NL
=False)
88 while not access(destination_disk
, F_OK
):
90 self
.print_plugin_char('.')
92 def check_parameters(self
, capabilitity
, *args
, **kwargs
):
93 """ This function should be ran each time we call execute()
94 to check if none of the required parameters is missing.
96 missing_parameters
= []
97 for parameter
in self
.required_parameters
:
98 if parameter
not in kwargs
:
99 missing_parameters
.append(parameter
)
100 if len(missing_parameters
) > 0:
101 self
.print_plugin_error("execute parameter(s) '%s' missing!"% (', '.join(parameter
)))
105 def run_command(self
, cmd
, shell
=True):
106 """ Runs command from command line.
110 ret
= call(cmd
, shell
=shell
)
112 self
.print_plugin_error("[ret=%d] Command: %s"% (int(ret
), cmd
))
114 except Exception as e
:
116 self
.print_plugin_error("[ret=%d] Command: %s"% (int(ret
), cmd
))
117 self
.print_plugin_error(str(e
))