Message ID | 20200616074048.7898-7-patrick.delaunay@st.com |
---|---|
State | New |
Headers | show |
Series | env: ext4: corrections and add test for env in ext4 | expand |
On 6/16/20 1:40 AM, Patrick Delaunay wrote: > Add basic test to persistent environment in ext4: > save and load in host ext4 file 'uboot.env'. > > On first execution an empty EXT4 file system is created in > persistent data dir: env.ext4.img. > diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py > +def mk_env_ext4(state_test_env): > + if os.path.exists(persistent): > + c.log.action('Disk image file ' + persistent + ' already exists') > + else: > + try: > + check_call('rm -f %s' % persistent, shell=True) This should be run with the results logged to the overall test log file so that if there are failures, it's possible to see what they were. Use util.run_and_log() for this. Also, this particular command doesn't seem useful, since 4 lines above the code verified that the file doesn't exist. > + at pytest.mark.boardspec('sandbox') > + at pytest.mark.buildconfigspec('cmd_nvedit_info') > + at pytest.mark.buildconfigspec('cmd_echo') > + at pytest.mark.buildconfigspec('env_is_in_ext4') > +def test_env_ext4(state_test_env): > + > + c = state_test_env.u_boot_console Nit: That blank line is a bit odd. > + fs_img = mk_env_ext4(state_test_env) > + c.run_command('host bind 0 %s' % fs_img) > + > + response = c.run_command('ext4ls host 0:0') > + assert 'uboot.env' not in response > + > + """ env location: ENVL_EXT4 (2) > + """ Nit: Wrap the trailing """ onto the same line; no need to force it to be a multi-line string. Also a comman may be better rather than a docstring. Same for the other docstring later. > + call('rm -f %s' % fs_img, shell=True) This won't happen if the test fails earlier. Should there be a try/except block or wrapper function with exception handling to resolve this?
Hi, > From: Stephen Warren <swarren at wwwdotorg.org> > Sent: lundi 22 juin 2020 20:57 > > On 6/16/20 1:40 AM, Patrick Delaunay wrote: > > Add basic test to persistent environment in ext4: > > save and load in host ext4 file 'uboot.env'. > > > > On first execution an empty EXT4 file system is created in persistent > > data dir: env.ext4.img. > > > diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py > > > +def mk_env_ext4(state_test_env): > > > + if os.path.exists(persistent): > > + c.log.action('Disk image file ' + persistent + ' already exists') > > + else: > > + try: > > + check_call('rm -f %s' % persistent, shell=True) > > This should be run with the results logged to the overall test log file so that if there > are failures, it's possible to see what they were. Use > util.run_and_log() for this. Ok, I will modifiy this part (I copy ext4 file create is copied form py/tests/test_fs/conftest.py:166 mk_fs() ) > Also, this particular command doesn't seem useful, since 4 lines above the code > verified that the file doesn't exist. Yes not needed, I remove this line. > > + at pytest.mark.boardspec('sandbox') > > + at pytest.mark.buildconfigspec('cmd_nvedit_info') > > + at pytest.mark.buildconfigspec('cmd_echo') > > + at pytest.mark.buildconfigspec('env_is_in_ext4') > > +def test_env_ext4(state_test_env): > > + > > + c = state_test_env.u_boot_console > > Nit: That blank line is a bit odd. OK > > + fs_img = mk_env_ext4(state_test_env) > > + c.run_command('host bind 0 %s' % fs_img) > > + > > + response = c.run_command('ext4ls host 0:0') > > + assert 'uboot.env' not in response > > + > > + """ env location: ENVL_EXT4 (2) > > + """ > > Nit: Wrap the trailing """ onto the same line; no need to force it to be a multi-line > string. Also a comman may be better rather than a docstring. Same for the other > docstring later. OK, I don't realized that it was docstring. > > + call('rm -f %s' % fs_img, shell=True) > > This won't happen if the test fails earlier. Should there be a try/except block or > wrapper function with exception handling to resolve this? Yes, I add it for V3 Patrick
diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py index cbdb41031c..6f1d94b953 100644 --- a/test/py/tests/test_env.py +++ b/test/py/tests/test_env.py @@ -4,6 +4,10 @@ # Test operation of shell commands relating to environment variables. +import os +import os.path +from subprocess import call, check_call + import pytest import u_boot_utils @@ -380,3 +384,86 @@ def test_env_info_quiet(state_test_env): assert response == "" response = c.run_command('echo $?') assert response == "1" + +def mk_env_ext4(state_test_env): + c = state_test_env.u_boot_console + + """Create a empty ext4 file system volume. + """ + filename = 'env.ext4.img' + persistent = c.config.persistent_data_dir + '/' + filename + fs_img = c.config.result_dir + '/' + filename + + if os.path.exists(persistent): + c.log.action('Disk image file ' + persistent + ' already exists') + else: + try: + check_call('rm -f %s' % persistent, shell=True) + check_call('dd if=/dev/zero of=%s bs=1M count=16' + % persistent, shell=True) + check_call('mkfs.ext4 -O ^metadata_csum %s' % persistent, shell=True) + except CalledProcessError: + call('rm -f %s' % persistent, shell=True) + raise + + call('cp -f %s %s' % (persistent, fs_img), shell=True) + return fs_img + + at pytest.mark.boardspec('sandbox') + at pytest.mark.buildconfigspec('cmd_nvedit_info') + at pytest.mark.buildconfigspec('cmd_echo') + at pytest.mark.buildconfigspec('env_is_in_ext4') +def test_env_ext4(state_test_env): + + c = state_test_env.u_boot_console + + fs_img = mk_env_ext4(state_test_env) + c.run_command('host bind 0 %s' % fs_img) + + response = c.run_command('ext4ls host 0:0') + assert 'uboot.env' not in response + + """ env location: ENVL_EXT4 (2) + """ + response = c.run_command('env_loc 2') + assert 'Saving Environment to EXT4' in response + + response = c.run_command('env_loc 2') + assert 'Loading Environment from EXT4... OK' in response + + response = c.run_command('ext4ls host 0:0') + assert '8192 uboot.env' in response + + response = c.run_command('env info') + assert 'env_valid = valid' in response + assert 'env_ready = true' in response + assert 'env_use_default = false' in response + + response = c.run_command('env info -p -d') + assert 'Environment was loaded from persistent storage' in response + assert 'Environment can be persisted' in response + + response = c.run_command('env info -d -q') + assert response == "" + response = c.run_command('echo $?') + assert response == "1" + + response = c.run_command('env info -p -q') + assert response == "" + response = c.run_command('echo $?') + assert response == "0" + + """ restore env location: ENVL_NOWHERE (12) + """ + c.run_command('env_loc 12') + + response = c.run_command('env info') + assert 'env_valid = valid' in response + 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 + + call('rm -f %s' % fs_img, shell=True)
Add basic test to persistent environment in ext4: save and load in host ext4 file 'uboot.env'. On first execution an empty EXT4 file system is created in persistent data dir: env.ext4.img. Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com> --- (no changes since v1) test/py/tests/test_env.py | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)