diff mbox

[U-Boot,V2,7/7] test/py: test the ums command

Message ID 1449094708-14784-7-git-send-email-swarren@wwwdotorg.org
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Stephen Warren Dec. 2, 2015, 10:18 p.m. UTC
From: Stephen Warren <swarren@nvidia.com>

This test invokes the "ums" command in U-Boot, and validates that a USB
storage device is enumerated on the test host system, and can be read
from.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
 test/py/test_ums.py | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 test/py/test_ums.py

Comments

Simon Glass Dec. 19, 2015, 10:24 p.m. UTC | #1
HI Stephen,

On 2 December 2015 at 15:18, Stephen Warren <swarren@wwwdotorg.org> wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> This test invokes the "ums" command in U-Boot, and validates that a USB
> storage device is enumerated on the test host system, and can be read
> from.
>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> ---
>  test/py/test_ums.py | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 75 insertions(+)
>  create mode 100644 test/py/test_ums.py

Reviewed-by: Simon Glass <sjg@chromium.org>

Is the intent to replace or augment the existing ums tests?

Regards,
Simon
Stephen Warren Jan. 4, 2016, 9:19 p.m. UTC | #2
On 12/19/2015 03:24 PM, Simon Glass wrote:
> HI Stephen,
>
> On 2 December 2015 at 15:18, Stephen Warren <swarren@wwwdotorg.org> wrote:
>> From: Stephen Warren <swarren@nvidia.com>
>>
>> This test invokes the "ums" command in U-Boot, and validates that a USB
>> storage device is enumerated on the test host system, and can be read
>> from.
>>
>> Signed-off-by: Stephen Warren <swarren@nvidia.com>
>> ---
>>   test/py/test_ums.py | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 75 insertions(+)
>>   create mode 100644 test/py/test_ums.py
>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> Is the intent to replace or augment the existing ums tests?

Eventually replace, although I haven't yet implemented everything that 
the existing tests do; the existing test does actual disk IO, whereas 
this test mostly just covers USB device and disk enumeration.
diff mbox

Patch

diff --git a/test/py/test_ums.py b/test/py/test_ums.py
new file mode 100644
index 000000000000..55bcc7ccb703
--- /dev/null
+++ b/test/py/test_ums.py
@@ -0,0 +1,75 @@ 
+# Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved.
+#
+# SPDX-License-Identifier: GPL-2.0
+
+import os
+import pytest
+import time
+
+"""
+Note: This test relies on:
+
+a) boardenv_* to contain configuration values to define which USB ports are
+available for testing. Without this, this test will be automatically skipped.
+For example:
+
+env__usb_dev_ports = (
+    {"tgt_usb_ctlr": "0", "host_dev_link": "/dev/disk/by-path/pci-0000:00:14.0-usb-0:13:1.0-scsi-0:0:0:0"},
+)
+
+env__block_devs = (
+    {"type": "mmc", "id": "0"}, # eMMC; always present
+    {"type": "mmc", "id": "1"}, # SD card; present since I plugged one in
+)
+
+b) udev rules to set permissions on devices nodes, so that sudo is not
+required. For example:
+
+ACTION=="add", SUBSYSTEM=="block", SUBSYSTEMS=="usb", KERNELS=="3-13", MODE:="666"
+
+(You may wish to change the group ID instead of setting the permissions wide
+open. All that matters is that the user ID running the test can access the
+device.)
+"""
+
+def open_ums_device(host_dev_link):
+    try:
+        return open(host_dev_link, "rb")
+    except:
+        return None
+
+def wait_for_ums_device(host_dev_link):
+    for i in xrange(100):
+        fh = open_ums_device(host_dev_link)
+        if fh:
+            return fh
+        time.sleep(0.1)
+    raise Exception("UMS device did not appear")
+
+def wait_for_ums_device_gone(host_dev_link):
+    for i in xrange(100):
+        fh = open_ums_device(host_dev_link)
+        if not fh:
+            return
+        fh.close()
+        time.sleep(0.1)
+    raise Exception("UMS device did not disappear")
+
+@pytest.mark.buildconfigspec("cmd_usb_mass_storage")
+def test_ums(uboot_console, env__usb_dev_port, env__block_devs):
+    tgt_usb_ctlr = env__usb_dev_port["tgt_usb_ctlr"]
+    host_dev_link = env__usb_dev_port["host_dev_link"]
+
+    # We're interested in testing USB device mode on each port, not the cross-
+    # product of that with each device. So, just pick the first entry in the
+    # device list here. We'll test each block device somewhere else.
+    tgt_dev_type = env__block_devs[0]["type"]
+    tgt_dev_id = env__block_devs[0]["id"]
+
+    cmd = "ums %s %s %s" % (tgt_usb_ctlr, tgt_dev_type, tgt_dev_id)
+    uboot_console.run_command("ums 0 mmc 0", wait_for_prompt=False)
+    fh = wait_for_ums_device(host_dev_link)
+    fh.read(4096)
+    fh.close()
+    uboot_console.ctrlc()
+    wait_for_ums_device_gone(host_dev_link)