* [LTP] [PATCH 0/2] Convert fallocate testing suite
@ 2026-07-20 11:48 Andrea Cervesato
2026-07-20 11:48 ` [LTP] [PATCH 1/2] fallocate01: Convert to new API Andrea Cervesato
2026-07-20 11:48 ` [LTP] [PATCH 2/2] fallocate02: " Andrea Cervesato
0 siblings, 2 replies; 4+ messages in thread
From: Andrea Cervesato @ 2026-07-20 11:48 UTC (permalink / raw)
To: Linux Test Project
Testing a new multi-agent converter that does a deep analysis on the
code, evaluate if it needs to be converted line by line or it only needs
a complete rewrite, then it spawn an agent for writing the test, one for
reviewing and it iterates until test is out of issues.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Andrea Cervesato (2):
fallocate01: Convert to new API
fallocate02: Convert to new API
testcases/kernel/syscalls/fallocate/fallocate01.c | 337 ++++++----------------
testcases/kernel/syscalls/fallocate/fallocate02.c | 193 ++++---------
2 files changed, 157 insertions(+), 373 deletions(-)
---
base-commit: ab04cf4157defb7f21a3cbf3392dec758dab590a
change-id: 20260720-convert_fallocate_suite-820312fbf352
Best regards,
--
Andrea Cervesato <andrea.cervesato@suse.com>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* [LTP] [PATCH 1/2] fallocate01: Convert to new API
2026-07-20 11:48 [LTP] [PATCH 0/2] Convert fallocate testing suite Andrea Cervesato
@ 2026-07-20 11:48 ` Andrea Cervesato
2026-07-20 13:16 ` [LTP] " linuxtestproject.agent
2026-07-20 11:48 ` [LTP] [PATCH 2/2] fallocate02: " Andrea Cervesato
1 sibling, 1 reply; 4+ messages in thread
From: Andrea Cervesato @ 2026-07-20 11:48 UTC (permalink / raw)
To: Linux Test Project
From: Andrea Cervesato <andrea.cervesato@suse.com>
Convert the fallocate01 test case from the legacy LTP API (test.h) to the
new tst_test API using a table-driven struct tcase[] and TST_EXP_* macros.
Preserve both scenarios (DEFAULT mode and FALLOC_FL_KEEP_SIZE) and all
oracles: the fallocate return code, the per-mode st_size side effect that
distinguishes the two modes (13 vs 12 blocks), the relative-seek position
check, and the write into the freshly allocated region. Map EOPNOTSUPP and
ENOSYS to TCONF for filesystems that do not support fallocate.
Reset the backing file to its pristine 12-block state at the start of each
run so the per-mode size assertions stay correct under -i, fixing a latent
bug where the legacy test silently failed on iterations after the first.
Derive the block size from st_blksize and rely on framework .needs_tmpdir
instead of manual tmpdir handling.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/syscalls/fallocate/fallocate01.c | 337 ++++++----------------
1 file changed, 96 insertions(+), 241 deletions(-)
diff --git a/testcases/kernel/syscalls/fallocate/fallocate01.c b/testcases/kernel/syscalls/fallocate/fallocate01.c
index d21936ebaa125fd1d842c5e606f6c9a22b6967da..d859a0b47dd48abdcb55530729f86e92cd71fcc6 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate01.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate01.c
@@ -1,274 +1,129 @@
-/******************************************************************************
- * fallocate01.c
- * Mon Dec 24 2007
- * Copyright (c) International Business Machines Corp., 2007
- * Emali : sharyathi@in.ibm.com
- ******************************************************************************/
-
-/***************************************************************************
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-***************************************************************************/
-
-/*****************************************************************************
- *
- * OS Test - International Business Machines Corp. 2007.
- *
- * TEST IDENTIFIER : fallocate01
- *
- * EXECUTED BY : anyone
- *
- * TEST TITLE : Basic test for fallocate()
- *
- * TEST CASE TOTAL : 2
- *
- * CPU ARCHITECTURES : PPC,X86, X86_64
- *
- * AUTHOR : Sharyathi Nagesh
- *
- * CO-PILOT :
- *
- * DATE STARTED : 24/12/2007
- *
- * TEST CASES
- * (Working of fallocate under 2 modes)
- * 1) DEFAULT 2)FALLOC_FL_KEEP_SIZE
- *
- * INPUT SPECIFICATIONS
- * No input needs to be specified
- * fallocate() in puts are generated randomly
- *
- * OUTPUT SPECIFICATIONS
- * Output describing whether test cases passed or failed.
- *
- * ENVIRONMENTAL NEEDS
- * Test Needs to be executed on file system supporting ext4
- * LTP {TMP} Needs to be set to such a folder
- *
- * SPECIAL PROCEDURAL REQUIREMENTS
- * None
- *
- * DETAILED DESCRIPTION
- * This is a test case for fallocate() system call.
- * This test suite tests basic working of fallocate under different modes
- * It trys to fallocate memory blocks and write into that block
- *
- * Total 2 Test Cases :-
- * (1) Test Case for DEFAULT MODE
- * (2) Test Case for FALLOC_FL_KEEP_SIZE
- *
- * Setup:
- * Setup file on which fallocate is to be called
- * Set up 2 files for each mode
- *
- * Test:
- * Loop if the proper options are given.
- * Execute system call
- * Check return code, if system call did fail
- * lseek to some random location with in allocate block
- * write data into the locattion Report if any error encountered
- * PASS the test otherwise
- *
- * Cleanup:
- * Cleanup the temporary folder
- *
-*************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2007
+ * Author: Sharyathi Nagesh <sharyathi@in.ibm.com>
+ * Copyright (c) Linux Test Project, 2008-2024
+ */
+
+/*\
+ * Basic test for :manpage:`fallocate(2)` covering the two preallocation
+ * modes and their effect on the file size.
+ *
+ * A file is pre-populated to 12 blocks and a single extra block is
+ * preallocated past the end of the file. The test verifies that the
+ * resulting file size matches the mode semantics and that the newly
+ * allocated region is writable.
+ *
+ * [Algorithm]
+ *
+ * - Populate the working file with 12 blocks of block_size bytes.
+ * - Preallocate one block at the end of the file.
+ * - In DEFAULT_MODE the file grows to 13 blocks.
+ * - In FALLOC_FL_KEEP_SIZE mode the file size stays at 12 blocks.
+ * - Seek into the newly allocated region and write a byte to it.
+ */
#define _GNU_SOURCE
-#include <stdio.h>
-#include <stdlib.h>
-#include <endian.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/syscall.h>
-#include <unistd.h>
-#include <inttypes.h>
-#include <sys/utsname.h>
-
-#include "test.h"
-#include "tso_safe_macros.h"
+#include "tst_test.h"
#include "lapi/fallocate.h"
-#include "lapi/fcntl.h"
#define BLOCKS_WRITTEN 12
-void get_blocksize(int);
-void populate_files(int fd);
-void runtest(int, int, loff_t);
+static int fd = -1;
+static int block_size;
-char *TCID = "fallocate01";
-char fname_mode1[255], fname_mode2[255]; /* Files used for testing */
-int fd_mode1, fd_mode2;
-int TST_TOTAL = 2;
-loff_t block_size;
-int buf_size;
+static struct tcase {
+ int mode;
+ int expected_blocks;
+ const char *desc;
+} tcases[] = {
+ {0, BLOCKS_WRITTEN + 1, "DEFAULT_MODE"},
+ {FALLOC_FL_KEEP_SIZE, BLOCKS_WRITTEN, "FALLOC_FL_KEEP_SIZE"},
+};
-/******************************************************************************
- * Performs all one time clean up for this test on successful
- * completion, premature exit or failure. Closes all temporary
- * files, removes all temporary directories exits the test with
- * appropriate return code by calling tst_exit() function.
-******************************************************************************/
-void cleanup(void)
+static void populate_file(void)
{
+ char buf[block_size];
- if (close(fd_mode1) == -1)
- tst_resm(TWARN | TERRNO, "close(%s) failed", fname_mode1);
- if (close(fd_mode2) == -1)
- tst_resm(TWARN | TERRNO, "close(%s) failed", fname_mode2);
- tst_rmdir();
-}
-
-/*****************************************************************************
- * Performs all one time setup for this test. This function is
- * used to create temporary dirs and temporary files
- * that may be used in the course of this test
- ******************************************************************************/
-void setup(void)
-{
- /* Create temporary directories */
- TEST_PAUSE;
+ for (int blocks = 0; blocks < BLOCKS_WRITTEN; blocks++) {
+ for (int i = 0; i < block_size; i++)
+ buf[i] = 'A' + (i % 26);
- tst_tmpdir();
-
- sprintf(fname_mode1, "tfile_mode1_%d", getpid());
- fd_mode1 = SAFE_OPEN(cleanup, fname_mode1, O_RDWR | O_CREAT, 0700);
- get_blocksize(fd_mode1);
- populate_files(fd_mode1);
-
- sprintf(fname_mode2, "tfile_mode2_%d", getpid());
- fd_mode2 = SAFE_OPEN(cleanup, fname_mode2, O_RDWR | O_CREAT, 0700);
- populate_files(fd_mode2);
+ SAFE_WRITE(SAFE_WRITE_ALL, fd, buf, block_size);
+ }
}
-/*****************************************************************************
- * Gets the block size for the file system
- ******************************************************************************/
-void get_blocksize(int fd)
+static void setup(void)
{
+ char fname[NAME_MAX];
struct stat file_stat;
- if (fstat(fd, &file_stat) < 0)
- tst_resm(TFAIL | TERRNO,
- "fstat failed while getting block_size");
-
- block_size = file_stat.st_blksize;
- buf_size = block_size;
-}
-
-/*****************************************************************************
- * Writes data into the file
- ******************************************************************************/
-
-void populate_files(int fd)
-{
- char buf[buf_size + 1];
- int index;
- int blocks;
- int data;
+ snprintf(fname, sizeof(fname), "tfile_%d", getpid());
+ fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0700);
- for (blocks = 0; blocks < BLOCKS_WRITTEN; blocks++) {
- for (index = 0; index < buf_size; index++)
- buf[index] = 'A' + (index % 26);
- buf[buf_size] = '\0';
- if ((data = write(fd, buf, buf_size)) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "write failed");
- }
+ SAFE_FSTAT(fd, &file_stat);
+ block_size = (int)file_stat.st_blksize;
}
-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);
- 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);
}
- 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;
}
- //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,
+};
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [LTP] [PATCH 2/2] fallocate02: Convert to new API
2026-07-20 11:48 [LTP] [PATCH 0/2] Convert fallocate testing suite Andrea Cervesato
2026-07-20 11:48 ` [LTP] [PATCH 1/2] fallocate01: Convert to new API Andrea Cervesato
@ 2026-07-20 11:48 ` Andrea Cervesato
1 sibling, 0 replies; 4+ messages in thread
From: Andrea Cervesato @ 2026-07-20 11:48 UTC (permalink / raw)
To: Linux Test Project
From: Andrea Cervesato <andrea.cervesato@suse.com>
Convert the fallocate02 test case from the legacy LTP API (test.h) to the
new tst_test API using a table-driven struct tcase[] and TST_EXP_FAIL for
each error-path oracle.
Preserve every scenario and its exact errno (EBADF, EINVAL, EFBIG), the
64-bit-only guard around the EFBIG cases, the read-only fd that drives
EBADF, and the pre-population of the writable file. Map EOPNOTSUPP/ENOSYS
to TCONF via a support probe in setup(), and rely on framework
.needs_tmpdir instead of manual tmpdir handling.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/syscalls/fallocate/fallocate02.c | 193 +++++++---------------
1 file changed, 61 insertions(+), 132 deletions(-)
diff --git a/testcases/kernel/syscalls/fallocate/fallocate02.c b/testcases/kernel/syscalls/fallocate/fallocate02.c
index 4469f02f2c45604c4f0503f0e824dd37f371b245..d31d2a1e407c5a78ece134387cad7e065fce473b 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate02.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate02.c
@@ -1,164 +1,93 @@
-/******************************************************************************
- * Copyright (c) International Business Machines Corp., 2007
- * Author: Sharyathi Nagesh <sharyathi@in.ibm.com>
- ******************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2007
+ * Author: Sharyathi Nagesh <sharyathi@in.ibm.com>
+ */
-/***************************************************************************
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+/*\
+ * Verify that :manpage:`fallocate(2)` fails with the expected error codes:
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-***************************************************************************/
-
-/*
- * DESCRIPTION
- * check fallocate() with various error conditions that should produce
- * EBADF, EINVAL and EFBIG.
+ * - EBADF when the file descriptor is opened read-only.
+ * - EINVAL when the offset or length is negative, or the length is zero.
+ * - EFBIG when the requested range exceeds the maximum file size (only
+ * tested on 64-bit offset ABIs).
*/
#define _GNU_SOURCE
-#include <stdio.h>
-#include <stdlib.h>
-#include <endian.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <inttypes.h>
-#include <sys/utsname.h>
-#include <limits.h>
-
-#include "test.h"
-#include "tso_safe_macros.h"
+#include "tst_test.h"
#include "lapi/fallocate.h"
#include "lapi/abisize.h"
-#define BLOCKS_WRITTEN 12
-#ifdef TEST_DEFAULT
-# define DEFAULT_TEST_MODE 0
-#else
-# define DEFAULT_TEST_MODE 1
-#endif
-#define OFFSET 12
-#define FNAMER "test_file1"
-#define FNAMEW "test_file2"
-#define BLOCK_SIZE 1024
-#define MAX_FILESIZE (LLONG_MAX / 1024)
-
-static void setup(void);
-static void fallocate_verify(int);
-static void cleanup(void);
+#define BLOCKS_WRITTEN 12
+#define OFFSET 12
+#define FNAMER "test_file1"
+#define FNAMEW "test_file2"
+#define BLOCK_SIZE 1024
+#define MAX_FILESIZE (LLONG_MAX / BLOCK_SIZE)
-static int fdw;
-static int fdr;
+static int fdr = -1;
+static int fdw = -1;
-static struct test_data_t {
+static struct tcase {
int *fd;
- char *fname;
- int mode;
loff_t offset;
loff_t len;
- int error;
-} test_data[] = {
- {&fdr, FNAMER, DEFAULT_TEST_MODE, 0, 1, EBADF},
- {&fdw, FNAMEW, DEFAULT_TEST_MODE, -1, 1, EINVAL},
- {&fdw, FNAMEW, DEFAULT_TEST_MODE, 1, -1, EINVAL},
- {&fdw, FNAMEW, DEFAULT_TEST_MODE, BLOCKS_WRITTEN, 0, EINVAL},
- {&fdw, FNAMEW, DEFAULT_TEST_MODE, BLOCKS_WRITTEN, -1, EINVAL},
- {&fdw, FNAMEW, DEFAULT_TEST_MODE, -(BLOCKS_WRITTEN+OFFSET), 1, EINVAL},
+ int exp_errno;
+} tcases[] = {
+ {&fdr, 0, 1, EBADF},
+ {&fdw, -1, 1, EINVAL},
+ {&fdw, 1, -1, EINVAL},
+ {&fdw, BLOCKS_WRITTEN, 0, EINVAL},
+ {&fdw, BLOCKS_WRITTEN, -1, EINVAL},
+ {&fdw, -(BLOCKS_WRITTEN + OFFSET), 1, EINVAL},
#if defined(TST_ABI64) || _FILE_OFFSET_BITS == 64
- {&fdw, FNAMEW, DEFAULT_TEST_MODE, MAX_FILESIZE, 1, EFBIG},
- {&fdw, FNAMEW, DEFAULT_TEST_MODE, 1, MAX_FILESIZE, EFBIG},
+ {&fdw, MAX_FILESIZE, 1, EFBIG},
+ {&fdw, 1, MAX_FILESIZE, EFBIG},
#endif
};
-TCID_DEFINE(fallocate02);
-int TST_TOTAL = ARRAY_SIZE(test_data);
-
-int main(int ac, char **av)
-{
- int lc;
- int i;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
-
- tst_count = 0;
-
- for (i = 0; i < TST_TOTAL; i++)
- fallocate_verify(i);
- }
-
- cleanup();
-
- tst_exit();
-}
-
static void setup(void)
{
+ char buf[BLOCK_SIZE];
int i;
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
-
- tst_tmpdir();
-
- fdr = SAFE_OPEN(cleanup, FNAMER, O_RDONLY | O_CREAT, S_IRUSR);
+ fdr = SAFE_OPEN(FNAMER, O_RDONLY | O_CREAT, 0400);
+ fdw = SAFE_OPEN(FNAMEW, O_RDWR | O_CREAT, 0700);
- fdw = SAFE_OPEN(cleanup, FNAMEW, O_RDWR | O_CREAT, S_IRWXU);
-
- char buf[BLOCK_SIZE];
memset(buf, 'A', BLOCK_SIZE);
for (i = 0; i < BLOCKS_WRITTEN; i++)
- SAFE_WRITE(cleanup, SAFE_WRITE_ALL, fdw, buf, BLOCK_SIZE);
-}
+ SAFE_WRITE(SAFE_WRITE_ALL, fdw, buf, BLOCK_SIZE);
-static void fallocate_verify(int i)
-{
- TEST(fallocate(*test_data[i].fd, test_data[i].mode,
- test_data[i].offset * BLOCK_SIZE,
- test_data[i].len * BLOCK_SIZE));
- if (TEST_ERRNO != test_data[i].error) {
- if (TEST_ERRNO == EOPNOTSUPP ||
- TEST_ERRNO == ENOSYS) {
- tst_brkm(TCONF, cleanup,
- "fallocate system call is not implemented");
- }
- tst_resm(TFAIL | TTERRNO,
- "fallocate(%s:%d, %d, %" PRId64 ", %" PRId64 ") "
- "failed, expected errno:%d", test_data[i].fname,
- *test_data[i].fd, test_data[i].mode,
- test_data[i].offset * BLOCK_SIZE,
- test_data[i].len * BLOCK_SIZE, test_data[i].error);
- } else {
- tst_resm(TPASS | TTERRNO,
- "fallocate(%s:%d, %d, %" PRId64 ", %" PRId64 ") "
- "returned %d", test_data[i].fname, *test_data[i].fd,
- test_data[i].mode, test_data[i].offset * BLOCK_SIZE,
- test_data[i].len * BLOCK_SIZE, TEST_ERRNO);
- }
+ TEST(fallocate(fdw, FALLOC_FL_KEEP_SIZE, 0, BLOCK_SIZE));
+ if (TST_RET == -1 && (TST_ERR == EOPNOTSUPP || TST_ERR == ENOSYS))
+ tst_brk(TCONF, "fallocate() not supported");
}
static void cleanup(void)
{
- if (fdw > 0)
- SAFE_CLOSE(NULL, fdw);
- if (fdr > 0)
- SAFE_CLOSE(NULL, fdr);
+ if (fdw != -1)
+ SAFE_CLOSE(fdw);
+ if (fdr != -1)
+ SAFE_CLOSE(fdr);
+}
- tst_rmdir();
+static void verify_fallocate(unsigned int n)
+{
+ struct tcase *tc = &tcases[n];
+
+ TST_EXP_FAIL(fallocate(*tc->fd, FALLOC_FL_KEEP_SIZE,
+ tc->offset * BLOCK_SIZE,
+ tc->len * BLOCK_SIZE), tc->exp_errno,
+ "fallocate(%d, %lld, %lld)", *tc->fd,
+ (long long)(tc->offset * BLOCK_SIZE),
+ (long long)(tc->len * BLOCK_SIZE));
}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .test = verify_fallocate,
+ .tcnt = ARRAY_SIZE(tcases),
+ .needs_tmpdir = 1,
+};
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [LTP] fallocate01: Convert to new API
2026-07-20 11:48 ` [LTP] [PATCH 1/2] fallocate01: Convert to new API Andrea Cervesato
@ 2026-07-20 13:16 ` linuxtestproject.agent
0 siblings, 0 replies; 4+ messages in thread
From: linuxtestproject.agent @ 2026-07-20 13:16 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi Andrea,
On Mon, 20 Jul 2026 13:48:26 +0200, Andrea Cervesato wrote:
> fallocate01: Convert to new API
--- [PATCH 1/2] ---
> +static void setup(void)
> +{
> + char fname[NAME_MAX];
> + struct stat file_stat;
> +
> + snprintf(fname, sizeof(fname), "tfile_%d", getpid());
The filename buffer is one byte short. Per the LTP coding standard
(c-tests.md, "Path Buffers" section), a buffer holding only a filename
component must be NAME_MAX + 1 bytes to accommodate the null terminator
when the filename is exactly NAME_MAX characters long.
In this specific case the generated name is at most ~29 bytes and there
is no actual overflow, but the declaration should still read:
char fname[NAME_MAX + 1];
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-20 13:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20 11:48 [LTP] [PATCH 0/2] Convert fallocate testing suite Andrea Cervesato
2026-07-20 11:48 ` [LTP] [PATCH 1/2] fallocate01: Convert to new API Andrea Cervesato
2026-07-20 13:16 ` [LTP] " linuxtestproject.agent
2026-07-20 11:48 ` [LTP] [PATCH 2/2] fallocate02: " Andrea Cervesato
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.