1 import mock 2 import unittest 3 4 from autotest_lib.client.common_lib.cros.cfm.usb import usb_port_manager 5 6 # gpio for the port on bus 1, port 2. Specified in 7 # usb_port_manager._PORT_ID_TO_GPIO_INDEX_DICT 8 GPIO = 218 9 GPIO_PATH = '/sys/class/gpio/gpio%s' % GPIO 10 11 # pylint: disable=missing-docstring 12 class UsbPortManagerTest(unittest.TestCase): 13 14 def test_power_off_gpio_unexported(self): 15 host = mock.Mock() 16 host.get_board = mock.Mock(return_value='board: guado') 17 host.run = mock.Mock() 18 host.path_exists = mock.Mock(return_value=False) 19 port_manager = usb_port_manager.UsbPortManager(host) 20 port_manager.set_port_power([(1, 2)], False) 21 expected_runs = [ 22 mock.call('echo %s > /sys/class/gpio/export' % GPIO), 23 mock.call('echo out > %s/direction' % GPIO_PATH), 24 mock.call('echo 0 > %s/value' % GPIO_PATH), 25 mock.call('echo %s > /sys/class/gpio/unexport' % GPIO), 26 ] 27 host.run.assert_has_calls(expected_runs) 28 29 def test_power_on_gpio_exported(self): 30 host = mock.Mock() 31 host.get_board = mock.Mock(return_value='board: guado') 32 host.run = mock.Mock() 33 host.path_exists = mock.Mock(return_value=True) 34 port_manager = usb_port_manager.UsbPortManager(host) 35 port_manager.set_port_power([(1, 2)], True) 36 expected_runs = [ 37 mock.call('echo out > %s/direction' % GPIO_PATH), 38 mock.call('echo 1 > %s/value' % GPIO_PATH), 39 ] 40 host.run.assert_has_calls(expected_runs) 41