Skip to content

Commit 2cc0205

Browse files
Miklos Szeredibrauner
authored andcommitted
selftests: always check mask returned by statmount(2)
STATMOUNT_MNT_OPTS can actually be missing if there are no options. This is a change of behavior since 75ead69 ("fs: don't let statmount return empty strings"). The other checks shouldn't actually trigger, but add them for correctness and for easier debugging if the test fails. Signed-off-by: Miklos Szeredi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 5eb9871 commit 2cc0205

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

tools/testing/selftests/filesystems/statmount/statmount_test.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ static void test_statmount_mnt_point(void)
383383
return;
384384
}
385385

386+
if (!(sm->mask & STATMOUNT_MNT_POINT)) {
387+
ksft_test_result_fail("missing STATMOUNT_MNT_POINT in mask\n");
388+
return;
389+
}
386390
if (strcmp(sm->str + sm->mnt_point, "/") != 0) {
387391
ksft_test_result_fail("unexpected mount point: '%s' != '/'\n",
388392
sm->str + sm->mnt_point);
@@ -408,6 +412,10 @@ static void test_statmount_mnt_root(void)
408412
strerror(errno));
409413
return;
410414
}
415+
if (!(sm->mask & STATMOUNT_MNT_ROOT)) {
416+
ksft_test_result_fail("missing STATMOUNT_MNT_ROOT in mask\n");
417+
return;
418+
}
411419
mnt_root = sm->str + sm->mnt_root;
412420
last_root = strrchr(mnt_root, '/');
413421
if (last_root)
@@ -437,6 +445,10 @@ static void test_statmount_fs_type(void)
437445
strerror(errno));
438446
return;
439447
}
448+
if (!(sm->mask & STATMOUNT_FS_TYPE)) {
449+
ksft_test_result_fail("missing STATMOUNT_FS_TYPE in mask\n");
450+
return;
451+
}
440452
fs_type = sm->str + sm->fs_type;
441453
for (s = known_fs; s != NULL; s++) {
442454
if (strcmp(fs_type, *s) == 0)
@@ -464,6 +476,11 @@ static void test_statmount_mnt_opts(void)
464476
return;
465477
}
466478

479+
if (!(sm->mask & STATMOUNT_MNT_BASIC)) {
480+
ksft_test_result_fail("missing STATMOUNT_MNT_BASIC in mask\n");
481+
return;
482+
}
483+
467484
while (getline(&line, &len, f_mountinfo) != -1) {
468485
int i;
469486
char *p, *p2;
@@ -514,7 +531,10 @@ static void test_statmount_mnt_opts(void)
514531
if (p2)
515532
*p2 = '\0';
516533

517-
statmount_opts = sm->str + sm->mnt_opts;
534+
if (sm->mask & STATMOUNT_MNT_OPTS)
535+
statmount_opts = sm->str + sm->mnt_opts;
536+
else
537+
statmount_opts = "";
518538
if (strcmp(statmount_opts, p) != 0)
519539
ksft_test_result_fail(
520540
"unexpected mount options: '%s' != '%s'\n",

0 commit comments

Comments
 (0)