From c6eb899c4d0f8311f8a9d6c991344a27b8f9d4db Mon Sep 17 00:00:00 2001 From: Lukasz Majewski Date: Wed, 20 Apr 2016 10:36:32 +0200 Subject: tests: py: dfu: Add variables to store dfu alt numbers for test and dummy files This patch replaces hardcoded (i.e. 0 and 1) values passed to dfu_{read|write} with variables. Signed-off-by: Lukasz Majewski Acked-by: Stephen Warren --- Changes for v3: - Replace per module global variables with ones defined inside a function Changes for v2: - None --- test/py/tests/test_dfu.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/py/tests/test_dfu.py b/test/py/tests/test_dfu.py index 093e8d0..2e6cd7b 100644 --- a/test/py/tests/test_dfu.py +++ b/test/py/tests/test_dfu.py @@ -99,6 +99,10 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config): Nothing. """ + # Default alt settings for test and dummy files + alt_setting_test_file = 0 + alt_setting_dummy_file = 1 + def start_dfu(): """Start U-Boot's dfu shell command. @@ -229,15 +233,15 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config): u_boot_console.log.action('Writing test data to DFU primary ' + 'altsetting') - dfu_write(0, test_f.abs_fn) + dfu_write(alt_setting_test_file, test_f.abs_fn) u_boot_console.log.action('Writing dummy data to DFU secondary ' + 'altsetting to clear DFU buffers') - dfu_write(1, dummy_f.abs_fn) + dfu_write(alt_setting_dummy_file, dummy_f.abs_fn) u_boot_console.log.action('Reading DFU primary altsetting for ' + 'comparison') - dfu_read(0, readback_fn) + dfu_read(alt_setting_test_file, readback_fn) u_boot_console.log.action('Comparing written and read data') written_hash = test_f.content_hash @@ -266,7 +270,7 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config): u_boot_console.log.action( 'Overwriting DFU primary altsetting with dummy data') - dfu_write(0, dummy_f.abs_fn) + dfu_write(alt_setting_test_file, dummy_f.abs_fn) for size in sizes: with u_boot_console.log.section('Data size %d' % size): -- cgit v1.1 From 8eb37524468efa6f90dd00862aeaabe934557a5a Mon Sep 17 00:00:00 2001 From: Lukasz Majewski Date: Mon, 18 Apr 2016 17:01:15 +0200 Subject: tests: py: dfu: Add functionality to set different u-boot's dfu env variable By default (on almost all systems) the dfu env variable, which defines available alt settings, is named as "dfu_alt_info". However on some platforms (i.e. Odroid XU3), the 'dfu_alt_info' is concatenated from other variables - namely 'dfu_alt_boot' and 'dfu_alt_system' at run time (when one types 'dfu 0 mmc 0' for first time). 'dfu_alt_boot' describes alt settings which depend on boot medium - for example boot loader's LBA sectors which are different on eMMC and SD card because of e.g. MBR/GPT. 'dfu_alt_system' describes board agnostic alt settings - like rootfs, kernel. On such system we can only append/modify this env variable. Because of the above, we must have way to modify other than "dfu_ale_info" variable to perform tests. Signed-off-by: Lukasz Majewski Acked-by: Stephen Warren --- Changes for v3: - None Changes for v2: - Rewrite of "alt_info_env_name" variable description - Use of get() method on python's dictionary to easily obtain default value --- test/py/tests/test_dfu.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/py/tests/test_dfu.py b/test/py/tests/test_dfu.py index 2e6cd7b..0442af8 100644 --- a/test/py/tests/test_dfu.py +++ b/test/py/tests/test_dfu.py @@ -44,6 +44,14 @@ env__dfu_configs = ( # configurations, but don't want to test every single transfer size # on each, to avoid bloating the overall time taken by testing. "test_sizes": (63, 64, 65), + # This value is optional. + # The name of the environment variable that the the dfu command reads + # alt info from. If unspecified, this defaults to dfu_alt_info, which is + # valid for most systems. Some systems use a different variable name. + # One example is the Odroid XU3, which automatically generates + # $dfu_alt_info, each time the dfu command is run, by concatenating + # $dfu_alt_boot and $dfu_alt_system. + "alt_info_env_name": "dfu_alt_system", }, ) @@ -124,7 +132,11 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config): u_boot_console.log.action( 'Starting long-running U-Boot dfu shell command') - cmd = 'setenv dfu_alt_info "%s"' % env__dfu_config['alt_info'] + dfu_alt_info_env = env__dfu_config.get('alt_info_env_name', \ + 'dfu_alt_info') + + cmd = 'setenv "%s" "%s"' % (dfu_alt_info_env, + env__dfu_config['alt_info']) u_boot_console.run_command(cmd) cmd = 'dfu 0 ' + env__dfu_config['cmd_params'] -- cgit v1.1 From f3a87f5b79a8f1957753131b09b539027913c731 Mon Sep 17 00:00:00 2001 From: Lukasz Majewski Date: Wed, 20 Apr 2016 10:57:08 +0200 Subject: tests: py: dfu: Provide functionality to set test and dummy files alt settings After concatenation of "dfu_alt_info" variable from "dfu_alt_boot" and "dfu_alt_system" it may happen that test and dummy files alt settings are different than default 0 and 1. This patch provides the ability to set different values for them. Signed-off-by: Lukasz Majewski Acked-by: Stephen Warren --- Changes for v3: - replace variables declarations with ones read from configuration file - remove not necessary str() conversion at DFU host command generation Changes for v2: - generate "alt_info" automatically - use file names as alt settings instead of numerical values - extend in-code documentation --- test/py/tests/test_dfu.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/py/tests/test_dfu.py b/test/py/tests/test_dfu.py index 0442af8..8649d87 100644 --- a/test/py/tests/test_dfu.py +++ b/test/py/tests/test_dfu.py @@ -30,6 +30,13 @@ env__usb_dev_ports = ( }, ) +# Optional entries (required only when "alt_id_test_file" and +# "alt_id_dummy_file" are specified). +test_file_name = "/dfu_test.bin" +dummy_file_name = "/dfu_dummy.bin" +# Above files are used to generate proper "alt_info" entry +"alt_info": "/%s ext4 0 2;/%s ext4 0 2" % (test_file_name, dummy_file_name), + env__dfu_configs = ( # eMMC, partition 1 { @@ -52,6 +59,16 @@ env__dfu_configs = ( # $dfu_alt_info, each time the dfu command is run, by concatenating # $dfu_alt_boot and $dfu_alt_system. "alt_info_env_name": "dfu_alt_system", + # This value is optional. + # For boards which require the "test file" alt setting number other than + # default (0) it is possible to specify exact file name to be used as + # this parameter. + "alt_id_test_file": test_file_name, + # This value is optional. + # For boards which require the "dummy file" alt setting number other + # than default (1) it is possible to specify exact file name to be used + # as this parameter. + "alt_id_dummy_file": dummy_file_name, }, ) @@ -107,10 +124,6 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config): Nothing. """ - # Default alt settings for test and dummy files - alt_setting_test_file = 0 - alt_setting_dummy_file = 1 - def start_dfu(): """Start U-Boot's dfu shell command. @@ -188,7 +201,7 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config): Nothing. """ - cmd = ['dfu-util', '-a', str(alt_setting), up_dn_load_arg, fn] + cmd = ['dfu-util', '-a', alt_setting, up_dn_load_arg, fn] if 'host_usb_port_path' in env__usb_dev_port: cmd += ['-p', env__usb_dev_port['host_usb_port_path']] u_boot_utils.run_and_log(u_boot_console, cmd) @@ -276,6 +289,9 @@ def test_dfu(u_boot_console, env__usb_dev_port, env__dfu_config): dummy_f = u_boot_utils.PersistentRandomFile(u_boot_console, 'dfu_dummy.bin', 1024) + alt_setting_test_file = env__dfu_config.get('alt_id_test_file', '0') + alt_setting_dummy_file = env__dfu_config.get('alt_id_dummy_file', '1') + ignore_cleanup_errors = True try: start_dfu() -- cgit v1.1