diff mbox series

[RESEND,v5,4/4] test: env: add test for env info sub-command

Message ID 20200619120337.17042-5-patrick.delaunay@st.com
State Accepted
Commit acbf93b52695431b683d2665120707a3f52d6b4b
Delegated to: Tom Rini
Headers show
Series cmd: env: add option for quiet output on env info | expand

Commit Message

Patrick DELAUNAY June 19, 2020, 12:03 p.m. UTC
Add a pytest for testing the env info sub-command:

test_env_info: test command with several option that
can be executed on real hardware device without assumption

test_env_info_sandbox: test the result on sandbox
with a known ENV configuration: ready & default & persistent

The quiet option '-q' is used for support in shell test;
for example:
  if env info -p -d -q; then env save; fi

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
---

Changes in v5:
- allow to execute cmd_nvedit_info on real board
- rename test_env_info_quiet to test_env_info_sandbox

Changes in v4:
- rebase on master branch
- move 5/7 stm32mp1: configs: activate CMD_ERASEENV
  in a new serie 183380
- move 2/7 and 4/7 in a new serie 183387

Changes in v3:
- update commit message (sub-commandi)
- rename test_env_info_test to test_env_info_quiet

Changes in v2:
- add pytest test_env_info and test_env_info_test (new)

 test/py/tests/test_env.py | 63 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

Comments

Stephen Warren June 22, 2020, 6:50 p.m. UTC | #1
On 6/19/20 6:03 AM, Patrick Delaunay wrote:
> Add a pytest for testing the env info sub-command:
> 
> test_env_info: test command with several option that
> can be executed on real hardware device without assumption
> 
> test_env_info_sandbox: test the result on sandbox
> with a known ENV configuration: ready & default & persistent
> 
> The quiet option '-q' is used for support in shell test;
> for example:
>   if env info -p -d -q; then env save; fi

Acked-by: Stephen Warren <swarren@nvidia.com>

> +def test_env_info(state_test_env):
...
> +    for l in response.split('\n'):
> +        if 'env_valid = ' in l:
> +            assert '= invalid' in l or '= valid' in l or '= redundant' in l
> +            nb_line += 1
> +        elif 'env_ready =' in l or 'env_use_default =' in l:
> +            assert '= true' in l or '= false' in l
> +            nb_line += 1
> +        else:
> +            assert true

Those last two lines don't seem terribly useful:-)
Patrick DELAUNAY June 23, 2020, 1:25 p.m. UTC | #2
Hi Stephen,

> From: Stephen Warren <swarren@wwwdotorg.org>
> Sent: lundi 22 juin 2020 20:51
> 
> On 6/19/20 6:03 AM, Patrick Delaunay wrote:
> > Add a pytest for testing the env info sub-command:
> >
> > test_env_info: test command with several option that can be executed
> > on real hardware device without assumption
> >
> > test_env_info_sandbox: test the result on sandbox with a known ENV
> > configuration: ready & default & persistent
> >
> > The quiet option '-q' is used for support in shell test; for example:
> >   if env info -p -d -q; then env save; fi
> 
> Acked-by: Stephen Warren <swarren@nvidia.com>

Thanks

 
> > +def test_env_info(state_test_env):
> ...
> > +    for l in response.split('\n'):
> > +        if 'env_valid = ' in l:
> > +            assert '= invalid' in l or '= valid' in l or '= redundant' in l
> > +            nb_line += 1
> > +        elif 'env_ready =' in l or 'env_use_default =' in l:
> > +            assert '= true' in l or '= false' in l
> > +            nb_line += 1
> > +        else:
> > +            assert true
> 
> Those last two lines don't seem terribly useful:-)

Not really,
beacuse I add the nb_line check,
this first check can be removed.

Do expect a V6 just for that?

Patrick
Stephen Warren June 23, 2020, 8:24 p.m. UTC | #3
On 6/23/20 7:25 AM, Patrick DELAUNAY wrote:
> Hi Stephen,
> 
>> From: Stephen Warren <swarren@wwwdotorg.org>
>> Sent: lundi 22 juin 2020 20:51
>>
>> On 6/19/20 6:03 AM, Patrick Delaunay wrote:
>>> Add a pytest for testing the env info sub-command:
>>>
>>> test_env_info: test command with several option that can be executed
>>> on real hardware device without assumption
>>>
>>> test_env_info_sandbox: test the result on sandbox with a known ENV
>>> configuration: ready & default & persistent
>>>
>>> The quiet option '-q' is used for support in shell test; for example:
>>>   if env info -p -d -q; then env save; fi
>>
>> Acked-by: Stephen Warren <swarren@nvidia.com>
> 
> Thanks
> 
>  
>>> +def test_env_info(state_test_env):
>> ...
>>> +    for l in response.split('\n'):
>>> +        if 'env_valid = ' in l:
>>> +            assert '= invalid' in l or '= valid' in l or '= redundant' in l
>>> +            nb_line += 1
>>> +        elif 'env_ready =' in l or 'env_use_default =' in l:
>>> +            assert '= true' in l or '= false' in l
>>> +            nb_line += 1
>>> +        else:
>>> +            assert true
>>
>> Those last two lines don't seem terribly useful:-)
> 
> Not really,
> beacuse I add the nb_line check,
> this first check can be removed.
> 
> Do expect a V6 just for that?

