From patchwork Sat Apr 30 09:26:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1624641 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=YqNgYkpf; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kr3s1720Sz9sBy for ; Sat, 30 Apr 2022 19:26:43 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 91D9583989; Sat, 30 Apr 2022 11:26:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="YqNgYkpf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 82A418399B; Sat, 30 Apr 2022 11:26:34 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9D56B811D8 for ; Sat, 30 Apr 2022 11:26:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from LT2ubnt.fritz.box (ip-062-143-094-109.um16.pools.vodafone-ip.de [62.143.94.109]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 773133F152; Sat, 30 Apr 2022 09:26:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1651310787; bh=/LGzBU0jIttu1YPqCEy6UX73ToYvFayP9S0fv9P7KGU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=YqNgYkpf5wlda9Nwk42P9fSt3oJlqIBpfVhcnqbN5AXTjsS8CbHW7Xxvejn2Dq0Lk z4R3xvVdxNvo2RlxBZmm31JvJ3aV9t/BOfJFiWaAMh4ks80vDWQkvjdK/F8q2thvj9 SbL5vwTSeUQqHtt6CA6dXITt7tCO72i6KV3uAMv3WbxGbB0r2zYOEt5k2djL3EOD+i Y9DJrfiGBi7taw2tuNsxqcky5mNQwBhNAMh7Koxnp/fg+todp1tJzA+aYG1URTUUvr ZoAf1RpCSCRm1cU5QoYnMBI3Q0LV+qshI81D2KNbfYJuPIO0ogrOXEoe4j77nxbUev ceN8nQ4m7ri+w== From: Heinrich Schuchardt To: Simon Glass Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH] test: fix some pylint errors in test_bind.py Date: Sat, 30 Apr 2022 11:26:23 +0200 Message-Id: <20220430092623.50223-1-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean * 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 Signed-off-by: Heinrich Schuchardt --- test/py/tests/test_bind.py | 345 +++++++++++++++++++------------------ 1 file changed, 175 insertions(+), 170 deletions(-) diff --git a/test/py/tests/test_bind.py b/test/py/tests/test_bind.py index 8ad277da19..d7e6626d45 100644 --- a/test/py/tests/test_bind.py +++ b/test/py/tests/test_bind.py @@ -1,186 +1,191 @@ # SPDX-License-Identifier: GPL-2.0 # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. -import os.path -import pytest +""" Test for bind command """ + import re +import pytest 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 + 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 == '' + 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 + 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 == '' + #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 == ''