diff mbox series

syscalls/statx05: add mkfs.ext4 package version check

Message ID 20201029140031.40968-1-po-hsu.lin@canonical.com
State Changes Requested
Headers show
Series syscalls/statx05: add mkfs.ext4 package version check | expand

Commit Message

Po-Hsu Lin Oct. 29, 2020, 2 p.m. UTC
The encryption feature was added in e2fsprogs 1.43:
  e2fsprogs (1.43~WIP.2015.05.18-1) unstable; urgency=low
    * Add support for file encryption feature

The test should be skipped when running with older package, otherwise
it will fail with:
  Invalid filesystem option set: encrypt

Use popen and fscanf to get mkfs.ext4 -V output for version
comparison. This version checking by adding digits together does not
work with alphabets in the number like rc1, but in that case the test
will still be tested.

It will now be skipped with (Tested with Ubuntu Xenial + 4.15 kernel):
  statx05.c:102: TCONF: Test needs mkfs.ext4 >= 1.43 for encrypt option, test skipped

Fixes: #542
Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
 testcases/kernel/syscalls/statx/statx05.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Cyril Hrubis Oct. 30, 2020, 1:12 p.m. UTC | #1
Hi!
> +	int ret, rc, major, minor, patch;
> +
> +	f = SAFE_POPEN("mkfs.ext4 -V 2>&1 | awk '/mke2fs/ {print $2}'", "r");
> +	rc = fscanf(f, "%d.%d.%d", &major, &minor, &patch);

I wonder if the awk is necessary, it may produce TWARN on minimal
embedded systems where awk is not present. Why can't we use scanf() instead?

As far as I can tell fscanf(f, "mke2fs %d.%d.%d", &major, &minor,
&patch); should work fine without the awk.
Po-Hsu Lin Nov. 2, 2020, 2:43 a.m. UTC | #2
On Fri, Oct 30, 2020 at 9:11 PM Cyril Hrubis <chrubis@suse.cz> wrote:
>
> Hi!
> > +     int ret, rc, major, minor, patch;
> > +
> > +     f = SAFE_POPEN("mkfs.ext4 -V 2>&1 | awk '/mke2fs/ {print $2}'", "r");
> > +     rc = fscanf(f, "%d.%d.%d", &major, &minor, &patch);
>
> I wonder if the awk is necessary, it may produce TWARN on minimal
> embedded systems where awk is not present. Why can't we use scanf() instead?
>
> As far as I can tell fscanf(f, "mke2fs %d.%d.%d", &major, &minor,
> &patch); should work fine without the awk.
Yes this works,
I will send V2 for this, thanks!

>
> --
> Cyril Hrubis
> chrubis@suse.cz
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/statx/statx05.c b/testcases/kernel/syscalls/statx/statx05.c
index 77684e1ed..fef848863 100644
--- a/testcases/kernel/syscalls/statx/statx05.c
+++ b/testcases/kernel/syscalls/statx/statx05.c
@@ -17,6 +17,7 @@ 
  * Second directory has no flags set.
  *
  * Minimum kernel version required is 4.11.
+ * Minimum e2fsprogs version required is 1.43.
  */
 
 #define _GNU_SOURCE
@@ -24,6 +25,7 @@ 
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include "tst_safe_stdio.h"
 #include "tst_test.h"
 #include "lapi/fs.h"
 #include "lapi/stat.h"
@@ -86,9 +88,18 @@  static void run(unsigned int i)
 
 static void setup(void)
 {
+	FILE *f;
 	char opt_bsize[32];
 	const char *const fs_opts[] = {"-O encrypt", opt_bsize, NULL};
-	int ret;
+	int ret, rc, major, minor, patch;
+
+	f = SAFE_POPEN("mkfs.ext4 -V 2>&1 | awk '/mke2fs/ {print $2}'", "r");
+	rc = fscanf(f, "%d.%d.%d", &major, &minor, &patch);
+	if (rc != 3)
+		tst_res(TWARN, "Unable parse version number");
+	else if (major * 10000 + minor * 100 + patch < 14300)
+		tst_brk(TCONF, "Test needs mkfs.ext4 >= 1.43 for encrypt option, test skipped");
+	pclose(f);
 
 	snprintf(opt_bsize, sizeof(opt_bsize), "-b %i", getpagesize());