mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-19 03:15:00 +00:00
test: fix some pylint errors in test_bind.py
* Use spaces not tabs * Limit lines to 100 spaces * Remove an unused import * Sort imports correctly * Add a module description Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
This commit is contained in:
parent
2be964d29f
commit
06d590844f
1 changed files with 148 additions and 143 deletions
|
@ -1,186 +1,191 @@
|
||||||
# SPDX-License-Identifier: GPL-2.0
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
|
# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
|
||||||
|
|
||||||
import os.path
|
""" Test for bind command """
|
||||||
import pytest
|
|
||||||
import re
|
import re
|
||||||
|
import pytest
|
||||||
|
|
||||||
def in_tree(response, name, uclass, drv, depth, last_child):
|
def in_tree(response, name, uclass, drv, depth, last_child):
|
||||||
lines = [x.strip() for x in response.splitlines()]
|
lines = [x.strip() for x in response.splitlines()]
|
||||||
leaf = ''
|
leaf = ''
|
||||||
if depth != 0:
|
if depth != 0:
|
||||||
leaf = ' ' + ' ' * (depth - 1) ;
|
leaf = ' ' + ' ' * (depth - 1)
|
||||||
if not last_child:
|
if not last_child:
|
||||||
leaf = leaf + r'\|'
|
leaf = leaf + r'\|'
|
||||||
else:
|
else:
|
||||||
leaf = leaf + '`'
|
leaf = leaf + '`'
|
||||||
|
|
||||||
leaf = leaf + '-- ' + name
|
leaf = leaf + '-- ' + name
|
||||||
line = (r' *{:10.10} *[0-9]* \[ [ +] \] {:20.20} [` |]{}$'
|
line = (r' *{:10.10} *[0-9]* \[ [ +] \] {:20.20} [` |]{}$'
|
||||||
.format(uclass, drv, leaf))
|
.format(uclass, drv, leaf))
|
||||||
prog = re.compile(line)
|
prog = re.compile(line)
|
||||||
for l in lines:
|
for l in lines:
|
||||||
if prog.match(l):
|
if prog.match(l):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.buildconfigspec('cmd_bind')
|
@pytest.mark.buildconfigspec('cmd_bind')
|
||||||
def test_bind_unbind_with_node(u_boot_console):
|
def test_bind_unbind_with_node(u_boot_console):
|
||||||
|
|
||||||
tree = u_boot_console.run_command('dm tree')
|
tree = u_boot_console.run_command('dm tree')
|
||||||
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
||||||
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, False)
|
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, False)
|
||||||
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
||||||
|
|
||||||
#bind usb_ether driver (which has no compatible) to usb@1 node.
|
#bind usb_ether driver (which has no compatible) to usb@1 node.
|
||||||
##New entry usb_ether should appear in the dm tree
|
##New entry usb_ether should appear in the dm tree
|
||||||
response = u_boot_console.run_command('bind /usb@1 usb_ether')
|
response = u_boot_console.run_command('bind /usb@1 usb_ether')
|
||||||
assert response == ''
|
assert response == ''
|
||||||
tree = u_boot_console.run_command('dm tree')
|
tree = u_boot_console.run_command('dm tree')
|
||||||
assert in_tree(tree, 'usb@1', 'ethernet', 'usb_ether', 1, True)
|
assert in_tree(tree, 'usb@1', 'ethernet', 'usb_ether', 1, True)
|
||||||
|
|
||||||
#Unbind child #1. No error expected and all devices should be there except for bind-test-child1
|
#Unbind child #1. No error expected and all devices should be there except for bind-test-child1
|
||||||
response = u_boot_console.run_command('unbind /bind-test/bind-test-child1')
|
response = u_boot_console.run_command('unbind /bind-test/bind-test-child1')
|
||||||
assert response == ''
|
assert response == ''
|
||||||
tree = u_boot_console.run_command('dm tree')
|
tree = u_boot_console.run_command('dm tree')
|
||||||
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
||||||
assert 'bind-test-child1' not in tree
|
assert 'bind-test-child1' not in tree
|
||||||
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
||||||
|
|
||||||
#bind child #1. No error expected and all devices should be there
|
#bind child #1. No error expected and all devices should be there
|
||||||
response = u_boot_console.run_command('bind /bind-test/bind-test-child1 phy_sandbox')
|
response = u_boot_console.run_command('bind /bind-test/bind-test-child1 phy_sandbox')
|
||||||
assert response == ''
|
assert response == ''
|
||||||
tree = u_boot_console.run_command('dm tree')
|
tree = u_boot_console.run_command('dm tree')
|
||||||
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
||||||
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, True)
|
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, True)
|
||||||
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, False)
|
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, False)
|
||||||
|
|
||||||
#Unbind child #2. No error expected and all devices should be there except for bind-test-child2
|
#Unbind child #2. No error expected and all devices should be there except for bind-test-child2
|
||||||
response = u_boot_console.run_command('unbind /bind-test/bind-test-child2')
|
response = u_boot_console.run_command('unbind /bind-test/bind-test-child2')
|
||||||
assert response == ''
|
assert response == ''
|
||||||
tree = u_boot_console.run_command('dm tree')
|
tree = u_boot_console.run_command('dm tree')
|
||||||
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
||||||
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, True)
|
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, True)
|
||||||
assert 'bind-test-child2' not in tree
|
assert 'bind-test-child2' not in tree
|
||||||
|
|
||||||
|
|
||||||
#Bind child #2. No error expected and all devices should be there
|
#Bind child #2. No error expected and all devices should be there
|
||||||
response = u_boot_console.run_command('bind /bind-test/bind-test-child2 simple_bus')
|
response = u_boot_console.run_command('bind /bind-test/bind-test-child2 simple_bus')
|
||||||
assert response == ''
|
assert response == ''
|
||||||
tree = u_boot_console.run_command('dm tree')
|
tree = u_boot_console.run_command('dm tree')
|
||||||
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
||||||
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, False)
|
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, False)
|
||||||
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
||||||
|
|
||||||
#Unbind parent. No error expected. All devices should be removed and unbound
|
#Unbind parent. No error expected. All devices should be removed and unbound
|
||||||
response = u_boot_console.run_command('unbind /bind-test')
|
response = u_boot_console.run_command('unbind /bind-test')
|
||||||
assert response == ''
|
assert response == ''
|
||||||
tree = u_boot_console.run_command('dm tree')
|
tree = u_boot_console.run_command('dm tree')
|
||||||
assert 'bind-test' not in tree
|
assert 'bind-test' not in tree
|
||||||
assert 'bind-test-child1' not in tree
|
assert 'bind-test-child1' not in tree
|
||||||
assert 'bind-test-child2' not in tree
|
assert 'bind-test-child2' not in tree
|
||||||
|
|
||||||
#try binding invalid node with valid driver
|
#try binding invalid node with valid driver
|
||||||
response = u_boot_console.run_command('bind /not-a-valid-node simple_bus')
|
response = u_boot_console.run_command('bind /not-a-valid-node simple_bus')
|
||||||
assert response != ''
|
assert response != ''
|
||||||
tree = u_boot_console.run_command('dm tree')
|
tree = u_boot_console.run_command('dm tree')
|
||||||
assert 'not-a-valid-node' not in tree
|
assert 'not-a-valid-node' not in tree
|
||||||
|
|
||||||
#try binding valid node with invalid driver
|
#try binding valid node with invalid driver
|
||||||
response = u_boot_console.run_command('bind /bind-test not_a_driver')
|
response = u_boot_console.run_command('bind /bind-test not_a_driver')
|
||||||
assert response != ''
|
assert response != ''
|
||||||
tree = u_boot_console.run_command('dm tree')
|
tree = u_boot_console.run_command('dm tree')
|
||||||
assert 'bind-test' not in tree
|
assert 'bind-test' not in tree
|
||||||
|
|
||||||
#bind /bind-test. Device should come up as well as its children
|
#bind /bind-test. Device should come up as well as its children
|
||||||
response = u_boot_console.run_command('bind /bind-test simple_bus')
|
response = u_boot_console.run_command('bind /bind-test simple_bus')
|
||||||
assert response == ''
|
assert response == ''
|
||||||
tree = u_boot_console.run_command('dm tree')
|
tree = u_boot_console.run_command('dm tree')
|
||||||
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
||||||
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, False)
|
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, False)
|
||||||
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
||||||
|
|
||||||
response = u_boot_console.run_command('unbind /bind-test')
|
response = u_boot_console.run_command('unbind /bind-test')
|
||||||
assert response == ''
|
assert response == ''
|
||||||
|
|
||||||
def get_next_line(tree, name):
|
def get_next_line(tree, name):
|
||||||
treelines = [x.strip() for x in tree.splitlines() if x.strip()]
|
treelines = [x.strip() for x in tree.splitlines() if x.strip()]
|
||||||
child_line = ''
|
child_line = ''
|
||||||
for idx, line in enumerate(treelines):
|
for idx, line in enumerate(treelines):
|
||||||
if ('-- ' + name) in line:
|
if '-- ' + name in line:
|
||||||
try:
|
try:
|
||||||
child_line = treelines[idx+1]
|
child_line = treelines[idx+1]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
break
|
break
|
||||||
return child_line
|
return child_line
|
||||||
|
|
||||||
@pytest.mark.buildconfigspec('cmd_bind')
|
@pytest.mark.buildconfigspec('cmd_bind')
|
||||||
def test_bind_unbind_with_uclass(u_boot_console):
|
def test_bind_unbind_with_uclass(u_boot_console):
|
||||||
#bind /bind-test
|
#bind /bind-test
|
||||||
response = u_boot_console.run_command('bind /bind-test simple_bus')
|
response = u_boot_console.run_command('bind /bind-test simple_bus')
|
||||||
assert response == ''
|
assert response == ''
|
||||||
|
|
||||||
#make sure bind-test-child2 is there and get its uclass/index pair
|
#make sure bind-test-child2 is there and get its uclass/index pair
|
||||||
tree = u_boot_console.run_command('dm tree')
|
tree = u_boot_console.run_command('dm tree')
|
||||||
child2_line = [x.strip() for x in tree.splitlines() if '-- bind-test-child2' in x]
|
child2_line = [x.strip() for x in tree.splitlines() if '-- bind-test-child2' in x]
|
||||||
assert len(child2_line) == 1
|
assert len(child2_line) == 1
|
||||||
|
|
||||||
child2_uclass = child2_line[0].split()[0]
|
child2_uclass = child2_line[0].split()[0]
|
||||||
child2_index = int(child2_line[0].split()[1])
|
child2_index = int(child2_line[0].split()[1])
|
||||||
|
|
||||||
#bind simple_bus as a child of bind-test-child2
|
#bind simple_bus as a child of bind-test-child2
|
||||||
response = u_boot_console.run_command('bind {} {} simple_bus'.format(child2_uclass, child2_index))
|
response = u_boot_console.run_command(
|
||||||
|
'bind {} {} simple_bus'.format(child2_uclass, child2_index))
|
||||||
|
|
||||||
#check that the child is there and its uclass/index pair is right
|
#check that the child is there and its uclass/index pair is right
|
||||||
tree = u_boot_console.run_command('dm tree')
|
tree = u_boot_console.run_command('dm tree')
|
||||||
|
|
||||||
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
|
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
|
||||||
assert child_of_child2_line
|
assert child_of_child2_line
|
||||||
child_of_child2_index = int(child_of_child2_line.split()[1])
|
child_of_child2_index = int(child_of_child2_line.split()[1])
|
||||||
assert in_tree(tree, 'simple_bus', 'simple_bus', 'simple_bus', 2, True)
|
assert in_tree(tree, 'simple_bus', 'simple_bus', 'simple_bus', 2, True)
|
||||||
assert child_of_child2_index == child2_index + 1
|
assert child_of_child2_index == child2_index + 1
|
||||||
|
|
||||||
#unbind the child and check it has been removed
|
#unbind the child and check it has been removed
|
||||||
response = u_boot_console.run_command('unbind simple_bus {}'.format(child_of_child2_index))
|
response = u_boot_console.run_command('unbind simple_bus {}'.format(child_of_child2_index))
|
||||||
assert response == ''
|
assert response == ''
|
||||||
tree = u_boot_console.run_command('dm tree')
|
tree = u_boot_console.run_command('dm tree')
|
||||||
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
||||||
assert not in_tree(tree, 'simple_bus', 'simple_bus', 'simple_bus', 2, True)
|
assert not in_tree(tree, 'simple_bus', 'simple_bus', 'simple_bus', 2, True)
|
||||||
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
|
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
|
||||||
assert child_of_child2_line == ''
|
assert child_of_child2_line == ''
|
||||||
|
|
||||||
#bind simple_bus as a child of bind-test-child2
|
#bind simple_bus as a child of bind-test-child2
|
||||||
response = u_boot_console.run_command('bind {} {} simple_bus'.format(child2_uclass, child2_index))
|
response = u_boot_console.run_command(
|
||||||
|
'bind {} {} simple_bus'.format(child2_uclass, child2_index))
|
||||||
|
|
||||||
#check that the child is there and its uclass/index pair is right
|
#check that the child is there and its uclass/index pair is right
|
||||||
tree = u_boot_console.run_command('dm tree')
|
tree = u_boot_console.run_command('dm tree')
|
||||||
treelines = [x.strip() for x in tree.splitlines() if x.strip()]
|
treelines = [x.strip() for x in tree.splitlines() if x.strip()]
|
||||||
|
|
||||||
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
|
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
|
||||||
assert child_of_child2_line
|
assert child_of_child2_line
|
||||||
child_of_child2_index = int(child_of_child2_line.split()[1])
|
child_of_child2_index = int(child_of_child2_line.split()[1])
|
||||||
assert in_tree(tree, 'simple_bus', 'simple_bus', 'simple_bus', 2, True)
|
assert in_tree(tree, 'simple_bus', 'simple_bus', 'simple_bus', 2, True)
|
||||||
assert child_of_child2_index == child2_index + 1
|
assert child_of_child2_index == child2_index + 1
|
||||||
|
|
||||||
#unbind the child and check it has been removed
|
#unbind the child and check it has been removed
|
||||||
response = u_boot_console.run_command('unbind {} {} simple_bus'.format(child2_uclass, child2_index))
|
response = u_boot_console.run_command(
|
||||||
assert response == ''
|
'unbind {} {} simple_bus'.format(child2_uclass, child2_index))
|
||||||
|
assert response == ''
|
||||||
|
|
||||||
tree = u_boot_console.run_command('dm tree')
|
tree = u_boot_console.run_command('dm tree')
|
||||||
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
||||||
|
|
||||||
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
|
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
|
||||||
assert child_of_child2_line == ''
|
assert child_of_child2_line == ''
|
||||||
|
|
||||||
#unbind the child again and check it doesn't change the tree
|
#unbind the child again and check it doesn't change the tree
|
||||||
tree_old = u_boot_console.run_command('dm tree')
|
tree_old = u_boot_console.run_command('dm tree')
|
||||||
response = u_boot_console.run_command('unbind {} {} simple_bus'.format(child2_uclass, child2_index))
|
response = u_boot_console.run_command(
|
||||||
tree_new = u_boot_console.run_command('dm tree')
|
'unbind {} {} simple_bus'.format(child2_uclass, child2_index))
|
||||||
|
tree_new = u_boot_console.run_command('dm tree')
|
||||||
|
|
||||||
assert response == ''
|
assert response == ''
|
||||||
assert tree_old == tree_new
|
assert tree_old == tree_new
|
||||||
|
|
||||||
response = u_boot_console.run_command('unbind /bind-test')
|
response = u_boot_console.run_command('unbind /bind-test')
|
||||||
assert response == ''
|
assert response == ''
|
||||||
|
|
Loading…
Add table
Reference in a new issue