public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: opensource.kab@gmail.com
To: u-boot@lists.denx.de
Cc: alex.kiernan@gmail.com, Adarsh Babu Kalepalli <opensource.kab@gmail.com>
Subject: [PATCH] test/py:Update python tests for ‘gpio’ cmd
Date: Mon, 31 May 2021 16:23:51 +0530	[thread overview]
Message-ID: <20210531105351.15502-1-opensource.kab@gmail.com> (raw)

From: Adarsh Babu Kalepalli <opensource.kab@gmail.com>

Generic Python Test cases are developed to verfiy 'gpio' command.

Signed-off-by: Adarsh Babu Kalepalli <opensource.kab@gmail.com>
---

 test/py/tests/test_gpio.py | 175 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 174 insertions(+), 1 deletion(-)

diff --git a/test/py/tests/test_gpio.py b/test/py/tests/test_gpio.py
index 8c64f686b0..109649e2c7 100644
--- a/test/py/tests/test_gpio.py
+++ b/test/py/tests/test_gpio.py
@@ -1,6 +1,16 @@
-# SPDX-License-Identifier: GPL-2.0+
+# SPDX-License-Identifier:  GPL-2.0+
+#
+# Copyright (c) 2021 Adarsh Babu Kalepalli <opensource.kab@gmail.com>
+# Copyright (c) 2020 Alex Kiernan <alex.kiernan@gmail.com>
 
 import pytest
+import time
+import u_boot_utils
+
+"""
+	test_gpio_input is intended to test the fix 4dbc107f4683.
+	4dbc107f4683:"cmd: gpio: Correct do_gpio() return value"
+"""
 
 @pytest.mark.boardspec('sandbox')
 @pytest.mark.buildconfigspec('cmd_gpio')
@@ -35,3 +45,166 @@ def test_gpio_exit_statuses(u_boot_console):
     assert(expected_response in response)
     response = u_boot_console.run_command('gpio input 200; echo rc:$?')
     assert(expected_response in response)
