diff mbox series

fs/lftest: Convert to new library

Message ID 20201215092534.757347-1-lkml@jv-coder.de
State Accepted
Headers show
Series fs/lftest: Convert to new library | expand

Commit Message

Joerg Vehlow Dec. 15, 2020, 9:25 a.m. UTC
From: Joerg Vehlow <joerg.vehlow@aox-tech.de>

Additonal changes:
 - Use temp directory instead of working dir
 - 100 buffers is teh default  now and can be changed using -n
 - Removed some useless output (nseek, nwrite was always bufnum)

Signed-off-by: Joerg Vehlow <joerg.vehlow@aox-tech.de>
---
 runtest/fs                          |   2 +-
 testcases/kernel/fs/lftest/lftest.c | 111 ++++++++++++----------------
 2 files changed, 49 insertions(+), 64 deletions(-)

Comments

Petr Vorel Jan. 19, 2021, 11:01 a.m. UTC | #1
Hi Joerg,

> Additonal changes:
>  - Use temp directory instead of working dir
>  - 100 buffers is teh default  now and can be changed using -n
>  - Removed some useless output (nseek, nwrite was always bufnum)

Reviewed-by: Petr Vorel <pvorel@suse.cz>

LGTM, going to merge it after Jan 2021 release.

Below are 2 tiny details I'll fix during merge.

...
> +++ b/runtest/fs
> @@ -58,7 +58,7 @@ ftest06 ftest06
>  ftest07 ftest07
>  ftest08 ftest08

> -lftest01	lftest 100
> +lftest01	lftest

Not sure if anybody uses runtest/fs_readonly, but we still haven't removed it.
Thus it must be also updated:

-test_robind54 test_robind.sh -c "lftest 80"
+test_robind54 test_robind.sh -c "lftest"

