Linux Test Project
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 06/15] syscalls/fallocate05: New test
Date: Tue, 10 Oct 2017 14:31:56 +0200	[thread overview]
Message-ID: <20171010123205.20147-6-chrubis@suse.cz> (raw)
In-Reply-To: <20171010123205.20147-1-chrubis@suse.cz>

Tests that fallocate() works fine when filesystem is full.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 runtest/syscalls                                  |   1 +
 testcases/kernel/syscalls/.gitignore              |   1 +
 testcases/kernel/syscalls/fallocate/fallocate05.c | 104 ++++++++++++++++++++++
 3 files changed, 106 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fallocate/fallocate05.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 2362a231d..a31d15da6 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -160,6 +160,7 @@ fallocate01 fallocate01
 fallocate02 fallocate02
 fallocate03 fallocate03
 fallocate04 fallocate04
+fallocate05 fallocate05
 
 #posix_fadvise test cases
 posix_fadvise01                      posix_fadvise01
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 930f3f999..a91abd9f0 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -141,6 +141,7 @@
 /fallocate/fallocate02
 /fallocate/fallocate03
 /fallocate/fallocate04
+/fallocate/fallocate05
 /fchdir/fchdir01
 /fchdir/fchdir02
 /fchdir/fchdir03
diff --git a/testcases/kernel/syscalls/fallocate/fallocate05.c b/testcases/kernel/syscalls/fallocate/fallocate05.c
new file mode 100644
index 000000000..1fac26adb
--- /dev/null
+++ b/testcases/kernel/syscalls/fallocate/fallocate05.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Tests that writing to fallocated file works when filesystem is full.
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <fcntl.h>
+#include "tst_test.h"
+#include "lapi/fallocate.h"
+
+#define MNTPOINT "mntpoint"
+#define FALLOCATE_SIZE 8192
+
+static int fd;
+
+static void run(void)
+{
+	char buf[FALLOCATE_SIZE];
+	ssize_t ret;
+
+	fd = SAFE_OPEN(MNTPOINT "/test_file", O_WRONLY | O_CREAT);
+
+	if (fallocate(fd, 0, 0, FALLOCATE_SIZE)) {
+		if (errno == EOPNOTSUPP) {
+			tst_res(TCONF | TERRNO, "fallocate() not supported");
+			SAFE_CLOSE(fd);
+			return;
+		}
+
+		tst_brk(TBROK | TERRNO,
+			"fallocate(fd, 0, 0, %i)", FALLOCATE_SIZE);
+	}
+
+	tst_fill_fs(MNTPOINT, 1);
+
+	ret = write(fd, buf, sizeof(buf));
+
+	if (ret < 0)
+		tst_res(TFAIL | TERRNO, "write() failed unexpectedly");
+	else
+		tst_res(TPASS, "write() wrote %zu bytes", ret);
+
+	ret = fallocate(fd, 0, FALLOCATE_SIZE, FALLOCATE_SIZE);
+	if (ret != -1)
+		tst_brk(TFAIL, "fallocate() succeeded unexpectedly");
+
+	if (errno != ENOSPC)
+		tst_brk(TFAIL | TERRNO, "fallocate() should fail with ENOSPC");
+
+	tst_res(TPASS | TERRNO, "fallocate() on full FS");
+
+	ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE, 0, FALLOCATE_SIZE);
+	if (ret == -1) {
+		if (errno == EOPNOTSUPP)
+			tst_brk(TCONF, "fallocate(FALLOC_FL_PUNCH_HOLE)");
+
+		tst_brk(TBROK | TERRNO, "fallocate(FALLOC_FL_PUNCH_HOLE)");
+	}
+	tst_res(TPASS, "fallocate(FALLOC_FL_PUNCH_HOLE)");
+
+	ret = write(fd, buf, 10);
+	if (ret == -1)
+		tst_res(TFAIL | TERRNO, "write()");
+	else
+		tst_res(TPASS, "write()");
+
+	SAFE_CLOSE(fd);
+}
+
+static void cleanup(void)
+{
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.cleanup = cleanup,
+	.test_all = run,
+};
-- 
2.13.5


  parent reply	other threads:[~2017-10-10 12:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-10 12:31 [LTP] [PATCH v2 01/15] lib/tst_mkfs: Clear first 512k of the device Cyril Hrubis
2017-10-10 12:31 ` [LTP] [PATCH v2 02/15] lib: Add interface to list supported filesystems Cyril Hrubis
2017-10-10 12:31 ` [LTP] [PATCH v2 03/15] SAFE_MOUNT: Handle FUSE mounts as well Cyril Hrubis
2017-10-10 12:31 ` [LTP] [PATCH v2 04/15] lib/tst_test: Add .all_filesystems flag Cyril Hrubis
2017-10-11  8:42   ` Jan Stancek
2017-10-11  9:54     ` Cyril Hrubis
2017-10-11 10:38       ` Jan Stancek
2017-10-11 11:11         ` Cyril Hrubis
2017-10-11 11:17           ` Jan Stancek
2017-10-10 12:31 ` [LTP] [PATCH v2 05/15] lib/tst_fs: Add tst_fill_fs() Cyril Hrubis
2017-10-10 12:31 ` Cyril Hrubis [this message]
2017-10-10 12:31 ` [LTP] [PATCH v2 07/15] syscalls/msync04: Run test for all filesystems Cyril Hrubis
2017-10-10 12:31 ` [LTP] [PATCH v2 08/15] syscalls/fallocate04: Convert to the new library Cyril Hrubis
2017-10-10 12:31 ` [LTP] [PATCH v2 09/15] syscalls/fallocate04: Run test for all filesystems Cyril Hrubis
2017-10-10 12:32 ` [LTP] [PATCH v2 10/15] syscalls/setxattr01: Convert to the new library Cyril Hrubis
2017-10-10 12:32 ` [LTP] [PATCH v2 11/15] syscalls/setxattr01: Run test for all filesystems Cyril Hrubis
2017-10-10 12:32 ` [LTP] [PATCH v2 12/15] syscallse/setxattr02: Convert to the new library Cyril Hrubis
2017-10-10 12:32 ` [LTP] [PATCH v2 13/15] syscalls/fsync01: " Cyril Hrubis
2017-10-10 12:32 ` [LTP] [PATCH v2 14/15] syscalls/fsync01: Run test for all filesystems Cyril Hrubis
2017-10-10 12:32 ` [LTP] [PATCH v2 15/15] fs/fs_fill: Add a test to fill a FS in a few threads 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=20171010123205.20147-6-chrubis@suse.cz \
    --to=chrubis@suse.cz \
    --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