Skip to contentSkip to conversation

test: fs: Add filesystem integrity checks

PATCH New Jean-Jacques Hiblot 3 participants 5 messages Feb 4, 2019 – Feb 10, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test: fs: Add filesystem integrity checks

We need to make sure that file writes,file creation, etc. are properly performed and do not corrupt the filesystem.
To help with this, introduce the assert_fs_integrity() function that executes the appropriate fsck tool. It should be called at the end of any test that modifies the content/organization of the filesystem. Currently only supports FATs and EXT4.

---

While working on symlink I had noticed the need for automated check of the filesystem. It indeed helped catch a few corruption problems.

- SPOILER - this patch will turn some lights red in travis - SPOILER -

 test/py/tests/test_fs/fstest_helpers.py | 10 ++++++++++
 test/py/tests/test_fs/test_basic.py     |  4 ++++
 test/py/tests/test_fs/test_ext.py       | 10 ++++++++++
 test/py/tests/test_fs/test_mkdir.py     |  8 ++++++++
 test/py/tests/test_fs/test_unlink.py    | 14 +++++++++++---
 5 files changed, 43 insertions(+), 3 deletions(-)
 create mode 100644 test/py/tests/test_fs/fstest_helpers.py
test/py/tests/test_fs/fstest_helpers.py new file +10 -0
new file mode 100644
index 0000000000..28fc460468
@@ -0,0 +1,10 @@
+from subprocess import check_call, CalledProcessError
+
+def assert_fs_integrity(fs_type, fs_img):
+    try:
+        if fs_type == 'ext4':
+            check_call('fsck.ext4 -n -f %s' % fs_img, shell=True)
+        if fs_type == 'fat':
+            check_call('fsck.fat -n %s' % fs_img, shell=True)
+    except CalledProcessError:
+        raise
test/py/tests/test_fs/test_basic.py +4 -0
index 140ca29ac7..71f3e86fb1 100644
@@ -11,6 +11,7 @@ This test verifies basic read/write operation on file system.
 import pytest
 import re
 from fstest_defs import *
+from fstest_helpers import assert_fs_integrity
 
 @pytest.mark.boardspec('sandbox')
 @pytest.mark.slow
