[LTP] [PATCH] statvfs01: Convert to new LTP API

Li Wang liwang@redhat.com
Thu Dec 1 07:00:42 CET 2022


Li Wang <liwang@redhat.com> wrote:


> We (probably) know that maximum filename should be less than 255 chars
>> (for e.g.), but I think there is a good chance that trying to validate
>> this will result in false positives and stuff we might want to revert.
>>
>
> Maybe we can create a concrete size of the device and mount
> it with a designated FS (e.g. ext4), then extracting the known FS
> data into `struct statvfs` and validating them.
>

As some of the data are determined by the FS attribute and
device size. (e.g. block size, total block, fragment size, and
total inodes). We can check them directly by known values.

For those easy change data, e.g. FS free blocks, which
determined by the real system status, maybe just check
that is no large than the total block number.

Based on that I draft something below to validate the fields.
what do you think?


#include <sys/statvfs.h>
#include "tst_test.h"

#define MNT_POINT "mntpoint"
#define TEST_PATH MNT_POINT"/testfile"

static void run(void)
{
        int type;
        struct statfs buf;
        struct statvfs vbuf;

        TST_EXP_PASS_SILENT(statfs(TEST_PATH, &buf));
        TST_EXP_PASS(statvfs(TEST_PATH, &vbuf));

        tst_res(TINFO, "Extracting FS info from the '%s' file", MNT_POINT);
        tst_res(TINFO, "vbuf.f_fsid == %lu", vbuf.f_fsid);

        long fs_type = tst_fs_type(TEST_PATH);

        switch (fs_type) {
        case TST_EXT2_OLD_MAGIC:
        case TST_EXT234_MAGIC:
                TST_EXP_EQ_LI(vbuf.f_bsize, 1024);
                TST_EXP_EQ_LI(vbuf.f_frsize, 1024);
                ttype = (vbuf.f_bfree <= buf.f_blocks) ? TPASS : TFAIL;
                tst_res(ttype, "vbuf.f_bfree == %ju", (uintmax_t)
vbuf.f_bfree);
                TST_EXP_EQ_LI(vbuf.f_files, 76912);
                ttype = (vbuf.f_ffree <= vbuf.f_files) ? TPASS : TFAIL;
                tst_res(ttype, "vbuf.f_ffree == %ju", (uintmax_t)
vbuf.f_ffree);
                TST_EXP_EQ_LI(vbuf.f_flag, 4096);
                TST_EXP_EQ_LI(vbuf.f_namemax, 255);
                break;
        case TST_XFS_MAGIC:
                TST_EXP_EQ_LI(vbuf.f_bsize, 4096);
                TST_EXP_EQ_LI(vbuf.f_frsize, 4096);
                ttype = (vbuf.f_bfree <= buf.f_blocks) ? TPASS : TFAIL;
                tst_res(ttype, "vbuf.f_bfree == %ju", (uintmax_t)
vbuf.f_bfree);
                TST_EXP_EQ_LI(vbuf.f_files, 153600);
                ttype = (vbuf.f_ffree <= vbuf.f_files) ? TPASS : TFAIL;
                tst_res(ttype, "vbuf.f_ffree == %ju", (uintmax_t)
vbuf.f_ffree);
                TST_EXP_EQ_LI(vbuf.f_flag, 4096);
                TST_EXP_EQ_LI(vbuf.f_namemax, 255);
                break;
        case TST_BTRFS_MAGIC:
                TST_EXP_EQ_LI(vbuf.f_bsize, 4096);
                TST_EXP_EQ_LI(vbuf.f_frsize, 4096);
                ttype = (vbuf.f_bfree <= buf.f_blocks) ? TPASS : TFAIL;
                tst_res(ttype, "vbuf.f_bfree == %ju", (uintmax_t)
vbuf.f_bfree);
                TST_EXP_EQ_LI(vbuf.f_files, 0);
                ttype = (vbuf.f_ffree <= vbuf.f_files) ? TPASS : TFAIL;
                tst_res(ttype, "vbuf.f_ffree == %ju", (uintmax_t)
vbuf.f_ffree);
                TST_EXP_EQ_LI(vbuf.f_flag, 4096);
                TST_EXP_EQ_LI(vbuf.f_namemax, 255);
                break;
        default:
                tst_res(TINFO, "vbuf.f_bsize == %lu bytes", vbuf.f_bsize);
                tst_res(TINFO, "vbuf.f_frsize == %lu bytes", vbuf.f_frsize);
                tst_res(TINFO, "vbuf.f_bfree == %ju", (uintmax_t)
vbuf.f_bfree);
                tst_res(TINFO, "vbuf.f_files == %ju", (uintmax_t)
vbuf.f_files);
                tst_res(TINFO, "vbuf.f_ffree == %ju", (uintmax_t)
vbuf.f_ffree);
                tst_res(TINFO, "vbuf.f_namemax == %lu", vbuf.f_namemax);
                break;
    }
}

static void setup(void)
{
        SAFE_TOUCH(TEST_PATH, 0666, NULL);
}

static struct tst_test test = {
        .test_all = run,
        .setup = setup,
        .needs_root = 1,
        .mount_device = 1,
        .mntpoint = MNT_POINT,
        .dev_min_size = 300,
        .all_filesystems = 1
};


-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20221201/dceaa3b0/attachment.htm>


More information about the ltp mailing list