Add support to mount 'tmpfs' for EROFS testing
cover Add support to mount 'tmpfs' for EROFS testing
There are several tests in LTP (especially the syscalls) that test for EROFS error return in case of "read-only filesystem" that fail on Android (and possibly other systems) because of the fact that they need to find a free loopback device, create, format and mount a filesystem by default.
This makes all those tests flaky for number of reasons
- Loopback device paths are different on Android (i.e. /dev/block/loopN)
- This is very easily fixable though.
- Filesystem tools are different on Android and in some cases non-existent.
For a test that checks for EROFS, going through the whole filesystem generation and mounting is an overkill since the filesystem is unused after the mount anyway.
So, add support to mount 'tmpfs' (read-only if required) in libltp instead of creating a filesystem and mounting a device. This simplifies a lot of tests as mentioned in the changelog for PATCH 1/2.
Note: I've tested this on Android system as well as an ubuntu based machine.
Sandeep Patil (2):
libltp: add support to mount tmpfs
access04: use the new tmpfs mount for EROFS testing
include/tst_test.h | 6 ++++++ lib/tst_test.c | 17 +++++++++++++++++ testcases/kernel/syscalls/access/access04.c | 6 +++--- 3 files changed, 26 insertions(+), 3 deletions(-)
Signature · 1 line
2.14.1.342.g6490525c54-goog
RFC PATCH 1/2 libltp: add support to mount tmpfs
Some tests go through losetup, create, format and mount filesystems only to run tests for 'EROFS' return value from system calls. The tests end up being flaky depending on the tools available on the platform. e.g. mkfs.<filesystem> tool is required for mounting a device with filesystem.
If the test is only to check for EROFS, this can be achieved by simply doing a 'tmpfs' read-only mount in $tmpdir.
Example of tests that can benefit from this are:
access04, mkdirat02, mknodat02, acct01, fchown04, mknod07 etc.
This also allows for these tests to successfully run on Android.
--- include/tst_test.h | 6 ++++++ lib/tst_test.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+)
include/tst_test.h +6 -0
@@ -124,6 +124,7 @@ struct tst_test { int needs_checkpoints:1; int format_device:1; int mount_device:1; + int mount_tmpfs:1;/* Minimal device size in megabytes */ unsigned int dev_min_size;
@@ -140,6 +141,11 @@ struct tst_test {unsigned int mnt_flags;void *mnt_data; +/* tmpfs mount options, used if mount_tmpfs is set */ +const char *tmpfs_mntpoint; +unsigned int tmpfs_flags; +void *tmpfs_data; +/* override default timeout per test run, disabled == -1 */ int timeout;
lib/tst_test.c +17 -0
@@ -42,6 +42,7 @@ static int iterations = 1;static float duration =-1 ;static pid_t main_pid, lib_pid;static int device_mounted; +static int tmpfs_mounted;struct results {int passed;
@@ -734,6 +735,19 @@ static void do_setup(int argc, char *argv[]) } } +if (tst_test->mount_tmpfs) { +if (!tst_test->tmpfs_mntpoint) { +tst_brk (TBROK , +"tst_test->tmpfs_mntpoint must be set!" ); + } + +SAFE_MKDIR (tst_test->tmpfs_mntpoint,0777 ); +SAFE_MOUNT ("none" , tst_test->tmpfs_mntpoint,"tmpfs" , + tst_test->tmpfs_flags, tst_test->tmpfs_data); + + tmpfs_mounted =1 ; + } +if (tst_test->resource_files)copy_resources (); }
@@ -751,6 +765,9 @@ static void do_test_setup(void)static void do_cleanup (void ) { +if (tmpfs_mounted) +tst_umount (tst_test->tmpfs_mntpoint); +if (device_mounted)tst_umount (tst_test->mntpoint);
Signature · 1 line
2.14.1.342.g6490525c54-goog
RFC PATCH 1/2 libltp: add support to mount tmpfs
Hi!
Quoted 8 lines
Some tests go through losetup, create, format and mount filesystems only to run tests for 'EROFS' return value from system calls. The tests end up being flaky depending on the tools available on the platform. e.g. mkfs.<filesystem> tool is required for mounting a device with filesystem.
If the test is only to check for EROFS, this can be achieved by simply doing a 'tmpfs' read-only mount in $tmpdir.
Using tmpfs for EROFS sounds like a good idea, that should be much faster than loop device as well, but there is a catch. There most likely are embedded Linux devices that do not have tmpfs support compiled in and as it is this would break these testcases on such platforms.
What about we created even more high-level interface for this? For instance we can add .needs_rofs flag to the tst_test structure (reuse the mntpoint to mount it) and let the library handle the details. I.e. go for tmpfs and if that fails fall back to loop mounted device.
Signature · 2 lines
Cyril Hrubis [email protected]
RFC PATCH 1/2 libltp: add support to mount tmpfs
----- Original Message -----
Quoted 15 lines
Hi!
Quoted 8 lines
Some tests go through losetup, create, format and mount filesystems only to run tests for 'EROFS' return value from system calls. The tests end up being flaky depending on the tools available on the platform. e.g. mkfs.<filesystem> tool is required for mounting a device with filesystem.
If the test is only to check for EROFS, this can be achieved by simply doing a 'tmpfs' read-only mount in $tmpdir.
Using tmpfs for EROFS sounds like a good idea, that should be much faster than loop device as well, but there is a catch. There most likely are embedded Linux devices that do not have tmpfs support compiled in and as it is this would break these testcases on such platforms.
Quoted 4 lines
What about we created even more high-level interface for this? For instance we can add .needs_rofs flag to the
tst_teststructure (reuse the mntpoint to mount it) and let the library handle the details. I.e. go for tmpfs and if that fails fall back to loop mounted device.
Can we bind mount "/" as read-only somewhere to $tmpdir? That should be widely supported (MS_BIND since 2.4).
RFC PATCH 1/2 libltp: add support to mount tmpfs
Quoted 17 lines · Jan Stancek
----- Original Message -----
Quoted 15 lines
Hi!
Quoted 8 lines
Some tests go through losetup, create, format and mount filesystems only to run tests for 'EROFS' return value from system calls. The tests end up being flaky depending on the tools available on the platform. e.g. mkfs.<filesystem> tool is required for mounting a device with filesystem.
If the test is only to check for EROFS, this can be achieved by simply doing a 'tmpfs' read-only mount in $tmpdir.
Using tmpfs for EROFS sounds like a good idea, that should be much faster than loop device as well, but there is a catch. There most likely are embedded Linux devices that do not have tmpfs support compiled in and as it is this would break these testcases on such platforms.
Quoted 7 lines
Quoted 4 lines
What about we created even more high-level interface for this? For instance we can add .needs_rofs flag to the
tst_teststructure (reuse the mntpoint to mount it) and let the library handle the details. I.e. go for tmpfs and if that fails fall back to loop mounted device.Can we bind mount "/" as read-only somewhere to $tmpdir? That should be widely supported (
MS_BINDsince 2.4).
That sounds like a simpler, more readily available solution than 'tmpfs'. I'll change this to read-only bind mount //
- ssp
RFC PATCH 2/2 access04: use the new tmpfs mount for EROFS testing
In reply to Sandeep PatilUse the 'tmpfs' read-only mount to test for EROFS return from system call instead of finding a loop device and create, format, mount a file system
--- testcases/kernel/syscalls/access/access04.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/access/access04.c +3 -3
@@ -125,9 +125,9 @@ static struct tst_test test = { .needs_tmpdir = 1, .needs_root = 1, .forks_child = 1, - .mount_device = 1, - .mntpoint = MNT_POINT, - .mnt_flags = MS_RDONLY, + .mount_tmpfs = 1, + .tmpfs_mntpoint = MNT_POINT, + .tmpfs_flags = MS_RDONLY, .setup = setup, .test = verify_access, };
Signature · 1 line
2.14.1.342.g6490525c54-goog