@@ -237,6 +238,7 @@ class TestFsBasic(object):
                 'md5sum %x $filesize' % ADDR,
                 'setenv filesize'])
             assert(md5val[0] in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_fs12(self, u_boot_console, fs_obj_basic):
         """
@@ -252,6 +254,7 @@ class TestFsBasic(object):
                 'host bind 0 %s' % fs_img,
                 '%swrite host 0:0 %x /. 0x10' % (fs_type, ADDR)])
             assert('Unable to write' in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_fs13(self, u_boot_console, fs_obj_basic):
         """
@@ -286,3 +289,4 @@ class TestFsBasic(object):
                 'md5sum %x $filesize' % ADDR,
                 'setenv filesize'])
             assert(md5val[0] in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
test/py/tests/test_fs/test_ext.py +10 -0
index 06cad5516d..2c47738b8d 100644
@@ -11,6 +11,7 @@ This test verifies extended write operation on file system.
 import pytest
 import re
 from fstest_defs import *
+from fstest_helpers import assert_fs_integrity
 
 @pytest.mark.boardspec('sandbox')
 @pytest.mark.slow
@@ -36,6 +37,7 @@ class TestFsExt(object):
                 'md5sum %x $filesize' % ADDR,
                 'setenv filesize'])
             assert(md5val[0] in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_fs_ext2(self, u_boot_console, fs_obj_ext):
         """
@@ -58,6 +60,7 @@ class TestFsExt(object):
                 'md5sum %x $filesize' % ADDR,
                 'setenv filesize'])
             assert(md5val[0] in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_fs_ext3(self, u_boot_console, fs_obj_ext):
         """
@@ -72,6 +75,7 @@ class TestFsExt(object):
                 '%swrite host 0:0 %x /dir1/none/%s.w3 $filesize'
                     % (fs_type, ADDR, MIN_FILE)])
             assert('Unable to write "/dir1/none/' in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_fs_ext4(self, u_boot_console, fs_obj_ext):
         """
@@ -104,6 +108,7 @@ class TestFsExt(object):
                 'md5sum %x $filesize' % ADDR,
                 'setenv filesize'])
             assert(md5val[1] in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_fs_ext5(self, u_boot_console, fs_obj_ext):
         """
@@ -136,6 +141,7 @@ class TestFsExt(object):
                 'md5sum %x $filesize' % ADDR,
                 'setenv filesize'])
             assert(md5val[2] in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_fs_ext6(self, u_boot_console, fs_obj_ext):
         """
@@ -160,6 +166,7 @@ class TestFsExt(object):
                 'printenv filesize',
                 'setenv filesize'])
             assert('filesize=0' in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_fs_ext7(self, u_boot_console, fs_obj_ext):
         """
@@ -192,6 +199,7 @@ class TestFsExt(object):
                 'md5sum %x $filesize' % ADDR,
                 'setenv filesize'])
             assert(md5val[3] in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_fs_ext8(self, u_boot_console, fs_obj_ext):
         """
@@ -209,6 +217,7 @@ class TestFsExt(object):
                 '%swrite host 0:0 %x /dir1/%s.w8 0x1400 %x'
                     % (fs_type, ADDR, MIN_FILE, 0x100000 + 0x1400))
             assert('Unable to write "/dir1' in output)
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_fs_ext9(self, u_boot_console, fs_obj_ext):
         """
@@ -223,3 +232,4 @@ class TestFsExt(object):
                 '%swrite host 0:0 %x /dir1/%s.w9 0x1400 0x1400'
                     % (fs_type, ADDR, MIN_FILE)])
             assert('Unable to write "/dir1' in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
test/py/tests/test_fs/test_mkdir.py +8 -0
index b3fe11cf3b..fa9561ec35 100644
@@ -9,6 +9,7 @@ This test verifies mkdir operation on file system.
 """
 
 import pytest
+from fstest_helpers import assert_fs_integrity
 
 @pytest.mark.boardspec('sandbox')
 @pytest.mark.slow
@@ -29,6 +30,8 @@ class TestMkdir(object):
                 '%sls host 0:0 dir1' % fs_type)
             assert('./'   in output)
             assert('../'  in output)
+            assert_fs_integrity(fs_type, fs_img)
+
 
     def test_mkdir2(self, u_boot_console, fs_obj_mkdir):
         """
@@ -46,6 +49,7 @@ class TestMkdir(object):
                 '%sls host 0:0 dir1/dir2' % fs_type)
             assert('./'   in output)
             assert('../'  in output)
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_mkdir3(self, u_boot_console, fs_obj_mkdir):
         """
@@ -58,6 +62,7 @@ class TestMkdir(object):
                 'host bind 0 %s' % fs_img,
                 '%smkdir host 0:0 none/dir3' % fs_type])
             assert('Unable to create a directory' in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_mkdir4(self, u_boot_console, fs_obj_mkdir):
         """
@@ -69,6 +74,7 @@ class TestMkdir(object):
                 'host bind 0 %s' % fs_img,
                 '%smkdir host 0:0 .' % fs_type])
             assert('Unable to create a directory' in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_mkdir5(self, u_boot_console, fs_obj_mkdir):
         """
@@ -80,6 +86,7 @@ class TestMkdir(object):
                 'host bind 0 %s' % fs_img,
                 '%smkdir host 0:0 ..' % fs_type])
             assert('Unable to create a directory' in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_mkdir6(self, u_boot_console, fs_obj_mkdir):
         """
@@ -111,3 +118,4 @@ class TestMkdir(object):
                 '%sls host 0:0 dir6/0123456789abcdef13/..' % fs_type)
             assert('0123456789abcdef00/'  in output)
             assert('0123456789abcdef13/'  in output)