...
> +++ b/testcases/kernel/fs/lftest/lftest.c
...
> +	if (str_bufnum) {
> +		if (tst_parse_int(str_bufnum ,&bufnum, 0, INT_MAX)) {
nit: formatting:
		if (tst_parse_int(str_bufnum, &bufnum, 0, INT_MAX)) {

> +			tst_brk(TBROK, "Invalid buffer count '%s'", str_bufnum);
> +		}

Kind regards,
Petr
Joerg Vehlow Jan. 20, 2021, 5:30 a.m. UTC | #2
Hi Petr,

On 1/19/2021 12:01 PM, Petr Vorel wrote:
> Not sure if anybody uses runtest/fs_readonly, but we still haven't 
> removed it.
> Thus it must be also updated:
>
> -test_robind54 test_robind.sh -c "lftest 80"
> +test_robind54 test_robind.sh -c "lftest"
Oh did not see that...
The default parameter to lftest is now 100, so this should probably be
+test_robind54 test_robind.sh -c "lftest -n 80
Don't know if it is important

Jörg
Petr Vorel Jan. 21, 2021, 2:44 p.m. UTC | #3
Hi Jörg,

> Hi Petr,

> On 1/19/2021 12:01 PM, Petr Vorel wrote:
> > Not sure if anybody uses runtest/fs_readonly, but we still haven't
> > removed it.
> > Thus it must be also updated:

> > -test_robind54 test_robind.sh -c "lftest 80"
> > +test_robind54 test_robind.sh -c "lftest"
> Oh did not see that...
No big deal, these duplicities in runtest files are always confusing.
Looking forward a day when we replace runtest files with something better.

> The default parameter to lftest is now 100, so this should probably be
> +test_robind54 test_robind.sh -c "lftest -n 80
Correct.
> Don't know if it is important

No, it's probably not important, but merged with this change anyway.

> Jörg

Kind regards,
Petr
diff mbox series

Patch

diff --git a/runtest/fs b/runtest/fs
index 5892e9fda..17b1415eb 100644
--- a/runtest/fs
+++ b/runtest/fs
@@ -58,7 +58,7 @@  ftest06 ftest06
 ftest07 ftest07
 ftest08 ftest08
 
-lftest01	lftest 100
+lftest01	lftest
 writetest01	writetest
 
 #Also run the fs_di (Data Integrity tests)
diff --git a/testcases/kernel/fs/lftest/lftest.c b/testcases/kernel/fs/lftest/lftest.c
index 9439b4cf0..7ce7df84a 100644
--- a/testcases/kernel/fs/lftest/lftest.c
+++ b/testcases/kernel/fs/lftest/lftest.c
@@ -1,31 +1,12 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) 2001, International Business Machines  Corp.
+ * Copyright (c) 2020, Joerg Vehlow <joerg.vehlow@aox-tech.de>
  *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   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, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- *  FILE        : lftest.c
- *  DESCRIPTION : The purpose of this test is to verify the file size limitations of a filesystem.
- *                It writes one buffer at a time and lseeks from the beginning of the file to the
- *                end of the last write position.  The intent is to test lseek64.
- *  HISTORY:
- *           06/19/01  :  Written by Jeff Martin(martinjn@us.ibm.com) to test large files on jfs.
- *           07/12/01  :  Added timing.
- *
+ * The purpose of this test is to verify the file size limitations
+ * of a filesystem. It writes one buffer at a time and lseeks from
+ * the beginning of the file to the end of the last write position.
+ * The intent is to test lseek64.
  */
 
 #include <stdio.h>
@@ -36,59 +17,63 @@ 
 #include <fcntl.h>
 #include <time.h>
 
-/* set write buffer size to whatever floats your boat.  I usually use 1M */
-#define BSIZE 1048576L
-char buf[BSIZE];
+#include "tst_test.h"
 
-int main(int argc, char *argv[])
-{
-	off_t i;
-	long bufnum;
-	off_t fd;
-	time_t time1, time2;
-	int writecnt = 0, seekcnt = 0, diff;
+static char *str_bufnum;
+static int bufnum = 100;
+static char buf[TST_MB];
 
-	time1 = time(NULL);
+static void setup(void)
+{
+	unsigned int i;
 
-	if (argc != 2 || atoi(argv[1]) < 1) {
-		printf("usage:<# of %ld buffers to write>\n", BSIZE);
-		exit(3);
+	if (str_bufnum) {
+		if (tst_parse_int(str_bufnum ,&bufnum, 0, INT_MAX)) {
+			tst_brk(TBROK, "Invalid buffer count '%s'", str_bufnum);
+		}
 	}
-	bufnum = strtol(argv[1], NULL, 0);
-	printf("Started building a %lu megabyte file @ %s\n", bufnum,
-	       asctime(localtime(&time1)));
 
 	buf[0] = 'A';
-	for (i = 1; i < BSIZE; i++)
+	for (i = 1; i < ARRAY_SIZE(buf) - 1; i++)
 		buf[i] = '0';
-	buf[BSIZE - 1] = 'Z';
+	buf[ARRAY_SIZE(buf) - 1] = 'Z';
+}
+
+static void run(void)
+{
+	time_t time1, time2;
+	int i, fd, diff;
+
+	time1 = time(NULL);
+	tst_res(TINFO, "Started building a %d megabyte file", bufnum);
 
 	if ((fd = creat("large_file", 0755)) == -1)
-		perror("lftest: ");
+		tst_brk(TBROK | TERRNO, "creat failed");
 
 	for (i = 0; i < bufnum; i++) {
-		if (write(fd, buf, BSIZE) == -1)
-			return -1;
-		else {
-			printf(".");
-			writecnt++;
-			fflush(stdout);
+		if (write(fd, buf, sizeof(buf)) == -1) {
+			tst_brk(TFAIL | TERRNO, "write failed");
 		}
 		fsync(fd);
-		if (lseek(fd, (i + 1) * BSIZE, 0) == -1)
-			return -1;
-		else
-			seekcnt++;
+		if (lseek(fd, (i + 1) * sizeof(buf), 0) == -1)
+			tst_brk(TFAIL | TERRNO, "lseek failed");
 	}
 	close(fd);
 	time2 = time(NULL);
-	printf("\nFinished building a %lu megabyte file @ %s\n", bufnum,
-	       asctime(localtime(&time2)));
+	tst_res(TINFO, "Finished building a %d megabyte file", bufnum);
 	diff = time2 - time1;
-	printf("Number of Writes: %d\n"
-	       "Number of Seeks: %d\n"
-	       "Total time for test to run: %d minute(s) and %d seconds\n",
-	       writecnt, seekcnt, diff / 60, diff % 60);
+	tst_res(TINFO, "Total time for test to run: %d minute(s) and %d seconds",
+	        diff / 60, diff % 60);
 
-	return 0;
+	tst_res(TPASS, "Test successfull");
 }
+
+static struct tst_test test = {
+	.options = (struct tst_option[]) {
+		{"n:", &str_bufnum, "-n COUNT Number of megabytes to write (default 100)"},
+		{}
+	},
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.test_all = run
+};
\ No newline at end of file