+
+
+"""
+Generic Tests for 'gpio' command on sandbox and real hardware.
+The below sequence of tests rely on env__gpio_dev_config for configuration values of gpio pins.
+
+ Configuration data for gpio command.
+ The  set,clear,toggle ,input and status options of 'gpio' command are verified.
+ For sake of verification,A  LED/buzzer could be connected to GPIO pins configured as O/P.
+ Logic level '1'/'0' can be applied onto GPIO pins configured as I/P
+
+
+env__gpio_dev_config = {
+        #the number of 'gpio_str_x' strings should equal to
+        #'gpio_str_count' value
+        'gpio_str_count':4 ,
+        'gpio_str_1': '0',
+        'gpio_str_2': '31',
+        'gpio_str_3': '63',
+        'gpio_str_4': '127',
+        'gpio_op_pin': '64',
+        'gpio_ip_pin_set':'65',
+        'gpio_ip_pin_clear':'66',
+        'gpio_clear_value': 'value is 0',
+        'gpio_set_value': 'value is 1',
+}
+"""
+
+
+@pytest.mark.buildconfigspec('cmd_gpio')
+def test_gpio_status_all_generic(u_boot_console):
+    """Test the 'gpio status' command.
+
+	Displays all gpio pins available on the Board.
+	To verify if the status of pins is displayed or not,
+        the user can configure (gpio_str_count) and verify existence of certain
+	pins.The details of these can be configured in 'gpio_str_n'.
+        of boardenv_* (example above).User can configure any
+        number of such pins and mention that count in 'gpio_str_count'.
+    """
+
+    f = u_boot_console.config.env.get('env__gpio_dev_config',False)
+    if not f:
+        pytest.skip("gpio not configured")
+
+    gpio_str_count = f['gpio_str_count']
+
+    #Display all the GPIO ports
+    cmd = 'gpio status -a'
+    response = u_boot_console.run_command(cmd)
+
+    for str_value in range(1,gpio_str_count + 1):
+        assert f["gpio_str_%d" %(str_value)] in response
+
+
+@pytest.mark.buildconfigspec('cmd_gpio')
+def test_gpio_set_generic(u_boot_console):
+    """Test the 'gpio set' command.
+
+	A specific gpio pin configured by user as output
+        (mentioned in gpio_op_pin) is verified for
+	'set' option
+
+    """
+
+    f = u_boot_console.config.env.get('env__gpio_dev_config',False)
+    if not f:
+        pytest.skip("gpio not configured")
+
+    gpio_pin_adr = f['gpio_op_pin'];
+    gpio_set_value = f['gpio_set_value'];
+
+
+    cmd = 'gpio set ' + gpio_pin_adr
+    response = u_boot_console.run_command(cmd)
+    good_response = gpio_set_value
+    assert good_response in response
+
+
+
+@pytest.mark.buildconfigspec('cmd_gpio')
+def test_gpio_clear_generic(u_boot_console):
+    """Test the 'gpio clear' command.
+
+	A specific gpio pin configured by user as output
+        (mentioned in gpio_op_pin) is verified for
+	'clear' option
+    """
+
+    f = u_boot_console.config.env.get('env__gpio_dev_config',False)
+    if not f:
+        pytest.skip("gpio not configured")
+
+    gpio_pin_adr = f['gpio_op_pin'];
+    gpio_clear_value = f['gpio_clear_value'];
+
+
+    cmd = 'gpio clear ' + gpio_pin_adr
+    response = u_boot_console.run_command(cmd)
+    good_response = gpio_clear_value
+    assert good_response in response
+
+
+@pytest.mark.buildconfigspec('cmd_gpio')
+def test_gpio_toggle_generic(u_boot_console):
+    """Test the 'gpio toggle' command.
+
+	A specific gpio pin configured by user as output
+        (mentioned in gpio_op_pin) is verified for
+	'toggle' option
+    """
+
+
+    f = u_boot_console.config.env.get('env__gpio_dev_config',False)
+    if not f:
+        pytest.skip("gpio not configured")
+
+    gpio_pin_adr = f['gpio_op_pin'];
+    gpio_set_value = f['gpio_set_value'];
+    gpio_clear_value = f['gpio_clear_value'];
+
+    cmd = 'gpio set ' + gpio_pin_adr
+    response = u_boot_console.run_command(cmd)
+    good_response = gpio_set_value
+    assert good_response in response
+
+    cmd = 'gpio toggle ' + gpio_pin_adr
+    response = u_boot_console.run_command(cmd)
+    good_response = gpio_clear_value
+    assert good_response in response
+
+
+@pytest.mark.buildconfigspec('cmd_gpio')
+def test_gpio_input_generic(u_boot_console):
+    """Test the 'gpio input' command.
+
+	Specific gpio pins configured by user as input
+        (mentioned in gpio_ip_pin_set and gpio_ip_pin_clear)
+	is verified for logic '1' and logic '0' states
+    """
+
+    f = u_boot_console.config.env.get('env__gpio_dev_config',False)
+    if not f:
+        pytest.skip("gpio not configured")
+
+    gpio_pin_adr = f['gpio_ip_pin_clear'];
+    gpio_clear_value = f['gpio_clear_value'];
+
+
+    cmd = 'gpio input ' + gpio_pin_adr
+    response = u_boot_console.run_command(cmd)
+    good_response = gpio_clear_value
+    assert good_response in response
+
+
+    gpio_pin_adr = f['gpio_ip_pin_set'];
+    gpio_set_value = f['gpio_set_value'];
+
+
+    cmd = 'gpio input ' + gpio_pin_adr
+    response = u_boot_console.run_command(cmd)
+    good_response = gpio_set_value
+    assert good_response in response
-- 
2.17.1


             reply	other threads:[~2021-05-31 10:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-31 10:53 opensource.kab [this message]
2022-04-10 15:20 ` [PATCH] test/py:Update python tests for ‘gpio’ cmd Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210531105351.15502-1-opensource.kab@gmail.com \
    --to=opensource.kab@gmail.com \
    --cc=alex.kiernan@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox