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 v2 3/3] tests: py: dfu: Provide functionality to set test and dummy files alt settings
Date: Wed, 20 Apr 2016 11:40:17 +0200	[thread overview]
Message-ID: <20160420114017.3d1df243@amdc2363> (raw)
In-Reply-To: <57165BF0.8040607@wwwdotorg.org>

Hi Stephen,

> On 04/19/2016 09:51 AM, Lukasz Majewski wrote:
> > 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.
> 
> > @@ -122,6 +139,8 @@ def test_dfu(u_boot_console, env__usb_dev_port,
> > env__dfu_config): Returns:
> >               Nothing.
> >           """
> > +        global alt_setting_test_file
> > +        global alt_setting_dummy_file
> 
> There should be a blank line after the """ line. Although per the 
> comments below, you can simply drop this part of the diff completely.
> 
> > @@ -132,6 +151,9 @@ 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')
> >
> > +        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')
> 
> This always over-writes alt_setting_test_file, and changes the type
> from integer (as specified by the current global assignment added in
> patch 1) to string. You may as well simply remove the "global" lines
> added in this patch, and the global assignment, since this patch
> always assigns a value to those variables.
> 
> Since the variable always contains a string now, you can remove the 
> str() call from run_dfu_util()'s assignment to cmd[].
> 

Frankly I'm a bit confused now. 
I'm not the python expert, but v2 design seems logical to me:


test_dfu.py Python module (outermost scope):

alt_setting_test_file = 0
alt_setting_dummy_file = 1

def test_dfu:
	
	def start_dfu():
		global alt_setting_test_file
		global alt_setting_dummy_file

		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')

	def dfu_write_read_check():
		...
		dfu_write(alt_setting_test_file, test_f.abs_fn)
		...
		dfu_write(alt_setting_dummy_file, dummy_f.abs_fn)
		...
		dfu_write(alt_setting_test_file, dummy_f.abs_fn)


So I'm setting up alt_setting_{test|dummy}_file global variables at
start_dfu() function. Afterwards, I reuse them at
dfu_write_read_check().

Such approach is similar to one used for "first_usb_dev_port" global
variable in the same file.

If I remove "global" from alt_setting_{test|dummy}_file declaration
then I will set them only to be valid at start_dfu() function scope.
Hence at dfu_write_read_check() I will use those variables set to 0 and
1 respectively.



One possible solution that I've found is to use "function attributes":

def test_dfu:
	test_dfu.alt_setting_test_file
	test_dfu.alt_setting_dummy_file

	def start_dfu():
		test_dfu.alt_setting_test_file=env__dfu_config.get('alt_id_test_file','0')
		test_dfu.alt_setting_dummy_file=env__dfu_config.get('alt_id_dummy_file','1')

	def dfu_write_read_check():
		...
		dfu_write(test_dfu.alt_setting_test_file, test_f.abs_fn)
		...	

Stephen, is the above solution acceptable for you?

-- 
Best regards,

Lukasz Majewski

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

  reply	other threads:[~2016-04-20  9:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-08 15:44 [U-Boot] [PATCH 1/3] tests: py: dfu: Add global variables to store dfu alt numbers for test and dummy files Lukasz Majewski
2016-04-08 15:44 ` [U-Boot] [PATCH 2/3] tests: py: dfu: Add functionality to set different u-boot's dfu env variable Lukasz Majewski
2016-04-08 16:28   ` Stephen Warren
2016-04-08 20:10     ` Lukasz Majewski
2016-04-08 16:29   ` Stephen Warren
2016-04-08 20:11     ` Lukasz Majewski
2016-04-08 15:44 ` [U-Boot] [PATCH 3/3] tests: py: dfu: Provide functionality to set test and dummy files alt settings Lukasz Majewski
2016-04-08 16:34   ` Stephen Warren
2016-04-11  8:42     ` Lukasz Majewski
2016-04-11 17:05       ` Stephen Warren
2016-04-12  8:33         ` Lukasz Majewski
2016-04-19 15:51 ` [U-Boot] [PATCH v2 1/3] tests: py: dfu: Add global variables to store dfu alt numbers for test and dummy files Lukasz Majewski
2016-04-19 15:51   ` [U-Boot] [PATCH v2 2/3] tests: py: dfu: Add functionality to set different u-boot's dfu env variable Lukasz Majewski
2016-04-19 15:51   ` [U-Boot] [PATCH v2 3/3] tests: py: dfu: Provide functionality to set test and dummy files alt settings Lukasz Majewski
2016-04-19 16:25     ` Stephen Warren
2016-04-20  9:40       ` Lukasz Majewski [this message]
2016-04-20 15:55         ` Stephen Warren
2016-04-19 16:22   ` [U-Boot] [PATCH v2 1/3] tests: py: dfu: Add global variables to store dfu alt numbers for test and dummy files Stephen Warren
2016-04-19 16:30     ` Lukasz Majewski
2016-04-21 15:40 ` [U-Boot] [PATCH v3 1/3] tests: py: dfu: Add " Lukasz Majewski
2016-04-21 15:40   ` [U-Boot] [PATCH v3 2/3] tests: py: dfu: Add functionality to set different u-boot's dfu env variable Lukasz Majewski
2016-04-21 15:40   ` [U-Boot] [PATCH v3 3/3] tests: py: dfu: Provide functionality to set test and dummy files alt settings Lukasz Majewski
2016-04-21 16:10   ` [U-Boot] [PATCH v3 1/3] tests: py: dfu: Add variables to store dfu alt numbers for test and dummy files Stephen Warren

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=20160420114017.3d1df243@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