+            assert_fs_integrity(fs_type, fs_img)
test/py/tests/test_fs/test_unlink.py +11 -3
index 2b817468ed..97aafc63bb 100644
@@ -10,6 +10,7 @@ on file system.
 """
 
 import pytest
+from fstest_helpers import assert_fs_integrity
 
 @pytest.mark.boardspec('sandbox')
 @pytest.mark.slow
@@ -30,6 +31,7 @@ class TestUnlink(object):
                 '%sls host 0:0 dir1/' % fs_type)
             assert(not 'file1' in output)
             assert('file2' in output)
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_unlink2(self, u_boot_console, fs_obj_unlink):
         """
@@ -48,6 +50,7 @@ class TestUnlink(object):
             output = u_boot_console.run_command(
                 '%sls host 0:0 dir2' % fs_type)
             assert('0 file(s), 2 dir(s)' in output)
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_unlink3(self, u_boot_console, fs_obj_unlink):
         """
@@ -59,6 +62,7 @@ class TestUnlink(object):
                 'host bind 0 %s' % fs_img,
                 '%srm host 0:0 dir1/nofile' % fs_type])
             assert('nofile: doesn\'t exist' in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_unlink4(self, u_boot_console, fs_obj_unlink):
         """
@@ -71,9 +75,10 @@ class TestUnlink(object):
                 '%srm host 0:0 dir4' % fs_type])
             assert('' == ''.join(output))
 
-        output = u_boot_console.run_command(
-            '%sls host 0:0 /' % fs_type)
-        assert(not 'dir4' in output)
+            output = u_boot_console.run_command(
+                '%sls host 0:0 /' % fs_type)
+            assert(not 'dir4' in output)
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_unlink5(self, u_boot_console, fs_obj_unlink):
         """
@@ -86,6 +91,7 @@ class TestUnlink(object):
                 'host bind 0 %s' % fs_img,
                 '%srm host 0:0 dir5' % fs_type])
             assert('directory is not empty' in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_unlink6(self, u_boot_console, fs_obj_unlink):
         """
