Skip to content

Commit 9d7a26f

Browse files
coolgwwangli5665
authored andcommitted
tst_filesystems01.c: Add test for .filesystems
Fixes: #1243 Signed-off-by: Wei Gao <wegao@suse.com> Reviewed-by: Petr Vorel <pvorel@suse.cz> Reviewed-by: Li Wang <liwang@redhat.com>
1 parent 1ba5880 commit 9d7a26f

2 files changed

Lines changed: 109 additions & 0 deletions

File tree

lib/newlib_tests/runtest.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ tst_checkpoint_wait_timeout
2424
tst_checkpoint_wake_timeout
2525
tst_device
2626
tst_expiration_timer
27+
tst_filesystems01
2728
tst_fuzzy_sync0[1-3]
2829
tst_needs_cmds0[1-36-8]
2930
tst_res_hexd
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright (c) 2025 Wei Gao <wegao@suse.com>
4+
*/
5+
6+
#include "tst_test.h"
7+
#include "tst_safe_stdio.h"
8+
9+
#define INODE_SIZE 128
10+
#define BLOCK_SIZE 1024
11+
#define MKFS_SIZE_VAL 10240
12+
13+
#define MOUNT_POINT "mount_test_filesystems"
14+
15+
static int check_inode_size(unsigned int size)
16+
{
17+
char path[PATH_MAX];
18+
char line[PATH_MAX];
19+
FILE *tune2fs;
20+
char str_size[NAME_MAX];
21+
22+
snprintf(str_size, sizeof(str_size), "%u", size);
23+
snprintf(path, sizeof(path), "tune2fs -l %s 2>&1", tst_device->dev);
24+
tune2fs = SAFE_POPEN(path, "r");
25+
26+
while (fgets(line, PATH_MAX, tune2fs) != NULL) {
27+
if (strstr(line, "Inode size:") && strstr(line, str_size))
28+
return 0;
29+
}
30+
31+
pclose(tune2fs);
32+
return -1;
33+
}
34+
35+
static int check_mnt_data(char *opt)
36+
{
37+
FILE *fp;
38+
char line[PATH_MAX];
39+
40+
fp = SAFE_FOPEN("/proc/mounts", "r");
41+
42+
while (fgets(line, PATH_MAX, fp) != NULL) {
43+
if (strstr(line, tst_device->dev) && strstr(line, opt))
44+
return 0;
45+
}
46+
SAFE_FCLOSE(fp);
47+
return -1;
48+
}
49+
50+
static int check_mkfs_size_opt(unsigned int size)
51+
{
52+
char path[PATH_MAX];
53+
char line[PATH_MAX];
54+
FILE *dumpe2fs;
55+
char str_size[NAME_MAX];
56+
57+
snprintf(str_size, sizeof(str_size), "%u", size);
58+
snprintf(path, sizeof(path), "dumpe2fs -h %s 2>&1", tst_device->dev);
59+
dumpe2fs = SAFE_POPEN(path, "r");
60+
61+
while (fgets(line, PATH_MAX, dumpe2fs) != NULL) {
62+
if (strstr(line, "Block count:") && strstr(line, str_size))
63+
return 0;
64+
}
65+
66+
pclose(dumpe2fs);
67+
return -1;
68+
}
69+
70+
static void do_test(void)
71+
{
72+
long fs_type;
73+
74+
fs_type = tst_fs_type(MOUNT_POINT);
75+
76+
if (fs_type == TST_EXT234_MAGIC) {
77+
TST_EXP_PASS((check_inode_size(INODE_SIZE)));
78+
TST_EXP_PASS((check_mkfs_size_opt(MKFS_SIZE_VAL)));
79+
}
80+
81+
if (fs_type == TST_XFS_MAGIC)
82+
TST_EXP_PASS((check_mnt_data("usrquota")));
83+
}
84+
85+
static struct tst_test test = {
86+
.test_all = do_test,
87+
.needs_root = 1,
88+
.mntpoint = MOUNT_POINT,
89+
.mount_device = 1,
90+
.needs_cmds = (struct tst_cmd[]) {
91+
{.cmd = "tune2fs"},
92+
{.cmd = "dumpe2fs"},
93+
{}
94+
},
95+
.filesystems = (struct tst_fs []) {
96+
{
97+
.type = "ext3",
98+
.mkfs_opts = (const char *const []){"-I", TST_TO_STR(INODE_SIZE), "-b", TST_TO_STR(BLOCK_SIZE), NULL},
99+
.mkfs_size_opt = TST_TO_STR(MKFS_SIZE_VAL),
100+
},
101+
{
102+
.type = "xfs",
103+
.mnt_data = "usrquota",
104+
},
105+
{}
106+
},
107+
108+
};

0 commit comments

Comments
 (0)