Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AC110C5DF97 for ; Wed, 26 Aug 2026 13:35:42 +0000 (UTC) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 02D483C2603 for ; Wed, 26 Aug 2026 15:35:41 +0200 (CEST) Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 428873CD74E for ; Wed, 26 Aug 2026 15:35:04 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id BD3C61400338 for ; Wed, 26 Aug 2026 15:35:03 +0200 (CEST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4B647874D8; Wed, 26 Aug 2026 13:34:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787751298; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0kM5jVg4tn4y4rQSzCYuktRlGvQfC0PHUCgV9N5tg6U=; b=HwGRDVgN+PBMdNCGrU6Z+CZrCE2ze5u1VLt13mKncTPL+7oTNpjXa6rS870XMw6jaZuVlN Dvf4MGtAqpkl2jOfm/vOkzPaxWQgF7em/bMDGbW/tNq1cMVmKVcvjz6gYxiOBbFJ79a15+ TCbWVjR1jxWbpf8F5IFcVC6wkbdB5EM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787751298; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0kM5jVg4tn4y4rQSzCYuktRlGvQfC0PHUCgV9N5tg6U=; b=TZkbEJoLx9YEaB0jT4pAF/h7NP9jO1ShBz1eN8/uxyyBqQ/poaUKoemdarRGXWBj++EHMu rQSBG0esgovOZlAg== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=MITTwHDr; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="LeLaSG/m" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1787751294; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0kM5jVg4tn4y4rQSzCYuktRlGvQfC0PHUCgV9N5tg6U=; b=MITTwHDrLG/DfSrrsPX/HOKLmT+agGOKk5T74m1gbMW+cNSkqJ4PKEmwXsEvB8cSnL2EDO VXpa5nKaEd6bqrGxRQuWTWdXWVkxcfIwuiRd/B7t0lv/BmBXjg5wMuDiu8y7uLBGRv8zPC Wn2wvz8T4R7lCNElLc3P3hD/ZNi3dIw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1787751294; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0kM5jVg4tn4y4rQSzCYuktRlGvQfC0PHUCgV9N5tg6U=; b=LeLaSG/mOdbMYM0GMT5y9YzoxoRRho2zcstGVWzu42TpHGSSlVd1qfmBVDafX8nm1qvvfn Cx/6Dbo+BPYOmoDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2DEFF1364A; Wed, 26 Aug 2026 13:34:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id sGa8CX7rjmqmbQAAD6G6ig (envelope-from ); Wed, 26 Aug 2026 13:34:54 +0000 From: Andrea Cervesato Date: Wed, 26 Aug 2026 15:34:54 +0200 MIME-Version: 1.0 Message-Id: <20260826-convert_fallocate_suite-v3-2-1286ede0493d@suse.com> References: <20260826-convert_fallocate_suite-v3-0-1286ede0493d@suse.com> In-Reply-To: <20260826-convert_fallocate_suite-v3-0-1286ede0493d@suse.com> To: Linux Test Project X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1787751293; l=7477; i=andrea.cervesato@suse.com; s=20251210; h=from:subject:message-id; bh=2TxBtijFudxU8bLggcCxHMTZUkd6vfmPeJe4jXoOIKk=; b=OZx4SBvO5ehfVw0wTVUBxToNG+k8QU9YYhFQ0GLAjXyouNel+9cCXXHz+MwbuDeTvgX8xTR5n OZdS33xaaepD92reyWpcsPzFN+zIgqAzlX346ehItkP8vrefG5L7EVg X-Developer-Key: i=andrea.cervesato@suse.com; a=ed25519; pk=zKY+6GCauOiuHNZ//d8PQ/UL4jFCTKbXrzXAOQSLevI= X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCPT_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; TO_DN_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid,suse.com:email,suse.de:dkim,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Queue-Id: 4B647874D8 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Virus-Scanned: clamav-milter 1.0.9 at in-6.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v3 2/2] fallocate02: Convert to new API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ltp-bounces+ltp=archiver.kernel.org@lists.linux.it Sender: "ltp" From: Andrea Cervesato 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. Signed-off-by: Andrea Cervesato --- testcases/kernel/syscalls/fallocate/fallocate02.c | 192 +++++++--------------- 1 file changed, 61 insertions(+), 131 deletions(-) diff --git a/testcases/kernel/syscalls/fallocate/fallocate02.c b/testcases/kernel/syscalls/fallocate/fallocate02.c index 4469f02f2..0a25a5611 100644 --- a/testcases/kernel/syscalls/fallocate/fallocate02.c +++ b/testcases/kernel/syscalls/fallocate/fallocate02.c @@ -1,164 +1,94 @@ -/****************************************************************************** - * Copyright (c) International Business Machines Corp., 2007 - * Author: Sharyathi Nagesh - ******************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) International Business Machines Corp., 2007 + * Author: Sharyathi Nagesh + * Copyright (c) Linux Test Project, 2026 + */ -/*************************************************************************** - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#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(); + TEST(fallocate(-1, 0, 0, 0)); + if (TST_ERR == EOPNOTSUPP || TST_ERR == ENOSYS) + tst_brk(TCONF, "fallocate() not supported"); - 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) +static void cleanup(void) { - 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); - } + if (fdw != -1) + SAFE_CLOSE(fdw); + if (fdr != -1) + SAFE_CLOSE(fdr); } -static void cleanup(void) +static void verify_fallocate(unsigned int n) { - if (fdw > 0) - SAFE_CLOSE(NULL, fdw); - if (fdr > 0) - SAFE_CLOSE(NULL, fdr); - - tst_rmdir(); + 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