Add simple lseek() test on a standard file. Standard it runs on the

/var/log/messages file wich is most likely not interesting but the
regression test can work on every specified filingsystem by passing a file
on that filingsystem to it as argument.

It tests:
- initial position
- seeking absolute position
- seeking end
- seeking negative relative position

more can be added later.
This commit is contained in:
reinoud 2006-09-21 01:27:32 +00:00
parent 1b78265f0e
commit a06f598ad6
3 changed files with 87 additions and 2 deletions

View File

@ -1,5 +1,5 @@
# $NetBSD: Makefile,v 1.5 2005/12/19 17:50:02 rpaulo Exp $
# $NetBSD: Makefile,v 1.6 2006/09/21 01:27:32 reinoud Exp $
SUBDIR= mkdir getdents posix_fadvise tmpfs
SUBDIR= mkdir getdents posix_fadvise tmpfs lseek
.include <bsd.subdir.mk>

View File

@ -0,0 +1,15 @@
# $NetBSD: Makefile,v 1.1 2006/09/21 01:27:32 reinoud Exp $
NOMAN= # defined
PROG= lseek
regress: ${PROG}
@set -e; \
if ./${PROG} /var/log/messages > /dev/null; then \
echo PASSED; exit 0; \
else \
echo FAILED; exit 1; \
fi
.include <bsd.prog.mk>

View File

@ -0,0 +1,70 @@
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/unistd.h>
int main(int argc, char **argv)
{
int fd;
off_t cur;
struct stat st;
int error;
if (argc != 2) {
printf("seektest filename\n");
return EXIT_FAILURE;
}
fd = open(argv[1], 0, O_RDONLY);
if (fd <= 0) {
printf("can't open `%s` : %s\n", argv[1], strerror(errno));
return EXIT_FAILURE;
}
error = fstat(fd, &st);
if (error) {
printf("can't stat file\n");
return EXIT_FAILURE;
}
if (st.st_size < 1500) {
printf("can't run this test on such a small file\n");
return EXIT_FAILURE;
}
printf("get initial position\n");
cur = lseek(fd, 0, SEEK_CUR);
printf("seek start %d\n", cur);
if (cur != 0) {
printf("seek initial position wrong\n");
return EXIT_FAILURE;
}
printf("seek set 1000\n");
cur = lseek(fd, 1000, SEEK_SET);
printf("seek now %d\n", cur);
if (cur != 1000) {
printf("seek 1000 went wrong\n");
return EXIT_FAILURE;
}
printf("seeking end (filesize = %d)\n", (uint32_t) st.st_size);
cur = lseek(fd, 0, SEEK_END);
printf("seek now %d\n", cur);
if (cur != st.st_size) {
printf("seek to the end went wrong\n");
return EXIT_FAILURE;
}
printf("seeking backwards filesize-150 steps\n");
cur = lseek(fd, -(st.st_size - 150), SEEK_CUR);
printf("seek now %d\n", cur);
if (cur != 150) {
printf("relative seek from end to 150 failed\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}