@@ -97,6 +103,7 @@ class TestUnlink(object):
                 'host bind 0 %s' % fs_img,
                 '%srm host 0:0 dir5/.' % fs_type])
             assert('directory is not empty' in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
 
     def test_unlink7(self, u_boot_console, fs_obj_unlink):
         """
@@ -108,3 +115,4 @@ class TestUnlink(object):
                 'host bind 0 %s' % fs_img,
                 '%srm host 0:0 dir5/..' % fs_type])
             assert('directory is not empty' in ''.join(output))
+            assert_fs_integrity(fs_type, fs_img)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 test: fs: Add filesystem integrity checks

Quoted 7 lines · Jean-Jacques Hiblot

We need to make sure that file writes,file creation, etc. are properly performed and do not corrupt the filesystem.
To help with this, introduce the assert_fs_integrity() function that executes the appropriate fsck tool. It should be called at the end of any test that modifies the content/organization of the filesystem. Currently only supports FATs and EXT4.

Quoted 7 lines

---

While working on symlink I had noticed the need for automated check of the filesystem. It indeed helped catch a few corruption problems.

- SPOILER - this patch will turn some lights red in travis - SPOILER -

Oh fun. Do you have a link to the travis failures? Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190205/0c043c77/attachment.sig>
#2 lore raw

PATCH 1/1 test: fs: Add filesystem integrity checks

Quoted 8 lines · Tom Rini
Quoted 7 lines · Jean-Jacques Hiblot

We need to make sure that file writes,file creation, etc. are properly performed and do not corrupt the filesystem.
To help with this, introduce the assert_fs_integrity() function that executes the appropriate fsck tool. It should be called at the end of any test that modifies the content/organization of the filesystem. Currently only supports FATs and EXT4.

Quoted 8 lines
Quoted 7 lines

---

While working on symlink I had noticed the need for automated check of the filesystem. It indeed helped catch a few corruption problems.

- SPOILER - this patch will turn some lights red in travis - SPOILER -

Oh fun. Do you have a link to the travis failures? Thanks!

Actually I was wrong. no red lights: the fs tests are skipped :/ Probably because they take so long to run.

I haven't figured out how they are disabled and how to enable them.

Nevertheless running the test at least on sandbox would be a pretty good idea. It revealed some corruptions going on with FAT16 and FAT32

Quoted 1 line
#3 lore raw

PATCH 1/1 test: fs: Add filesystem integrity checks

+ Simon

Quoted 21 lines · Jean-Jacques Hiblot
Quoted 12 lines · Tom Rini
Quoted 11 lines · Jean-Jacques Hiblot

We need to make sure that file writes,file creation, etc. are properly performed and do not corrupt the filesystem.
To help with this, introduce the assert_fs_integrity() function that executes the appropriate fsck tool. It should be called at the end of any
test that modifies the content/organization of the filesystem. Currently only supports FATs and EXT4.

---

Quoted 6 lines
Quoted 5 lines

While working on symlink I had noticed the need for automated check of the
filesystem. It indeed helped catch a few corruption problems.

- SPOILER - this patch will turn some lights red in travis - SPOILER -

Oh fun.  Do you have a link to the travis failures?  Thanks!

Quoted 9 lines

Actually I was wrong. no red lights: the fs tests are skipped :/ Probably because they take so long to run.

I haven't figured out how they are disabled and how to enable them.

Nevertheless running the test at least on sandbox would be a pretty good idea. It revealed some corruptions going on with FAT16 and FAT32

Simon,

Do you have an idea on how to enable the fs tests in travis? Not on all platforms but it would be nice to enable them on sandbox.

JJ

Quoted 10 lines
Quoted 6 lines

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot

#4 lore raw

PATCH 1/1 test: fs: Add filesystem integrity checks

Hi Jean-Jacques,

Quoted 30 lines · Jean-Jacques Hiblot

+ Simon

Quoted 26 lines · Jean-Jacques Hiblot
Quoted 12 lines · Tom Rini
Quoted 11 lines · Jean-Jacques Hiblot

We need to make sure that file writes,file creation, etc. are properly performed and do not corrupt the filesystem.
To help with this, introduce the assert_fs_integrity() function that executes the appropriate fsck tool. It should be called at the end of any
test that modifies the content/organization of the filesystem. Currently only supports FATs and EXT4.

---

Quoted 6 lines
Quoted 5 lines

While working on symlink I had noticed the need for automated check of the
filesystem. It indeed helped catch a few corruption problems.

- SPOILER - this patch will turn some lights red in travis - SPOILER -

Oh fun. Do you have a link to the travis failures? Thanks!

Actually I was wrong. no red lights: the fs tests are skipped :/ Probably because they take so long to run.

I haven't figured out how they are disabled and how to enable them.

Quoted 8 lines
Quoted 4 lines

Nevertheless running the test at least on sandbox would be a pretty good idea. It revealed some corruptions going on with FAT16 and FAT32

Simon,

Do you have an idea on how to enable the fs tests in travis? Not on all platforms but it would be nice to enable them on sandbox.

No I am not sure what is going on. The FS tests are definitely skipped on travis, but something like:

./test/py/test.py --bd sandbox --build-dir build-sandbox --build

does run them. That appears to be what travis is using:

./test/py/test.py --bd ${TEST_PY_BD} ${TEST_PY_ID} -k "${TEST_PY_TEST_SPEC:-not a_test_which_does_not_exist}" --build-dir "$UBOOT_TRAVIS_BUILD_DIR";

as from what I can tell, TEST_PY_TEST_SPEC and TEST_PY_ID are empty when running sandbox tests.

Tom is much more of an expert on this than me.

Regards,
Simon