[U-Boot] [PATCH V2 7/7] test/py: test the ums command
Stephen Warren
swarren at wwwdotorg.org
Wed Dec 2 23:18:28 CET 2015
From: Stephen Warren <swarren at 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 at nvidia.com>
---
test/py/test_ums.py | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
create mode 100644 test/py/test_ums.py
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")
+
+ at 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)
--
2.6.3
More information about the U-Boot
mailing list