From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 08/15] syscalls/fallocate04: Convert to the new library
Date: Tue, 10 Oct 2017 14:31:58 +0200 [thread overview]
Message-ID: <20171010123205.20147-8-chrubis@suse.cz> (raw)
In-Reply-To: <20171010123205.20147-1-chrubis@suse.cz>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/syscalls/fallocate/fallocate04.c | 169 ++++++++++------------
1 file changed, 77 insertions(+), 92 deletions(-)
diff --git a/testcases/kernel/syscalls/fallocate/fallocate04.c b/testcases/kernel/syscalls/fallocate/fallocate04.c
index a6729161c..4916c8b47 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate04.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate04.c
@@ -30,13 +30,9 @@
#include <fcntl.h>
#include <unistd.h>
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
#include "lapi/fallocate.h"
-char *TCID = "fallocate04";
-int TST_TOTAL = 5;
-
static int fd;
static const char fname[] = "fallocate04.txt";
static size_t block_size;
@@ -44,28 +40,18 @@ static size_t buf_size;
#define NUM_OF_BLOCKS 3
-static int verbose;
-static const option_t options[] = {
- {"v", &verbose, NULL},
- {NULL, NULL, NULL}
-};
-
-static void help(void)
-{
- printf(" -v Verbose\n");
-}
+static char *verbose;
static void cleanup(void)
{
- close(fd);
- tst_rmdir();
+ SAFE_CLOSE(fd);
}
static void get_blocksize(void)
{
struct stat file_stat;
- SAFE_FSTAT(cleanup, fd, &file_stat);
+ SAFE_FSTAT(fd, &file_stat);
block_size = file_stat.st_blksize;
buf_size = NUM_OF_BLOCKS * block_size;
@@ -77,7 +63,7 @@ static size_t get_allocsize(void)
fsync(fd);
- SAFE_FSTAT(cleanup, fd, &file_stat);
+ SAFE_FSTAT(fd, &file_stat);
return file_stat.st_blocks * 512;
}
@@ -93,9 +79,7 @@ static void fill_tst_buf(char buf[])
static void setup(void)
{
- tst_tmpdir();
-
- fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0700);
+ fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0700);
get_blocksize();
}
@@ -104,86 +88,86 @@ static void check_file_data(const char exp_buf[], size_t size)
{
char rbuf[size];
- tst_resm(TINFO, "reading the file, compare with expected buffer");
+ tst_res(TINFO, "reading the file, compare with expected buffer");
- SAFE_LSEEK(cleanup, fd, 0, SEEK_SET);
- SAFE_READ(cleanup, 1, fd, rbuf, size);
+ SAFE_LSEEK(fd, 0, SEEK_SET);
+ SAFE_READ(1, fd, rbuf, size);
if (memcmp(exp_buf, rbuf, size)) {
if (verbose) {
- tst_resm_hexd(TINFO, exp_buf, size, "expected:");
- tst_resm_hexd(TINFO, rbuf, size, "but read:");
+ tst_res_hexd(TINFO, exp_buf, size, "expected:");
+ tst_res_hexd(TINFO, rbuf, size, "but read:");
}
- tst_brkm(TFAIL, cleanup, "not expected file data");
+ tst_brk(TFAIL, "not expected file data");
}
}
static void test01(void)
{
- tst_resm(TINFO, "allocate '%zu' bytes", buf_size);
+ tst_res(TINFO, "allocate '%zu' bytes", buf_size);
if (fallocate(fd, 0, 0, buf_size) == -1) {
if (errno == ENOSYS || errno == EOPNOTSUPP)
- tst_brkm(TCONF, cleanup, "fallocate() not supported");
- tst_brkm(TFAIL | TERRNO, cleanup, "fallocate() failed");
+ tst_brk(TCONF, "fallocate() not supported");
+ tst_brk(TFAIL | TERRNO, "fallocate() failed");
}
char buf[buf_size];
fill_tst_buf(buf);
- SAFE_WRITE(cleanup, 1, fd, buf, buf_size);
+ SAFE_WRITE(1, fd, buf, buf_size);
- tst_resm(TPASS, "test-case succeeded");
+ tst_res(TPASS, "test-case succeeded");
}
static void test02(void)
{
size_t alloc_size0 = get_allocsize();
- tst_resm(TINFO, "read allocated file size '%zu'", alloc_size0);
- tst_resm(TINFO, "make a hole with FALLOC_FL_PUNCH_HOLE");
+ tst_res(TINFO, "read allocated file size '%zu'", alloc_size0);
+ tst_res(TINFO, "make a hole with FALLOC_FL_PUNCH_HOLE");
if (tst_kvercmp(2, 6, 38) < 0) {
- tst_brkm(TCONF, cleanup,
- "FALLOC_FL_PUNCH_HOLE needs Linux 2.6.38 or newer");
+ tst_brk(TCONF,
+ "FALLOC_FL_PUNCH_HOLE needs Linux 2.6.38 or newer");
}
if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
block_size, block_size) == -1) {
if (errno == EOPNOTSUPP) {
- tst_brkm(TCONF, cleanup,
- "FALLOC_FL_PUNCH_HOLE not supported");
+ tst_brk(TCONF,
+ "FALLOC_FL_PUNCH_HOLE not supported");
}
- tst_brkm(TFAIL | TERRNO, cleanup, "fallocate() failed");
+ tst_brk(TFAIL | TERRNO, "fallocate() failed");
}
- tst_resm(TINFO, "check that file has a hole with lseek(,,SEEK_HOLE)");
+ tst_res(TINFO, "check that file has a hole with lseek(,,SEEK_HOLE)");
off_t ret = lseek(fd, 0, SEEK_HOLE);
if (ret != (ssize_t)block_size) {
/* exclude error when kernel doesn't have SEEK_HOLE support */
if (errno != EINVAL) {
- tst_brkm(TFAIL | TERRNO, cleanup,
+ tst_brk(TFAIL | TERRNO,
"fallocate() or lseek() failed");
}
if (tst_kvercmp(3, 1, 0) < 0) {
- tst_resm(TINFO, "lseek() doesn't support SEEK_HOLE, "
+ tst_res(TINFO, "lseek() doesn't support SEEK_HOLE, "
"this is expected for < 3.1 kernels");
} else {
- tst_brkm(TBROK | TERRNO, cleanup,
+ tst_brk(TBROK | TERRNO,
"lseek() doesn't support SEEK_HOLE");
}
} else {
- tst_resm(TINFO, "found a hole at '%ld' offset", ret);
+ tst_res(TINFO, "found a hole@'%ld' offset", ret);
}
size_t alloc_size1 = get_allocsize();
- tst_resm(TINFO, "allocated file size before '%zu' and after '%zu'",
+ tst_res(TINFO, "allocated file size before '%zu' and after '%zu'",
alloc_size0, alloc_size1);
if ((alloc_size0 - block_size) != alloc_size1)
- tst_brkm(TFAIL, cleanup, "not expected allocated size");
+ tst_brk(TFAIL, "not expected allocated size");
char exp_buf[buf_size];
@@ -192,29 +176,29 @@ static void test02(void)
check_file_data(exp_buf, buf_size);
- tst_resm(TPASS, "test-case succeeded");
+ tst_res(TPASS, "test-case succeeded");
}
static void test03(void)
{
- tst_resm(TINFO, "zeroing file space with FALLOC_FL_ZERO_RANGE");
+ tst_res(TINFO, "zeroing file space with FALLOC_FL_ZERO_RANGE");
if (tst_kvercmp(3, 15, 0) < 0) {
- tst_brkm(TCONF, cleanup,
- "FALLOC_FL_ZERO_RANGE needs Linux 3.15 or newer");
+ tst_brk(TCONF,
+ "FALLOC_FL_ZERO_RANGE needs Linux 3.15 or newer");
}
size_t alloc_size0 = get_allocsize();
- tst_resm(TINFO, "read current allocated file size '%zu'", alloc_size0);
+ tst_res(TINFO, "read current allocated file size '%zu'", alloc_size0);
if (fallocate(fd, FALLOC_FL_ZERO_RANGE, block_size - 1,
block_size + 2) == -1) {
if (errno == EOPNOTSUPP) {
- tst_brkm(TCONF, cleanup,
- "FALLOC_FL_ZERO_RANGE not supported");
+ tst_brk(TCONF,
+ "FALLOC_FL_ZERO_RANGE not supported");
}
- tst_brkm(TFAIL | TERRNO, cleanup, "fallocate failed");
+ tst_brk(TFAIL | TERRNO, "fallocate failed");
}
/* The file hole in the specified range must be allocated and
@@ -222,10 +206,10 @@ static void test03(void)
*/
size_t alloc_size1 = get_allocsize();
- tst_resm(TINFO, "allocated file size before '%zu' and after '%zu'",
+ tst_res(TINFO, "allocated file size before '%zu' and after '%zu'",
alloc_size0, alloc_size1);
if ((alloc_size0 + block_size) != alloc_size1)
- tst_brkm(TFAIL, cleanup, "not expected allocated size");
+ tst_brk(TFAIL, "not expected allocated size");
char exp_buf[buf_size];
@@ -234,32 +218,32 @@ static void test03(void)
check_file_data(exp_buf, buf_size);
- tst_resm(TPASS, "test-case succeeded");
+ tst_res(TPASS, "test-case succeeded");
}
static void test04(void)
{
- tst_resm(TINFO, "collapsing file space with FALLOC_FL_COLLAPSE_RANGE");
+ tst_res(TINFO, "collapsing file space with FALLOC_FL_COLLAPSE_RANGE");
size_t alloc_size0 = get_allocsize();
- tst_resm(TINFO, "read current allocated file size '%zu'", alloc_size0);
+ tst_res(TINFO, "read current allocated file size '%zu'", alloc_size0);
if (fallocate(fd, FALLOC_FL_COLLAPSE_RANGE, block_size,
block_size) == -1) {
if (errno == EOPNOTSUPP) {
- tst_brkm(TCONF, cleanup,
- "FALLOC_FL_COLLAPSE_RANGE not supported");
+ tst_brk(TCONF,
+ "FALLOC_FL_COLLAPSE_RANGE not supported");
}
- tst_brkm(TFAIL | TERRNO, cleanup, "fallocate failed");
+ tst_brk(TFAIL | TERRNO, "fallocate failed");
}
size_t alloc_size1 = get_allocsize();
- tst_resm(TINFO, "allocated file size before '%zu' and after '%zu'",
+ tst_res(TINFO, "allocated file size before '%zu' and after '%zu'",
alloc_size0, alloc_size1);
if ((alloc_size0 - block_size) != alloc_size1)
- tst_brkm(TFAIL, cleanup, "not expected allocated size");
+ tst_brk(TFAIL, "not expected allocated size");
size_t size = buf_size - block_size;
char tmp_buf[buf_size];
@@ -274,36 +258,36 @@ static void test04(void)
exp_buf[block_size - 1] = exp_buf[block_size] = '\0';
check_file_data(exp_buf, size);
- tst_resm(TPASS, "test-case succeeded");
+ tst_res(TPASS, "test-case succeeded");
}
static void test05(void)
{
- tst_resm(TINFO, "inserting space with FALLOC_FL_INSERT_RANGE");
+ tst_res(TINFO, "inserting space with FALLOC_FL_INSERT_RANGE");
size_t alloc_size0 = get_allocsize();
- tst_resm(TINFO, "read current allocated file size '%zu'", alloc_size0);
+ tst_res(TINFO, "read current allocated file size '%zu'", alloc_size0);
if (fallocate(fd, FALLOC_FL_INSERT_RANGE, block_size,
block_size) == -1) {
if (errno == EOPNOTSUPP) {
- tst_brkm(TCONF, cleanup,
- "FALLOC_FL_INSERT_RANGE not supported");
+ tst_brk(TCONF,
+ "FALLOC_FL_INSERT_RANGE not supported");
}
- tst_brkm(TFAIL | TERRNO, cleanup, "fallocate failed");
+ tst_brk(TFAIL | TERRNO, "fallocate failed");
}
/* allocate space and ensure that it filled with zeroes */
if (fallocate(fd, FALLOC_FL_ZERO_RANGE, block_size, block_size) == -1)
- tst_brkm(TFAIL | TERRNO, cleanup, "fallocate failed");
+ tst_brk(TFAIL | TERRNO, "fallocate failed");
size_t alloc_size1 = get_allocsize();
- tst_resm(TINFO, "allocated file size before '%zu' and after '%zu'",
+ tst_res(TINFO, "allocated file size before '%zu' and after '%zu'",
alloc_size0, alloc_size1);
if ((alloc_size0 + block_size) != alloc_size1)
- tst_brkm(TFAIL, cleanup, "not expected allocated size");
+ tst_brk(TFAIL, "not expected allocated size");
char exp_buf[buf_size];
@@ -312,26 +296,27 @@ static void test05(void)
check_file_data(exp_buf, buf_size);
- tst_resm(TPASS, "test-case succeeded");
+ tst_res(TPASS, "test-case succeeded");
}
-int main(int argc, char *argv[])
+static void run(void)
{
- int lc;
-
- tst_parse_opts(argc, argv, options, help);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); ++lc) {
- test01();
- test02();
- test03();
- test04();
- test05();
- }
+ test01();
+ test02();
+ test03();
+ test04();
+ test05();
+}
- cleanup();
+static struct tst_option opts[] = {
+ {"v", &verbose, "-v Turns on verbose mode"},
+ {NULL, NULL, NULL}
+};
- tst_exit();
-}
+static struct tst_test test = {
+ .options = opts,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = run,
+ .needs_tmpdir = 1,
+};
--
2.13.5
next prev 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 ` [LTP] [PATCH v2 06/15] syscalls/fallocate05: New test Cyril Hrubis
2017-10-10 12:31 ` [LTP] [PATCH v2 07/15] syscalls/msync04: Run test for all filesystems Cyril Hrubis
2017-10-10 12:31 ` Cyril Hrubis [this message]
2017-10-10 12:31 ` [LTP] [PATCH v2 09/15] syscalls/fallocate04: " 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-8-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