public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Lukasz Majewski <l.majewski@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V4 7/8] test/py: test the ums command
Date: Thu, 21 Jan 2016 12:06:34 +0100	[thread overview]
Message-ID: <20160121120634.3490df85@amdc2363> (raw)
In-Reply-To: <1452881731-30030-7-git-send-email-swarren@wwwdotorg.org>

Hi Stephen,

> 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>
> Acked-by: Simon Glass <sjg@chromium.org>
> ---
> v4:
> - No changes.
> 
> v3:
> - Move test scripts into a sub-directory.
>   Suggested by Michal Simek.
> - s/uboot/u[-_]boot/g. Suggested by Simon Glass.
> - s/"/'/g. Suggested by Simon Glass.
> - Add more documentation. Suggested by Simon Glass.
> - Rename boardenv USB device node variable to avoid naming conflicts
> if we add support for other types of USB device later (e.g. CDC ACM,
> CDC Ethernet, DFU).
> ---
>  test/py/tests/test_ums.py | 94
> +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94
> insertions(+) create mode 100644 test/py/tests/test_ums.py
> 
> diff --git a/test/py/tests/test_ums.py b/test/py/tests/test_ums.py
> new file mode 100644
> index 000000000000..a137221c7a5b
> --- /dev/null
> +++ b/test/py/tests/test_ums.py
> @@ -0,0 +1,94 @@
> +# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
> +#
> +# SPDX-License-Identifier: GPL-2.0
> +
> +# Test U-Boot's "ums" command. At present, this test only ensures
> that a UMS +# device can be enumerated by the host/test machine. In
> the future, this test +# should be enhanced to validate disk IO.
> +
> +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_ums_dev_node':
> '/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_ums_dev_node):
> +    '''Attempt to open a device node, returning either the opened
> file handle,
> +    or None on any error.'''
> +
> +    try:
> +        return open(host_ums_dev_node, 'rb')
> +    except:
> +        return None
> +
> +def wait_for_ums_device(host_ums_dev_node):
> +    '''Continually attempt to open the device node exported by the
> "ums"
> +    command, and either return the opened file handle, or raise an
> exception
> +    after a timeout.'''
> +
> +    for i in xrange(100):
> +        fh = open_ums_device(host_ums_dev_node)
> +        if fh:
> +            return fh
> +        time.sleep(0.1)
> +    raise Exception('UMS device did not appear')
> +
> +def wait_for_ums_device_gone(host_ums_dev_node):
> +    '''Continually attempt to open the device node exported by the
> "ums"
> +    command, and either return once the device has disappeared, or
> raise an
> +    exception if it does not before a timeout occurs.'''
> +
> +    for i in xrange(100):
> +        fh = open_ums_device(host_ums_dev_node)
> +        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(u_boot_console, env__usb_dev_port, env__block_devs):
> +    '''Test the "ums" command; the host system must be able to
> enumerate a UMS
> +    device when "ums" is running, and this device must disappear
> when "ums" is
> +    aborted.'''
> +
> +    tgt_usb_ctlr = env__usb_dev_port['tgt_usb_ctlr']
> +    host_ums_dev_node = env__usb_dev_port['host_ums_dev_node']
> +
> +    # 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)
> +    u_boot_console.run_command('ums 0 mmc 0', wait_for_prompt=False)
> +    fh = wait_for_ums_device(host_ums_dev_node)
> +    fh.read(4096)
> +    fh.close()
> +    u_boot_console.ctrlc()
> +    wait_for_ums_device_gone(host_ums_dev_node)

Reviewed-by: Stephen Warren <swarren@wwwdotorg.org>

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

  parent reply	other threads:[~2016-01-21 11:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-15 18:15 [U-Boot] [PATCH V4 1/8] test/py: Implement pytest infrastructure Stephen Warren
2016-01-15 18:15 ` [U-Boot] [PATCH V4 2/8] test/py: test that sandbox exits when asked Stephen Warren
2016-01-19  3:28   ` Simon Glass
2016-01-15 18:15 ` [U-Boot] [PATCH V4 3/8] test/py: add test of setenv/printenv/echo Stephen Warren
2016-01-19  3:28   ` Simon Glass
2016-01-15 18:15 ` [U-Boot] [PATCH V4 4/8] test/py: test the md/mw commands Stephen Warren
2016-01-19  3:28   ` Simon Glass
2016-01-15 18:15 ` [U-Boot] [PATCH V4 5/8] test/py: add test of basic shell functionality Stephen Warren
2016-01-19  3:28   ` Simon Glass
2016-01-15 18:15 ` [U-Boot] [PATCH V4 6/8] test/py: test the shell if command Stephen Warren
2016-01-19  3:28   ` Simon Glass
2016-01-15 18:15 ` [U-Boot] [PATCH V4 7/8] test/py: test the ums command Stephen Warren
2016-01-19  3:28   ` Simon Glass
2016-01-21 11:06   ` Lukasz Majewski [this message]
2016-01-15 18:15 ` [U-Boot] [PATCH V4 8/8] test/py: add a test for the sleep command Stephen Warren
2016-01-19  3:28   ` Simon Glass
2016-01-19  3:28 ` [U-Boot] [PATCH V4 1/8] test/py: Implement pytest infrastructure Simon Glass

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=20160121120634.3490df85@amdc2363 \
    --to=l.majewski@samsung.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