2 # Copyright 2015-2016 Samsung Electronics Co., Ltd.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
18 from litmus.device.device import device
19 from litmus.core.util import check_output, find_pattern
20 from litmus.core.util import call
23 class devicestandalone(device):
26 User can control device in topology by this class methods.
31 def __init__(self, *args, **kwargs):
34 self._name = kwargs['devicename']
35 if 'serialno' in kwargs:
36 self._id = kwargs['serialno']
38 self._id = self._find_device_id()
40 self._manager = kwargs['manager']
43 """docstring for _release"""
46 def _find_device_id(self):
47 """docstring for _find_device_id"""
48 self.start_sdb_server()
49 outs = check_output(['sdb', 'devices'], timeout=10)
50 pattern = '.*List of devices attached \n([a-zA-Z0-9]*).*device.*'
51 found = find_pattern(pattern, outs, groupindex=1)
59 Return the id of acquired device.
60 Device instance uses this id for sdb connection.
63 >>> dut = mgr.acquire_dut('xu3')
67 :returns str: device id
71 def on(self, booting_time=None):
73 Turn on the device acquired.
75 :param float powercut_delay: power-cut delay for cutter
77 logging.debug('=================Turn on device {}=================='
78 .format(self.get_name()))
80 self.start_sdb_server()
83 self.run_cmd('reboot -f', timeout=20)
84 wait_for_boot = booting_time if booting_time else self._booting_time
85 for loop in range(wait_for_boot):
86 logging.debug('Wait {} seconds......'
87 .format(wait_for_boot - loop))
89 self.start_sdb_server()
92 def off(self, powercut_delay=2):
94 Trun off the device acquired.
96 :param float powercut_delay: power-cut delay for cutter
98 logging.debug('off function is not supported for standalone device')
100 def flash(self, filenames, flasher='lthor', waiting=5,
101 partition_bin_mappings={'BOOT': 'zImage',
102 'ROOTFS': 'rootfs.img',
104 'SYSTEM-DATA': 'system-data.img'}):
106 Flash binaries to device.
107 This function turn on device and turn off device automatically.
109 :param dict filenames: filename string or dict
110 :param string flasher: external flashing tool name
111 :param float waiting: waiting time to acquire cdc_acm device
112 :param dict partition_bin_mappings: partition table for device which use heimdall flasher
115 >>> dut.flash(['boot.tar.gz','platform.tar.gz'])
117 >>> dut.flash('platform.tar.gz')
120 logging.debug('================Flash binaries to device============')
121 logging.debug(filenames)
123 self.start_sdb_server()
126 raise Exception('There\'s no file to flash.')
129 self._acquire_global_lock()
130 self.run_cmd('reboot -f download', timeout=20)
132 if flasher == 'lthor':
133 busid = self._find_usb_busid()
134 self._release_global_lock()
135 self._lthor(filenames=filenames, busid=busid)
136 elif flasher == 'heimdall':
137 (busaddr, devaddr) = self._find_usb_bus_and_device_address()
138 self._release_global_lock()
139 self._heimdall(filenames=filenames,
142 partition_bin_mappings=partition_bin_mappings)
143 except (Exception, KeyboardInterrupt) as e:
144 self._release_global_lock()
146 raise Exception('Can\'t flash files : {}.'.format(filenames))
148 def refresh_sdb_server(self):
149 """docstring for refresh_sdb_server"""
150 call('sdb kill-server; sdb start-server', shell=True, timeout=10)
153 def start_sdb_server(self):
154 """docstring for start_sdb_server"""
155 call('sdb start-server', shell=True, timeout=10)