-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional changes: - Use temp directory instead of working dir - 100 buffers is the default now and can be changed using -n - Removed some useless output (nseek, nwrite was always bufnum) Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Joerg Vehlow <[email protected]>
- Loading branch information
Showing
3 changed files
with
50 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,12 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Copyright (c) 2001, International Business Machines Corp. | ||
* Copyright (c) 2020, Joerg Vehlow <[email protected]> | ||
* | ||
* 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([email protected]) 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 | ||
}; |