All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Wang <liwang@redhat.com>
To: rpalethorpe@suse.de
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] statvfs01: Convert to new LTP API
Date: Thu, 1 Dec 2022 14:00:42 +0800	[thread overview]
Message-ID: <CAEemH2eQ5EKwjoUaz52hPxdCHgdJEG90cCMWDgKq-P1RGJQXvw@mail.gmail.com> (raw)
In-Reply-To: <CAEemH2dErC+9-UawDMdYq=rCnHOE7ciU7dZ4Ma0A542wdrg+eA@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 4113 bytes --]

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

[-- Attachment #1.2: Type: text/html, Size: 8403 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

      reply	other threads:[~2022-12-01  6:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-24 11:42 [LTP] [PATCH] statvfs01: Convert to new LTP API Avinesh Kumar
2022-11-25  2:18 ` Li Wang
2022-11-29 10:58   ` Richard Palethorpe
2022-11-30  7:05     ` [LTP] [PATCH v2] " Avinesh Kumar
2022-11-30  8:52       ` Petr Vorel
2022-11-30  9:50         ` Petr Vorel
2022-12-01  5:16           ` Li Wang
2022-12-01  9:34             ` Richard Palethorpe
2022-12-02  9:20               ` Petr Vorel
2022-12-01  8:51           ` Avinesh Kumar
2022-12-01  9:17             ` Li Wang
2022-12-01 10:45               ` Petr Vorel
2022-12-01 11:04                 ` Avinesh Kumar
2022-11-30  7:20     ` [LTP] [PATCH] " Li Wang
2022-12-01  6:00       ` Li Wang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEemH2eQ5EKwjoUaz52hPxdCHgdJEG90cCMWDgKq-P1RGJQXvw@mail.gmail.com \
    --to=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    --cc=rpalethorpe@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.