Probably not.
Patrick DELAUNAY June 24, 2020, 7:30 a.m. UTC | #4
Hi Stephen,

> From: Stephen Warren <swarren@wwwdotorg.org>
> Sent: mardi 23 juin 2020 22:25
> 
> On 6/23/20 7:25 AM, Patrick DELAUNAY wrote:
> > Hi Stephen,
> >
> >> From: Stephen Warren <swarren@wwwdotorg.org>
> >> Sent: lundi 22 juin 2020 20:51
> >>
> >> On 6/19/20 6:03 AM, Patrick Delaunay wrote:
> >>> Add a pytest for testing the env info sub-command:
> >>>
...
> >
> >>> +def test_env_info(state_test_env):
> >> ...
> >>> +    for l in response.split('\n'):
> >>> +        if 'env_valid = ' in l:
> >>> +            assert '= invalid' in l or '= valid' in l or '= redundant' in l
> >>> +            nb_line += 1
> >>> +        elif 'env_ready =' in l or 'env_use_default =' in l:
> >>> +            assert '= true' in l or '= false' in l
> >>> +            nb_line += 1
> >>> +        else:
> >>> +            assert true
> >>
> >> Those last two lines don't seem terribly useful:-)
> >
> > Not really,
> > beacuse I add the nb_line check,
> > this first check can be removed.
> >
> > Do expect a V6 just for that?
> 
> Probably not.

OK I will keep this remark if I need to update the serie
(or the next planned updates of this test)

Patrick
Tom Rini July 27, 2020, 1:33 p.m. UTC | #5
On Fri, Jun 19, 2020 at 02:03:37PM +0200, Patrick Delaunay wrote:

> Add a pytest for testing the env info sub-command:
> 
> test_env_info: test command with several option that
> can be executed on real hardware device without assumption
> 
> test_env_info_sandbox: test the result on sandbox
> with a known ENV configuration: ready & default & persistent
> 
> The quiet option '-q' is used for support in shell test;
> for example:
>   if env info -p -d -q; then env save; fi
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> Acked-by: Stephen Warren <swarren@nvidia.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py
index 6ff38f1020..a64aaa9bc5 100644
--- a/test/py/tests/test_env.py
+++ b/test/py/tests/test_env.py
@@ -336,3 +336,66 @@  def test_env_import_whitelist_delete(state_test_env):
     unset_var(state_test_env, 'foo2')
     unset_var(state_test_env, 'foo3')
     unset_var(state_test_env, 'foo4')
+
+@pytest.mark.buildconfigspec('cmd_nvedit_info')
+def test_env_info(state_test_env):
+
+    """Test 'env info' command with all possible options.
+    """
+    c = state_test_env.u_boot_console
+
+    response = c.run_command('env info')
+    nb_line = 0
+    for l in response.split('\n'):
+        if 'env_valid = ' in l:
+            assert '= invalid' in l or '= valid' in l or '= redundant' in l
+            nb_line += 1
+        elif 'env_ready =' in l or 'env_use_default =' in l:
+            assert '= true' in l or '= false' in l
+            nb_line += 1
+        else:
+            assert true
+    assert nb_line == 3
+
+    response = c.run_command('env info -p -d')
+    assert 'Default environment is used' in response or "Environment was loaded from persistent storage" in response
+    assert 'Environment can be persisted' in response or "Environment cannot be persisted" in response
+
+    response = c.run_command('env info -p -d -q')
+    assert response == ""
+
+    response = c.run_command('env info -p -q')
+    assert response == ""
+
+    response = c.run_command('env info -d -q')
+    assert response == ""
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_nvedit_info')
+@pytest.mark.buildconfigspec('cmd_echo')
+def test_env_info_sandbox(state_test_env):
+
+    """Test 'env info' command result with several options on sandbox
+       with a known ENV configuration: ready & default & persistent
+    """
+    c = state_test_env.u_boot_console
+
+    response = c.run_command('env info')
+    assert 'env_ready = true' in response
+    assert 'env_use_default = true' in response
+
+    response = c.run_command('env info -p -d')
+    assert 'Default environment is used' in response
+    assert 'Environment cannot be persisted' in response
+
+    response = c.run_command('env info -d -q')
+    response = c.run_command('echo $?')
+    assert response == "0"
+
+    response = c.run_command('env info -p -q')
+    response = c.run_command('echo $?')
+    assert response == "1"
+
+    response = c.run_command('env info -d -p -q')
+    response = c.run_command('echo $?')
+    assert response == "1"