# 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 = ''
	if depth != 0:
		leaf = '   ' + '    ' * (depth - 1) ;
		if not last_child:
			leaf = leaf + r'\|'
		else:
                        leaf = leaf + '`'

	leaf = leaf + '-- ' + name
	line = (r' *{:10.10} *[0-9]*  \[ [ +] \]   {:20.20}  [` |]{}$'
	        .format(uclass, drv, leaf))
	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):

	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-child1', 'phy', 'phy_sandbox', 1, False)
	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.
	##New entry usb_ether should appear in the dm tree
	response = u_boot_console.run_command('bind  /usb@1 usb_ether')
	assert response == ''
	tree = u_boot_console.run_command('dm tree')
	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
	response = u_boot_console.run_command('unbind  /bind-test/bind-test-child1')
	assert response == ''
	tree = u_boot_console.run_command('dm tree')
	assert in_tree(tree, 'bind-test', 'simple_bus', 'simple_bus', 0, True)
	assert 'bind-test-child1' not in tree
	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
	response = u_boot_console.run_command('bind  /bind-test/bind-test-child1 phy_sandbox')
	assert response == ''
	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-child1', 'phy', 'phy_sandbox', 1, True)
	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
	response = u_boot_console.run_command('unbind  /bind-test/bind-test-child2')
	assert response == ''
	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-child1', 'phy', 'phy_sandbox', 1, True)
	assert 'bind-test-child2' not in tree


	#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')
	assert response == ''
	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-child1', 'phy', 'phy_sandbox', 1, False)
	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
	response = u_boot_console.run_command('unbind  /bind-test')
	assert response == ''
	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

	#try binding invalid node with valid driver
	response = u_boot_console.run_command('bind  /not-a-valid-node simple_bus')
	assert response != ''
	tree = u_boot_console.run_command('dm tree')
	assert 'not-a-valid-node' not in tree

	#try binding valid node with invalid driver
	response = u_boot_console.run_command('bind  /bind-test not_a_driver')
	assert response != ''
	tree = u_boot_console.run_command('dm tree')
	assert 'bind-test' not in tree

	#bind /bind-test. Device should come up as well as its children
	response = u_boot_console.run_command('bind  /bind-test simple_bus')
	assert response == ''
	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-child1', 'phy', 'phy_sandbox', 1, False)
	assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)

	response = u_boot_console.run_command('unbind  /bind-test')
	assert response == ''

def get_next_line(tree, name):
	treelines = [x.strip() for x in tree.splitlines() if x.strip()]
	child_line = ''
	for idx, line in enumerate(treelines):
		if ('-- ' + name) in line:
			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
	response = u_boot_console.run_command('bind  /bind-test simple_bus')
	assert response == ''

	#make sure bind-test-child2 is there and get its uclass/index pair
	tree = u_boot_console.run_command('dm tree')
	child2_line = [x.strip() for x in tree.splitlines() if '-- bind-test-child2' in x]
	assert len(child2_line) == 1

	child2_uclass = child2_line[0].split()[0]
	child2_index = int(child2_line[0].split()[1])

	#bind simple_bus as a child of bind-test-child2
	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
	tree = u_boot_console.run_command('dm tree')

	child_of_child2_line = get_next_line(tree, 'bind-test-child2')
	assert child_of_child2_line
	child_of_child2_index = int(child_of_child2_line.split()[1])
	assert in_tree(tree, 'simple_bus', 'simple_bus', 'simple_bus', 2, True)
	assert child_of_child2_index == child2_index + 1

	#unbind the child and check it has been removed
	response = u_boot_console.run_command('unbind  simple_bus {}'.format(child_of_child2_index))
	assert response == ''
	tree = u_boot_console.run_command('dm tree')
	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)
	child_of_child2_line = get_next_line(tree, 'bind-test-child2')
	assert child_of_child2_line == ''

	#bind simple_bus as a child of bind-test-child2
	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
	tree = u_boot_console.run_command('dm tree')
	treelines = [x.strip() for x in tree.splitlines() if x.strip()]

	child_of_child2_line = get_next_line(tree, 'bind-test-child2')
	assert child_of_child2_line
	child_of_child2_index = int(child_of_child2_line.split()[1])
	assert in_tree(tree, 'simple_bus', 'simple_bus', 'simple_bus', 2, True)
	assert child_of_child2_index == child2_index + 1

	#unbind the child and check it has been removed
	response = u_boot_console.run_command('unbind  {} {} simple_bus'.format(child2_uclass, child2_index))
	assert response == ''

	tree = u_boot_console.run_command('dm tree')
	assert in_tree(tree, 'bind-test-child2', 'simple_bus', 'simple_bus', 1, True)

	child_of_child2_line = get_next_line(tree, 'bind-test-child2')
	assert child_of_child2_line == ''

	#unbind the child again and check it doesn't change the tree
	tree_old = u_boot_console.run_command('dm tree')
	response = u_boot_console.run_command('unbind  {} {} simple_bus'.format(child2_uclass, child2_index))
	tree_new = u_boot_console.run_command('dm tree')

	assert response == ''
	assert tree_old == tree_new

	response = u_boot_console.run_command('unbind  /bind-test')
	assert response == ''
