2018-08-09 14:17:46 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
|
|
|
|
import os.path
|
|
|
|
import pytest
|
|
|
|
import re
|
|
|
|
|
|
|
|
def in_tree(response, name, uclass, drv, depth, last_child):
|
|
|
|
lines = [x.strip() for x in response.splitlines()]
|
|
|
|
leaf = ' ' * 4 * depth;
|
|
|
|
if not last_child:
|
2019-10-24 15:59:28 +00:00
|
|
|
leaf = leaf + r'\|'
|
2018-08-09 14:17:46 +00:00
|
|
|
else:
|
|
|
|
leaf = leaf + '`'
|
|
|
|
leaf = leaf + '-- ' + name
|
2019-10-24 15:59:28 +00:00
|
|
|
line = (r' *{:10.10} [0-9]* \[ [ +] \] {:20.20} {}$'
|
2018-12-06 01:42:52 +00:00
|
|
|
.format(uclass, drv, leaf))
|
2018-08-09 14:17:46 +00:00
|
|
|
prog = re.compile(line)
|
|
|
|
for l in lines:
|
|
|
|
if prog.match(l):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.buildconfigspec('cmd_bind')
|
|
|
|
def test_bind_unbind_with_node(u_boot_console):
|
|
|
|
|
|
|
|
#bind /bind-test. Device should come up as well as its children
|
2020-06-25 04:10:04 +00:00
|
|
|
response = u_boot_console.run_command('bind /bind-test simple_bus')
|
2018-08-09 14:17:46 +00:00
|
|
|
assert response == ''
|
2018-12-27 15:11:13 +00:00
|
|
|
tree = u_boot_console.run_command('dm tree')
|
2020-06-25 04:10:04 +00:00
|
|
|
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
2018-12-27 15:11:13 +00:00
|
|
|
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, False)
|
2020-06-25 04:10:04 +00:00
|
|
|
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
2018-08-09 14:17:46 +00:00
|
|
|
|
|
|
|
#Unbind child #1. No error expected and all devices should be there except for bind-test-child1
|
2018-12-27 15:11:13 +00:00
|
|
|
response = u_boot_console.run_command('unbind /bind-test/bind-test-child1')
|
2018-08-09 14:17:46 +00:00
|
|
|
assert response == ''
|
2018-12-27 15:11:13 +00:00
|
|
|
tree = u_boot_console.run_command('dm tree')
|
2020-06-25 04:10:04 +00:00
|
|
|
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
2018-12-27 15:11:13 +00:00
|
|
|
assert 'bind-test-child1' not in tree
|
2020-06-25 04:10:04 +00:00
|
|
|
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
2018-08-09 14:17:46 +00:00
|
|
|
|
|
|
|
#bind child #1. No error expected and all devices should be there
|
2018-12-27 15:11:13 +00:00
|
|
|
response = u_boot_console.run_command('bind /bind-test/bind-test-child1 phy_sandbox')
|
2018-08-09 14:17:46 +00:00
|
|
|
assert response == ''
|
2018-12-27 15:11:13 +00:00
|
|
|
tree = u_boot_console.run_command('dm tree')
|
2020-06-25 04:10:04 +00:00
|
|
|
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
2018-12-27 15:11:13 +00:00
|
|
|
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, True)
|
2020-06-25 04:10:04 +00:00
|
|
|
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, False)
|
2018-08-09 14:17:46 +00:00
|
|
|
|
|
|
|
#Unbind child #2. No error expected and all devices should be there except for bind-test-child2
|
2018-12-27 15:11:13 +00:00
|
|
|
response = u_boot_console.run_command('unbind /bind-test/bind-test-child2')
|
2018-08-09 14:17:46 +00:00
|
|
|
assert response == ''
|
2018-12-27 15:11:13 +00:00
|
|
|
tree = u_boot_console.run_command('dm tree')
|
2020-06-25 04:10:04 +00:00
|
|
|
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
2018-12-27 15:11:13 +00:00
|
|
|
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, True)
|
|
|
|
assert 'bind-test-child2' not in tree
|
2018-08-09 14:17:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
#Bind child #2. No error expected and all devices should be there
|
2020-06-25 04:10:04 +00:00
|
|
|
response = u_boot_console.run_command('bind /bind-test/bind-test-child2 simple_bus')
|
2018-08-09 14:17:46 +00:00
|
|
|
assert response == ''
|
2018-12-27 15:11:13 +00:00
|
|
|
tree = u_boot_console.run_command('dm tree')
|
2020-06-25 04:10:04 +00:00
|
|
|
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
2018-12-27 15:11:13 +00:00
|
|
|
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, False)
|
2020-06-25 04:10:04 +00:00
|
|
|
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
2018-08-09 14:17:46 +00:00
|
|
|
|
|
|
|
#Unbind parent. No error expected. All devices should be removed and unbound
|
2018-12-27 15:11:13 +00:00
|
|
|
response = u_boot_console.run_command('unbind /bind-test')
|
2018-08-09 14:17:46 +00:00
|
|
|
assert response == ''
|
2018-12-27 15:11:13 +00:00
|
|
|
tree = u_boot_console.run_command('dm tree')
|
|
|
|
assert 'bind-test' not in tree
|
|
|
|
assert 'bind-test-child1' not in tree
|
|
|
|
assert 'bind-test-child2' not in tree
|
2018-08-09 14:17:46 +00:00
|
|
|
|
|
|
|
#try binding invalid node with valid driver
|
2020-06-25 04:10:04 +00:00
|
|
|
response = u_boot_console.run_command('bind /not-a-valid-node simple_bus')
|
2018-08-09 14:17:46 +00:00
|
|
|
assert response != ''
|
2018-12-27 15:11:13 +00:00
|
|
|
tree = u_boot_console.run_command('dm tree')
|
|
|
|
assert 'not-a-valid-node' not in tree
|
2018-08-09 14:17:46 +00:00
|
|
|
|
|
|
|
#try binding valid node with invalid driver
|
2018-12-27 15:11:13 +00:00
|
|
|
response = u_boot_console.run_command('bind /bind-test not_a_driver')
|
2018-08-09 14:17:46 +00:00
|
|
|
assert response != ''
|
2018-12-27 15:11:13 +00:00
|
|
|
tree = u_boot_console.run_command('dm tree')
|
|
|
|
assert 'bind-test' not in tree
|
2018-08-09 14:17:46 +00:00
|
|
|
|
|
|
|
#bind /bind-test. Device should come up as well as its children
|
2020-06-25 04:10:04 +00:00
|
|
|
response = u_boot_console.run_command('bind /bind-test simple_bus')
|
2018-08-09 14:17:46 +00:00
|
|
|
assert response == ''
|
2018-12-27 15:11:13 +00:00
|
|
|
tree = u_boot_console.run_command('dm tree')
|
2020-06-25 04:10:04 +00:00
|
|
|
assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
|
2018-12-27 15:11:13 +00:00
|
|
|
assert in_tree(tree, 'bind-test-child1', 'phy', 'phy_sandbox', 1, False)
|
2020-06-25 04:10:04 +00:00
|
|
|
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
2018-08-09 14:17:46 +00:00
|
|
|
|
2018-12-27 15:11:13 +00:00
|
|
|
response = u_boot_console.run_command('unbind /bind-test')
|
2018-08-09 14:17:46 +00:00
|
|
|
assert response == ''
|
|
|
|
|
|
|
|
def get_next_line(tree, name):
|
|
|
|
treelines = [x.strip() for x in tree.splitlines() if x.strip()]
|
2018-12-27 15:11:13 +00:00
|
|
|
child_line = ''
|
2018-08-09 14:17:46 +00:00
|
|
|
for idx, line in enumerate(treelines):
|
2018-12-27 15:11:13 +00:00
|
|
|
if ('-- ' + name) in line:
|
2018-08-09 14:17:46 +00:00
|
|
|
try:
|
|
|
|
child_line = treelines[idx+1]
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
break
|
|
|
|
return child_line
|
|
|
|
|
|
|
|
@pytest.mark.buildconfigspec('cmd_bind')
|
|
|
|
def test_bind_unbind_with_uclass(u_boot_console):
|
|
|
|
#bind /bind-test
|
2020-06-25 04:10:04 +00:00
|
|
|
response = u_boot_console.run_command('bind /bind-test simple_bus')
|
2018-08-09 14:17:46 +00:00
|
|
|
assert response == ''
|
|
|
|
|
|
|
|
#make sure bind-test-child2 is there and get its uclass/index pair
|
2018-12-27 15:11:13 +00:00
|
|
|
tree = u_boot_console.run_command('dm tree')
|
|
|
|
child2_line = [x.strip() for x in tree.splitlines() if '-- bind-test-child2' in x]
|
2018-08-09 14:17:46 +00:00
|
|
|
assert len(child2_line) == 1
|
|
|
|
|
|
|
|
child2_uclass = child2_line[0].split()[0]
|
|
|
|
child2_index = int(child2_line[0].split()[1])
|
|
|
|
|
2020-06-25 04:10:04 +00:00
|
|
|
#bind simple_bus as a child of bind-test-child2
|
|
|
|
response = u_boot_console.run_command('bind {} {} simple_bus'.format(child2_uclass, child2_index, 'simple_bus'))
|
2018-08-09 14:17:46 +00:00
|
|
|
|
|
|
|
#check that the child is there and its uclass/index pair is right
|
2018-12-27 15:11:13 +00:00
|
|
|
tree = u_boot_console.run_command('dm tree')
|
2018-08-09 14:17:46 +00:00
|
|
|
|
2018-12-27 15:11:13 +00:00
|
|
|
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
|
2018-08-09 14:17:46 +00:00
|
|
|
assert child_of_child2_line
|
|
|
|
child_of_child2_index = int(child_of_child2_line.split()[1])
|
2020-06-25 04:10:04 +00:00
|
|
|
assert in_tree(tree, 'simple_bus', 'simple_bus', 'simple_bus', 2, True)
|
2018-08-09 14:17:46 +00:00
|
|
|
assert child_of_child2_index == child2_index + 1
|
|
|
|
|
|
|
|
#unbind the child and check it has been removed
|
2018-12-27 15:11:13 +00:00
|
|
|
response = u_boot_console.run_command('unbind simple_bus {}'.format(child_of_child2_index))
|
2018-08-09 14:17:46 +00:00
|
|
|
assert response == ''
|
2018-12-27 15:11:13 +00:00
|
|
|
tree = u_boot_console.run_command('dm tree')
|
2020-06-25 04:10:04 +00:00
|
|
|
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)
|
2018-12-27 15:11:13 +00:00
|
|
|
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
|
|
|
|
assert child_of_child2_line == ''
|
2018-08-09 14:17:46 +00:00
|
|
|
|
2020-06-25 04:10:04 +00:00
|
|
|
#bind simple_bus as a child of bind-test-child2
|
|
|
|
response = u_boot_console.run_command('bind {} {} simple_bus'.format(child2_uclass, child2_index, 'simple_bus'))
|
2018-08-09 14:17:46 +00:00
|
|
|
|
|
|
|
#check that the child is there and its uclass/index pair is right
|
2018-12-27 15:11:13 +00:00
|
|
|
tree = u_boot_console.run_command('dm tree')
|
2018-08-09 14:17:46 +00:00
|
|
|
treelines = [x.strip() for x in tree.splitlines() if x.strip()]
|
|
|
|
|
2018-12-27 15:11:13 +00:00
|
|
|
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
|
2018-08-09 14:17:46 +00:00
|
|
|
assert child_of_child2_line
|
|
|
|
child_of_child2_index = int(child_of_child2_line.split()[1])
|
2020-06-25 04:10:04 +00:00
|
|
|
assert in_tree(tree, 'simple_bus', 'simple_bus', 'simple_bus', 2, True)
|
2018-08-09 14:17:46 +00:00
|
|
|
assert child_of_child2_index == child2_index + 1
|
|
|
|
|
|
|
|
#unbind the child and check it has been removed
|
2020-06-25 04:10:04 +00:00
|
|
|
response = u_boot_console.run_command('unbind {} {} simple_bus'.format(child2_uclass, child2_index, 'simple_bus'))
|
2018-08-09 14:17:46 +00:00
|
|
|
assert response == ''
|
|
|
|
|
2018-12-27 15:11:13 +00:00
|
|
|
tree = u_boot_console.run_command('dm tree')
|
2020-06-25 04:10:04 +00:00
|
|
|
assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)
|
2018-08-09 14:17:46 +00:00
|
|
|
|
2018-12-27 15:11:13 +00:00
|
|
|
child_of_child2_line = get_next_line(tree, 'bind-test-child2')
|
|
|
|
assert child_of_child2_line == ''
|
2018-08-09 14:17:46 +00:00
|
|
|
|
|
|
|
#unbind the child again and check it doesn't change the tree
|
2018-12-27 15:11:13 +00:00
|
|
|
tree_old = u_boot_console.run_command('dm tree')
|
2020-06-25 04:10:04 +00:00
|
|
|
response = u_boot_console.run_command('unbind {} {} simple_bus'.format(child2_uclass, child2_index, 'simple_bus'))
|
2018-12-27 15:11:13 +00:00
|
|
|
tree_new = u_boot_console.run_command('dm tree')
|
2018-08-09 14:17:46 +00:00
|
|
|
|
|
|
|
assert response == ''
|
|
|
|
assert tree_old == tree_new
|
|
|
|
|
2018-12-27 15:11:13 +00:00
|
|
|
response = u_boot_console.run_command('unbind /bind-test')
|
2018-08-09 14:17:46 +00:00
|
|
|
assert response == ''
|