From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: Linux Test Project <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v2 1/2] fallocate01: Convert to new API
Date: Wed, 26 Aug 2026 13:00:17 +0200 [thread overview]
Message-ID: <ao7HQbIt34iRZ2RV@yuki.lan> (raw)
In-Reply-To: <20260807-convert_fallocate_suite-v2-1-3761f7b74b1f@suse.com>
Hi!
> -int main(int ac, char **av)
> +static void run(unsigned int n)
> {
> - loff_t expected_size;
> - int lc;
> -
> - tst_parse_opts(ac, av, NULL, NULL);
> + struct tcase *tc = &tcases[n];
> + struct stat file_stat;
> + loff_t offset, len, pos, write_offset, expected_size;
>
> - setup();
> + /* Reset the backing file to a pristine 12-block state per run. */
> + SAFE_FTRUNCATE(fd, 0);
> + SAFE_LSEEK(fd, 0, SEEK_SET);
> + populate_file();
>
> - for (lc = 0; TEST_LOOPING(lc); lc++) {
> - tst_count = 0;
> + offset = SAFE_LSEEK(fd, 0, SEEK_END);
> + len = block_size;
> + expected_size = (loff_t)tc->expected_blocks * block_size;
>
> - expected_size = BLOCKS_WRITTEN * block_size + block_size;
> - runtest(0, fd_mode1, expected_size);
> + TEST(fallocate(fd, tc->mode, offset, len));
> + if (TST_RET != 0) {
> + if (TST_ERR == EOPNOTSUPP || TST_ERR == ENOSYS)
> + tst_brk(TCONF, "fallocate() not supported");
>
> - expected_size = BLOCKS_WRITTEN * block_size;
> - runtest(FALLOC_FL_KEEP_SIZE, fd_mode2, expected_size);
> + tst_res(TFAIL | TTERRNO, "fallocate(%s, %lld, %lld) failed",
> + tc->desc, (long long)offset, (long long)len);
> + return;
> }
> + tst_res(TPASS, "fallocate(%s, %lld, %lld) succeeded",
> + tc->desc, (long long)offset, (long long)len);
Can we do a dummy call to fallocate in the test setup and check for the
EOPNOTSUPP and ENOSYS so that we can use TST_EXP_PASS() here instead?
> - cleanup();
> - tst_exit();
> -}
> -
> -/*****************************************************************************
> - * Calls the system call, with appropriate parameters and writes data
> - ******************************************************************************/
> -void runtest(int mode, int fd, loff_t expected_size)
> -{
> - loff_t offset;
> - loff_t len = block_size;
> - loff_t write_offset, lseek_offset;
> - offset = lseek(fd, 0, SEEK_END);
> - struct stat file_stat;
> - errno = 0;
> -
> - TEST(fallocate(fd, mode, offset, len));
> - /* check return code */
> - if (TEST_RETURN != 0) {
> - if (TEST_ERRNO == EOPNOTSUPP || TEST_ERRNO == ENOSYS) {
> - tst_brkm(TCONF, cleanup,
> - "fallocate system call is not implemented");
> - }
> - tst_resm(TFAIL | TTERRNO,
> - "fallocate(%d, %d, %" PRId64 ", %" PRId64 ") failed",
> - fd, mode, offset, len);
> - return;
> + SAFE_FSTAT(fd, &file_stat);
> + if (file_stat.st_size != expected_size) {
> + tst_res(TFAIL, "file size is %lld, expected %lld",
> + (long long)file_stat.st_size, (long long)expected_size);
> } else {
> - tst_resm(TPASS,
> - "fallocate(%d, %d, %" PRId64 ", %" PRId64
> - ") returned %ld", fd, mode, offset, len,
> - TEST_RETURN);
> + tst_res(TPASS, "file size is %lld as expected",
> + (long long)expected_size);
> }
Can we use TST_EXP_EQ macro here?
> - if (fstat(fd, &file_stat) < 0)
> - tst_resm(TFAIL | TERRNO, "fstat failed after fallocate()");
> -
> - if (file_stat.st_size != expected_size)
> - tst_resm(TFAIL | TERRNO,
> - "fstat test fails on fallocate (%d, %d, %" PRId64 ", %"
> - PRId64 ") Failed on mode", fd, mode, offset, len);
> -
> - write_offset = random() % len;
> - lseek_offset = lseek(fd, write_offset, SEEK_CUR);
> - if (lseek_offset != offset + write_offset) {
> - tst_resm(TFAIL | TERRNO,
> - "lseek fails in fallocate(%d, %d, %" PRId64 ", %"
> - PRId64 ") failed on mode", fd, mode, offset, len);
> + write_offset = len / 2;
> + pos = SAFE_LSEEK(fd, write_offset, SEEK_CUR);
> + if (pos != offset + write_offset) {
> + tst_res(TFAIL, "lseek returned %lld, expected %lld",
> + (long long)pos, (long long)(offset + write_offset));
> return;
> }
And here?
> - //Write a character to file at random location
> - TEST(write(fd, "A", 1));
> - /* check return code */
> - if (TEST_RETURN == -1) {
> - tst_resm(TFAIL | TTERRNO,
> - "write fails in fallocate(%d, %d, %" PRId64 ", %"
> - PRId64 ") failed", fd, mode, offset, len);
> - } else {
> - tst_resm(TPASS,
> - "write operation on fallocated(%d, %d, %"
> - PRId64 ", %" PRId64 ") returned %ld", fd, mode,
> - offset, len, TEST_RETURN);
> - }
> +
> + TST_EXP_POSITIVE(write(fd, "A", 1),
> + "write into the newly allocated region");
> +}
> +
> +static void cleanup(void)
> +{
> + if (fd != -1)
> + SAFE_CLOSE(fd);
> }
> +
> +static struct tst_test test = {
> + .setup = setup,
> + .cleanup = cleanup,
> + .test = run,
> + .tcnt = ARRAY_SIZE(tcases),
> + .needs_tmpdir = 1,
> +};
I guess that it would make sense to enable the test for all_filesystems
here.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-08-26 11:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 8:15 [LTP] [PATCH v2 0/2] Convert fallocate testing suite Andrea Cervesato
2026-08-07 8:15 ` [LTP] [PATCH v2 1/2] fallocate01: Convert to new API Andrea Cervesato
2026-08-07 10:03 ` [LTP] " linuxtestproject.agent
2026-08-26 11:00 ` Cyril Hrubis [this message]
2026-08-07 8:15 ` [LTP] [PATCH v2 2/2] fallocate02: " Andrea Cervesato
2026-08-26 11:27 ` Cyril Hrubis
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=ao7HQbIt34iRZ2RV@yuki.lan \
--to=chrubis@suse.cz \
--cc=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox