cthon: added patches for connectathon

patches apply on top of http://www.connectathon.org/nfstests.zip

Signed-off-by: Casey Bodley <cbodley@citi.umich.edu>
This commit is contained in:
Casey Bodley 2010-10-11 15:37:56 -04:00
parent 0ad4db4fad
commit 55ff9d855d
11 changed files with 1182 additions and 0 deletions

View file

@ -0,0 +1,120 @@
From 6fc1a22d9f13e3f5a0ce5357582c511e5810bd89 Mon Sep 17 00:00:00 2001
From: Casey Bodley <cbodley@citi.umich.edu>
Date: Mon, 11 Oct 2010 15:22:37 -0400
Subject: [PATCH 01/11] cthon: tests.init for linux
---
tests.init | 36 ++++++++++++++++++------------------
1 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/tests.init b/tests.init
index 69b51bf..e55a4aa 100644
--- a/tests.init
+++ b/tests.init
@@ -13,8 +13,8 @@ MNTPOINT="/mnt"
# Use this mount command if using:
# SVR4
# Solaris 2.x
-MOUNTCMD='./domount -F nfs -o $MNTOPTIONS $SERVER\:$SERVPATH $MNTPOINT'
-CFSMOUNTCMD='./domount -F cachefs -o $MNTOPTIONS $SERVER\:$SERVPATH $MNTPOINT'
+#MOUNTCMD='./domount -F nfs -o $MNTOPTIONS $SERVER\:$SERVPATH $MNTPOINT'
+#CFSMOUNTCMD='./domount -F cachefs -o $MNTOPTIONS $SERVER\:$SERVPATH $MNTPOINT'
# Use this mount command if using:
# BSD
@@ -26,22 +26,22 @@ CFSMOUNTCMD='./domount -F cachefs -o $MNTOPTIONS $SERVER\:$SERVPATH $MNTPOINT'
# Mac OS X
# At least some BSD systems don't recognize "hard" (since that's the
# default), so you might also want to use this definition of MNTOPTIONS.
-#MNTOPTIONS="rw,intr"
-#MOUNTCMD='./domount -o $MNTOPTIONS $SERVER\:$SERVPATH $MNTPOINT'
+MNTOPTIONS="rw,intr"
+MOUNTCMD='./domount -o $MNTOPTIONS $SERVER\:$SERVPATH $MNTPOINT'
# Use this mount command if using:
# DG/UX
#MOUNTCMD='./domount -t nfs -o $MNTOPTIONS $SERVER\:$SERVPATH $MNTPOINT'
-UMOUNTCMD='./domount -u $MNTPOINT'
+#UMOUNTCMD='./domount -u $MNTPOINT'
# Use the next two lines if using:
# SVR3
# SVR4
# Solaris 2.x
# HPUX
-DASHN=
-BLC=\\c
+#DASHN=
+#BLC=\\c
# Use the next two lines if using:
# BSD
@@ -49,12 +49,12 @@ BLC=\\c
# Linux
# Tru64 UNIX
# Mac OS X
-#DASHN=-n
-#BLC=
+DASHN=-n
+BLC=
# Use this path for:
# Solaris 2.x
-PATH=/opt/SUNWspro/bin:/usr/ccs/bin:/sbin:/bin:/usr/bin:/usr/ucb:/etc:.
+#PATH=/opt/SUNWspro/bin:/usr/ccs/bin:/sbin:/bin:/usr/bin:/usr/ucb:/etc:.
# Use this path for:
# Solaris 2.x with GCC
@@ -73,7 +73,7 @@ PATH=/opt/SUNWspro/bin:/usr/ccs/bin:/sbin:/bin:/usr/bin:/usr/ucb:/etc:.
# Tru64 UNIX
# SVR4
# Linux
-#PATH=/bin:/usr/bin:/usr/ucb:/usr/ccs/bin:/sbin:/usr/sbin:.
+PATH=/bin:/usr/bin:/usr/ucb:/usr/ccs/bin:/sbin:/usr/sbin:.
# Use this path for:
# DG/UX
@@ -130,12 +130,12 @@ LOCKTESTS=tlock
# Use with Solaris 2.x systems. Need the 5.0 C compiler (or later)
# for 64-bit mode.
-CC=/opt/SUNWspro/bin/cc
+#CC=/opt/SUNWspro/bin/cc
# Use this with GCC
#CC=/opt/gnu/bin/gcc
# Use this through Solaris 2.6. For Solaris 2.7 and later, use
# this for 32-bit mode applications.
-CFLAGS=`echo -DSVR4 -DMMAP -DSOLARIS2X -DSTDARG`
+#CFLAGS=`echo -DSVR4 -DMMAP -DSOLARIS2X -DSTDARG`
# Use this with gcc (32-bit binaries):
#CFLAGS=`echo -DSVR4 -DMMAP -DSOLARIS2X -DSTDARG -mcpu=ultrasparc`
# For Solaris 2.7 and later, use this for 64-bit mode applications
@@ -143,7 +143,7 @@ CFLAGS=`echo -DSVR4 -DMMAP -DSOLARIS2X -DSTDARG`
#CFLAGS=`echo -DSVR4 -DMMAP -DSOLARIS2X -DSTDARG -xO0 -xarch=v9 -dalign -Xt -L/usr/lib/sparcv9`
# Use this to make 64-bit binaries with gcc (3.1 or later; untested):
#CFLAGS=`echo -DSVR4 -DMMAP -DSOLARIS2X -DSTDARG -m64`
-LIBS=`echo -lsocket -lnsl`
+#LIBS=`echo -lsocket -lnsl`
# Use this through Solaris 2.5.1.
#LOCKTESTS=`echo tlock`
# Use with 2.6 and later systems, 32-bit mode.
@@ -204,11 +204,11 @@ LOCKTESTS=`echo tlocklfs tlock64`
#UMOUNT=/bin/umount
# Use with Linux 2.4 / GNU libc 2.2
-#CFLAGS=`echo -DLINUX -DGLIBC=22 -DMMAP -DSTDARG -fwritable-strings`
+CFLAGS=`echo -DLINUX -DGLIBC=22 -DMMAP -DSTDARG -fwritable-strings`
#LIBS=`echo -lnsl`
-#MOUNT=/bin/mount
-#UMOUNT=/bin/umount
-#LOCKTESTS=`echo tlocklfs tlock64`
+MOUNT=/bin/mount
+UMOUNT=/bin/umount
+LOCKTESTS=`echo tlocklfs tlock64`
# Use with Linux if your distro doesn't provide a "cc".
#CC=gcc
--
1.6.4.msysgit.0

View file

@ -0,0 +1,51 @@
From ea26a4a5e46428dae198d11c9e07c7ce0bbcee91 Mon Sep 17 00:00:00 2001
From: Casey Bodley <cbodley@citi.umich.edu>
Date: Mon, 11 Oct 2010 15:23:38 -0400
Subject: [PATCH 02/11] cthon: fixing tools compilation
---
tools/Makefile | 4 ++--
tools/dirprt.c | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/tools/Makefile b/tools/Makefile
index ce2cbc7..ce6019f 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -31,9 +31,9 @@ dirdmp: dirdmp.c
dirprt: dirprt.c
$(CC) $(CFLAGS) -o $@ $@.c $(LIBS)
pmaptst: pmaptst.c
- $(CC) $(CFLAGS) -o $@ $@.c $(LIBS)
+ $(CC) $(CFLAGS) -o $@ $@.c $(LIBS) -lrpc
pmapbrd: pmapbrd.c
- $(CC) $(CFLAGS) -o $@ $@.c $(LIBS)
+ $(CC) $(CFLAGS) -o $@ $@.c $(LIBS) -lrpc
lint:
lint $(CFLAGS) tcp.c
diff --git a/tools/dirprt.c b/tools/dirprt.c
index a8b50ea..6f1f4ff 100644
--- a/tools/dirprt.c
+++ b/tools/dirprt.c
@@ -70,13 +70,13 @@ print(dir)
}
while ((dp = readdir(dirp)) != NULL) {
#if defined(SVR3) || defined(SVR4) || defined(LINUX)
- printf("%5ld %5ld %5d %s\n", (long)telldir(dirp),
+ printf("%5ld %5ld %s\n", (long)telldir(dirp),
(long)dp->d_ino,
- dp->d_reclen, dp->d_name);
+ dp->d_name);
#else
- printf("%5ld %5d %5d %5d %s\n", (long)telldir(dirp),
+ printf("%5ld %5d %5d %s\n", (long)telldir(dirp),
dp->d_fileno,
- dp->d_reclen, dp->d_namlen, dp->d_name);
+ dp->d_namlen, dp->d_name);
#endif
}
closedir(dirp);
--
1.6.4.msysgit.0

View file

@ -0,0 +1,29 @@
From 97bc9d6416c65d7f41c43847f99ace92ac78254c Mon Sep 17 00:00:00 2001
From: Casey Bodley <cbodley@citi.umich.edu>
Date: Mon, 11 Oct 2010 15:23:53 -0400
Subject: [PATCH 03/11] cthon: fixing locks compilation problem
---
lock/tlock.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/lock/tlock.c b/lock/tlock.c
index 8a7d0cc..fe8c760 100644
--- a/lock/tlock.c
+++ b/lock/tlock.c
@@ -75,10 +75,12 @@
#include <inttypes.h>
#if defined(LARGE_LOCKS) && !defined(_LFS64_LARGEFILE) && !defined(MACOSX)
+/*
This machine cannot compile the 64 bit version of this test using the
LARGE_LOCKS symbol.
If your machine uses native 64-bit offsets, you should not define
LARGE_LOCKS.
+*/
#endif
#ifndef HZ
--
1.6.4.msysgit.0

View file

@ -0,0 +1,26 @@
From 8be0e35514ff0be2c0023065000ae80dbf312a8d Mon Sep 17 00:00:00 2001
From: Casey Bodley <cbodley@citi.umich.edu>
Date: Mon, 11 Oct 2010 15:24:10 -0400
Subject: [PATCH 04/11] cthon: removed -fwritable-strings from cflags
---
tests.init | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/tests.init b/tests.init
index e55a4aa..3a1ba74 100644
--- a/tests.init
+++ b/tests.init
@@ -204,7 +204,8 @@ LOCKTESTS=`echo tlocklfs tlock64`
#UMOUNT=/bin/umount
# Use with Linux 2.4 / GNU libc 2.2
-CFLAGS=`echo -DLINUX -DGLIBC=22 -DMMAP -DSTDARG -fwritable-strings`
+#CFLAGS=`echo -DLINUX -DGLIBC=22 -DMMAP -DSTDARG -fwritable-strings`
+CFLAGS=`echo -DLINUX -DGLIBC=22 -DMMAP -DSTDARG`
#LIBS=`echo -lnsl`
MOUNT=/bin/mount
UMOUNT=/bin/umount
--
1.6.4.msysgit.0

View file

@ -0,0 +1,169 @@
From c2e26900f6631eea3b5f7e09af30b68243339162 Mon Sep 17 00:00:00 2001
From: Casey Bodley <cbodley@citi.umich.edu>
Date: Mon, 11 Oct 2010 15:24:29 -0400
Subject: [PATCH 05/11] cthon: general scripts use .exe extension, dirent.h
large*.c files include <dirent.h> instead of <sys/dir.h>
---
general/large.c | 8 ++++----
general/large1.c | 8 ++++----
general/large2.c | 8 ++++----
general/large3.c | 8 ++++----
general/large4.sh | 2 +-
general/runtests.wrk | 14 +++++++-------
6 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/general/large.c b/general/large.c
index 5dd2950..1ae2e85 100644
--- a/general/large.c
+++ b/general/large.c
@@ -9,11 +9,11 @@
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
-#ifdef SVR4
+//#ifdef SVR4
#include <dirent.h>
-#else
-#include <sys/dir.h>
-#endif
+//#else
+//#include <sys/dir.h>
+//#endif
#undef MAXNAMLEN
#define MAXNAMLEN 256
diff --git a/general/large1.c b/general/large1.c
index 5dd2950..1ae2e85 100644
--- a/general/large1.c
+++ b/general/large1.c
@@ -9,11 +9,11 @@
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
-#ifdef SVR4
+//#ifdef SVR4
#include <dirent.h>
-#else
-#include <sys/dir.h>
-#endif
+//#else
+//#include <sys/dir.h>
+//#endif
#undef MAXNAMLEN
#define MAXNAMLEN 256
diff --git a/general/large2.c b/general/large2.c
index 5dd2950..1ae2e85 100644
--- a/general/large2.c
+++ b/general/large2.c
@@ -9,11 +9,11 @@
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
-#ifdef SVR4
+//#ifdef SVR4
#include <dirent.h>
-#else
-#include <sys/dir.h>
-#endif
+//#else
+//#include <sys/dir.h>
+//#endif
#undef MAXNAMLEN
#define MAXNAMLEN 256
diff --git a/general/large3.c b/general/large3.c
index 5dd2950..1ae2e85 100644
--- a/general/large3.c
+++ b/general/large3.c
@@ -9,11 +9,11 @@
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
-#ifdef SVR4
+//#ifdef SVR4
#include <dirent.h>
-#else
-#include <sys/dir.h>
-#endif
+//#else
+//#include <sys/dir.h>
+//#endif
#undef MAXNAMLEN
#define MAXNAMLEN 256
diff --git a/general/large4.sh b/general/large4.sh
index 7c3117f..954a23f 100644
--- a/general/large4.sh
+++ b/general/large4.sh
@@ -10,4 +10,4 @@ $CC $CFLAGS -o large1 large1.c&
$CC $CFLAGS -o large2 large2.c&
$CC $CFLAGS -o large3 large3.c&
wait
-rm large large1 large2 large3
+rm large.exe large1.exe large2.exe large3.exe
diff --git a/general/runtests.wrk b/general/runtests.wrk
index 5efc091..83f3124 100644
--- a/general/runtests.wrk
+++ b/general/runtests.wrk
@@ -60,7 +60,7 @@ $TIME $CC $CFLAGS -o stat stat.c -lm 2>> smcomp.time || eval $errexit
$TIME $CC $CFLAGS -o stat stat.c -lm 2>> smcomp.time || eval $errexit
$TIME $CC $CFLAGS -o stat stat.c -lm 2>> smcomp.time || eval $errexit
set -e
-./stat smcomp.time
+./stat.exe smcomp.time
set +e
echo ""
@@ -76,7 +76,7 @@ set -e
# versions of tbl.
egrep -v '^tbl:.*$' <tbl.time >tbl.new
mv -f tbl.new tbl.time
-./stat tbl.time
+./stat.exe tbl.time
set +e
echo ""
@@ -89,7 +89,7 @@ $TIME nroff < nroff.tbl > nroff.out 2>> nroff.time || cat nroff.time
$TIME nroff < nroff.tbl > nroff.out 2>> nroff.time || cat nroff.time
rm nroff.out nroff.tbl
set -e
-./stat nroff.time
+./stat.exe nroff.time
set +e
echo ""
@@ -101,9 +101,9 @@ $TIME $CC $CFLAGS -o large large.c 2>> lrgcomp.time || eval $errexit
$TIME $CC $CFLAGS -o large large.c 2>> lrgcomp.time || eval $errexit
$TIME $CC $CFLAGS -o large large.c 2>> lrgcomp.time || eval $errexit
$TIME $CC $CFLAGS -o large large.c 2>> lrgcomp.time || eval $errexit
-rm large
+rm large.exe
set -e
-./stat lrgcomp.time
+./stat.exe lrgcomp.time
set +e
echo ""
@@ -116,7 +116,7 @@ $TIME ./large4.sh 2>> 4lrg.time || eval $errexit
$TIME ./large4.sh 2>> 4lrg.time || eval $errexit
$TIME ./large4.sh 2>> 4lrg.time || eval $errexit
set -e
-./stat 4lrg.time
+./stat.exe 4lrg.time
set +e
echo ""
@@ -134,7 +134,7 @@ rmdummy
grep -iv warning: makefile.time | grep -v 'make: ' > makefile.time2
mv makefile.time2 makefile.time
set -e
-./stat makefile.time
+./stat.exe makefile.time
set +e
echo ""
--
1.6.4.msysgit.0

View file

@ -0,0 +1,72 @@
From c640dc4eff98fe70732d0225d7b3f3e2b2e33e35 Mon Sep 17 00:00:00 2001
From: Casey Bodley <cbodley@citi.umich.edu>
Date: Mon, 11 Oct 2010 15:24:54 -0400
Subject: [PATCH 06/11] cthon: fixing op_unlk op_ren
fixing "ls" commands that unsuccessfully look for ".nfsXXXX" files instead of "nfsXXXX" files
---
special/op_ren.c | 6 +++---
special/op_unlk.c | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/special/op_ren.c b/special/op_ren.c
index 348b4f9..73fa409 100644
--- a/special/op_ren.c
+++ b/special/op_ren.c
@@ -120,13 +120,13 @@ main(argc, argv)
#endif /* O_RDWR */
printf("nfsjunk files before rename:\n ");
- system("ls -al .nfs*");
+ system("ls -al nfs*");
ret = rename(taname, tbname);
printf("%s open; rename ret = %d\n", tbname, ret);
if (ret)
xxit(" unlink");
printf("nfsjunk files after rename:\n ");
- system("ls -al .nfs*");
+ system("ls -al nfs*");
strcpy(wbuf, TMSG);
if ((ret = write(fd, wbuf, TBUFSIZ)) != TBUFSIZ) {
fprintf(stderr, "write ret %d; expected %d\n", ret, TBUFSIZ);
@@ -165,7 +165,7 @@ main(argc, argv)
}
printf("nfsjunk files after close:\n ");
- system("ls -al .nfs*");
+ system("ls -al nfs*");
if ((ret = close(fd)) == 0) {
errcount++;
diff --git a/special/op_unlk.c b/special/op_unlk.c
index 93a09b0..d5e5efc 100644
--- a/special/op_unlk.c
+++ b/special/op_unlk.c
@@ -78,13 +78,13 @@ main(argc, argv)
#ifndef WIN32
/* For WIN you can not delete the file if it is open */
printf("nfsjunk files before unlink:\n ");
- system("ls -al .nfs*");
+ system("ls -al nfs*");
ret = unlink(tname);
printf("%s open; unlink ret = %d\n", tname, ret);
if (ret)
xxit(" unlink");
printf("nfsjunk files after unlink:\n ");
- system("ls -al .nfs*");
+ system("ls -al nfs*");
#endif
strcpy(wbuf, TMSG);
if ((ret = write(fd, wbuf, TBUFSIZ)) != TBUFSIZ) {
@@ -137,7 +137,7 @@ main(argc, argv)
#ifndef WIN32
printf("nfsjunk files after close:\n ");
- system("ls -al .nfs*");
+ system("ls -al nfs*");
#endif
if ((ret = close(fd)) == 0) {
--
1.6.4.msysgit.0

View file

@ -0,0 +1,577 @@
From 8a73c727370c3062ff06f9203efbcc81ad37497e Mon Sep 17 00:00:00 2001
From: Casey Bodley <cbodley@citi.umich.edu>
Date: Mon, 11 Oct 2010 15:25:16 -0400
Subject: [PATCH 07/11] cthon: porting lock tests to win32 api
added '#ifdef _WIN32' blocks to implement the following changes:
int testfd -> HANDLE testfd
open() -> CreateFile()
close() -> CloseHandle()
unlink() -> DeleteFile()
write() -> WriteFile()
read() -> ReadFile()
ftruncate() -> SetFilePointer()+SetEndOfFile()
mmap() -> CreateFileMapping()+MapViewOfFile()
munmap() -> UnmapViewOfFile()+CloseHandle()
lockf(F_LOCK) -> LockFileEx()
lockf(F_TLOCK) -> LockFile()
lockf(F_ULOCK) -> UnlockFileEx()
lockf(F_TEST) -> LockFile()+UnlockFileEx()
some tests expect an overflow error when the lock range wraps, but win32 allows this. changed the expected errors for checks in _WIN32
skipping test8, which times 1000 consecutive calls to lock/unlock. this doesn't tell us anything, except that we're slow
skipping test10 which checks for splitting lock regions; in windows, the unlock range must match lock range exactly
for test11, the _WIN32 path reopens the file instead of using dup()/dup2(); the windows DuplicateHandle() function works differently, in that both copies of the handle must be closed before it releases its locks
for test12, it forks an extra 'subchild' process, takes a lock, then kills the process to make sure it releases the lock. had to move the open call from the child block into the subchild block for this to work; otherwise, the lock wouldn't release because the child still holds a handle
---
lock/tlock.c | 273 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 251 insertions(+), 22 deletions(-)
diff --git a/lock/tlock.c b/lock/tlock.c
index fe8c760..dac3519 100644
--- a/lock/tlock.c
+++ b/lock/tlock.c
@@ -54,6 +54,12 @@
#endif
#endif
+#define _WIN32
+
+#ifdef _WIN32
+# include <Windows.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
@@ -135,8 +141,16 @@ static int pidpipe[2];
static char testfile[256]; /* file for locking test */
static char *filepath = ".";
+#ifdef _WIN32
+static HANDLE testfd;
+#else
static int testfd;
+#endif
+
#ifdef MMAP
+#ifdef _WIN32
+static HANDLE mappinghandle;
+#endif
static caddr_t mappedaddr; /* address file is mapped to (some tests) */
static off_t mappedlen;
#endif
@@ -586,12 +600,21 @@ open_testfile(flags, modes)
int flags;
int modes;
{
-
+#ifdef _WIN32
+ testfd = CreateFile(testfile, GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+ if (testfd == INVALID_HANDLE_VALUE) {
+ fprintf(stderr, "CreateFile(%s) returned %d\n", testfile, GetLastError());
+ testexit(1);
+ }
+#else
testfd = open(testfile, flags, modes);
if (testfd < 0) {
perror("tlock: open");
testexit(1);
}
+#endif
}
static void
@@ -599,11 +622,17 @@ close_testfile(cleanup)
int cleanup;
{
- if (cleanup == JUST_CLOSE)
- comment("Closed testfile.");
+ if (cleanup == JUST_CLOSE)
+ comment("Closed testfile.");
+#ifdef _WIN32
+ CloseHandle(testfd);
+ if (cleanup == DO_UNLINK)
+ DeleteFile(testfile);
+#else
close(testfd);
if (cleanup == DO_UNLINK)
(void) unlink(testfile);
+#endif
}
static void
@@ -615,12 +644,28 @@ write_testfile(datap, offset, count, do_comment)
{
int result;
+#ifdef _WIN32
+ {
+ DWORD bytes = 0;
+ LARGE_INTEGER off = { offset };
+ OVERLAPPED overlapped = { 0 };
+ overlapped.Offset = off.LowPart;
+ overlapped.OffsetHigh = off.HighPart;
+
+ if (!WriteFile(testfd, datap, count, &bytes, &overlapped)) {
+ fprintf(stderr, "WriteFile() failed with %d\n", GetLastError());
+ testexit(1);
+ }
+ result = bytes;
+ }
+#else
(void) lseek(testfd, offset, 0);
result = write(testfd, datap, count);
if (result < 0) {
perror("tlock: testfile write");
testexit(1);
}
+#endif
if (result != count) {
fprintf(stderr, "tlock: short write (got %d, expected %d)\n",
result, count);
@@ -663,6 +708,21 @@ read_testfile(test, sec, datap, offset, count, pass, fail)
exit(1);
}
+#ifdef _WIN32
+ {
+ DWORD bytes = 0;
+ LARGE_INTEGER off = { offset };
+ OVERLAPPED overlapped = { 0 };
+ overlapped.Offset = off.LowPart;
+ overlapped.OffsetHigh = off.HighPart;
+
+ if (!ReadFile(testfd, array, count, &bytes, &overlapped)) {
+ fprintf(stderr, "ReadFile() failed with %d\n", GetLastError());
+ testexit(1);
+ }
+ result = bytes;
+ }
+#else
(void) lseek(testfd, offset, 0);
if (count > IORATE_BUFSIZE)
count = IORATE_BUFSIZE;
@@ -671,6 +731,7 @@ read_testfile(test, sec, datap, offset, count, pass, fail)
perror("tlock: testfile read");
testexit(1);
}
+#endif
if (result != count) {
fprintf(stderr, "tlock: short read (got %d, expected %d)\n",
result, count);
@@ -703,7 +764,6 @@ testdup2(fd1, fd2)
int fd1;
int fd2;
{
-
if (dup2(fd1, fd2) < 0) {
perror("tlock: dup2");
testexit(1);
@@ -713,12 +773,22 @@ testdup2(fd1, fd2)
static void
testtruncate()
{
-
- comment("Truncated testfile.");
+ comment("Truncated testfile.");
+#ifdef _WIN32
+ if (SetFilePointer(testfd, 0, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
+ fprintf(stderr, "SetFilePointer() failed with %d\n", GetLastError());
+ testexit(1);
+ }
+ if (!SetEndOfFile(testfd)) {
+ fprintf(stderr, "SetEndOfFile() failed with %d\n", GetLastError());
+ testexit(1);
+ }
+#else
if (ftruncate(testfd, (off_t)0) < 0) {
perror("tlock: ftruncate");
testexit(1);
}
+#endif
}
#ifdef MMAP
@@ -735,25 +805,120 @@ testtruncate()
static int
testmmap()
{
+#ifdef _WIN32
+ LARGE_INTEGER len = { mappedlen };
+
+ mappinghandle = CreateFileMapping(testfd, NULL,
+ PAGE_READWRITE, len.HighPart, len.LowPart, NULL);
+ if (mappinghandle == INVALID_HANDLE_VALUE)
+ return GetLastError();
+
+ mappedaddr = MapViewOfFile(mappinghandle, FILE_MAP_READ | FILE_MAP_WRITE,
+ 0, 0, len.QuadPart);
+ if (mappedaddr == NULL)
+ return GetLastError();
+#else
mappedaddr = mmap(0, mappedlen, PROT_READ | PROT_WRITE, MAP_SHARED,
testfd, (off_t)0);
if (mappedaddr == (caddr_t)MAP_FAILED)
return (errno);
+#endif
return (0);
}
static void
testmunmap()
{
- comment("unmap testfile.");
+ comment("unmap testfile.");
+#ifdef _WIN32
+ if (!UnmapViewOfFile(mappedaddr)) {
+ fprintf(stderr, "UnmapViewOfFile() failed with %d\n", GetLastError());
+ testexit(1);
+ }
+ CloseHandle(mappinghandle);
+#else
if (munmap(mappedaddr, mappedlen) < 0) {
perror("Can't unmap testfile.");
testexit(1);
}
+#endif
mappedaddr = (caddr_t)0xdeadbeef;
}
#endif /* MMAP */
+#ifdef _WIN32
+
+static int map_lock_error(int num, int sec, int status) {
+ switch (status) {
+ case NO_ERROR: return 0;
+ case ERROR_NOT_LOCKED:
+ case ERROR_LOCK_VIOLATION: return denied_err;
+ default:
+ comment("%d.%d unexpected windows error %d", num, sec, status);
+ testexit(1);
+ }
+}
+
+static void
+test(num, sec, func, offset, length, pass, fail)
+int num; /* test number */
+int sec; /* section number */
+int func; /* lockf function to invoke */
+off_t offset; /* starting offset of lock */
+off_t length; /* length of lock */
+int pass; /* expected return code */
+int fail; /* error vs warning */
+{
+ int result = PASS;
+ LARGE_INTEGER off = { offset };
+ LARGE_INTEGER len = { length };
+ OVERLAPPED overlapped = { 0 };
+ overlapped.Offset = off.LowPart;
+ overlapped.OffsetHigh = off.HighPart;
+
+ if (off.QuadPart + len.QuadPart < 0) {
+ result = EINVAL;
+ goto out;
+ }
+ if (length == 0)
+ len.QuadPart = ULLONG_MAX - offset;
+ if (len.QuadPart == 0) {
+ result = EINVAL;
+ goto out;
+ }
+
+ switch (func) {
+ case F_LOCK: /* blocking lock */
+ if (!LockFileEx(testfd, LOCKFILE_EXCLUSIVE_LOCK,
+ 0, len.LowPart, len.HighPart, &overlapped))
+ result = map_lock_error(num, sec, GetLastError());
+ break;
+
+ case F_TLOCK: /* non-blocking lock */
+ if (!LockFile(testfd, off.LowPart, off.HighPart, len.LowPart, len.HighPart))
+ result = map_lock_error(num, sec, GetLastError());
+ break;
+
+ case F_ULOCK:
+ if (!UnlockFileEx(testfd, 0, len.LowPart, len.HighPart, &overlapped))
+ result = map_lock_error(num, sec, GetLastError());
+ break;
+
+ case F_TEST:
+ if (!LockFile(testfd, off.LowPart, off.HighPart, len.LowPart, len.HighPart)) {
+ result = map_lock_error(num, sec, GetLastError());
+ } else if (!UnlockFileEx(testfd, 0, len.LowPart, len.HighPart, &overlapped)) {
+ fprintf(stderr, "UnlockFileEx() returned %d\n", GetLastError());
+ testexit(1);
+ }
+ break;
+ }
+out:
+ report(num, sec, tfunstr(func), offset, length, pass, result, fail);
+}
+
+#else /* !_WIN32 */
+
#ifdef USE_LOCKF
static void
@@ -854,11 +1019,16 @@ test(num, sec, func, offset, length, pass, fail)
}
#endif /* USE_LOCKF */
+#endif /* !_WIN32 */
static void
rate(cnt)
int cnt;
{
+#ifdef _WIN32
+ LARGE_INTEGER len = { 1 };
+ OVERLAPPED overlapped = { 0 };
+#endif
int i;
long beg;
long end;
@@ -867,9 +1037,17 @@ rate(cnt)
beg = times(&tms);
for (i = 0; i < cnt; i++) {
+#ifdef _WIN32
+ if (!LockFileEx(testfd, LOCKFILE_EXCLUSIVE_LOCK, 0,
+ len.LowPart, len.HighPart, &overlapped) ||
+ !UnlockFileEx(testfd, 0, len.LowPart,
+ len.HighPart, &overlapped)) {
+ fprintf(stderr, "tlock: rate error=%d.\n", GetLastError());
+#else
if ((lockf(testfd, F_LOCK, 1) != 0) ||
(lockf(testfd, F_ULOCK, 1) != 0)) {
fprintf(stderr, "tlock: rate error=%d.\n", errno);
+#endif
tstfail++;
break;
}
@@ -972,8 +1150,11 @@ test1()
* integer, no overflow). So treat those failures as
* warnings, not fatal.
*/
- test(1, 9, F_TEST, maxeof, maxeof, oflow_err,
- WARN);
+#ifdef _WIN32
+ test(1, 9, F_TEST, maxeof, maxeof, PASS, FATAL);
+#else
+ test(1, 9, F_TEST, maxeof, maxeof, oflow_err, WARN);
+#endif
close_testfile(DO_UNLINK);
childfree(0);
} else {
@@ -1006,10 +1187,12 @@ test2()
test(2, 5, F_TEST, (off_t)1, (off_t)END, denied_err, FATAL);
test(2, 6, F_TEST, (off_t)1, maxeof, denied_err, FATAL);
test(2, 7, F_TEST, maxeof, (off_t)1, denied_err, FATAL);
- test(2, 8, F_TEST, maxeof, (off_t)END, denied_err,
- FATAL);
- test(2, 9, F_TEST, maxeof, maxeof, oflow_err,
- WARN);
+ test(2, 8, F_TEST, maxeof, (off_t)END, denied_err, FATAL);
+#ifdef _WIN32
+ test(2, 9, F_TEST, maxeof, maxeof, denied_err, FATAL);
+#else
+ test(2, 9, F_TEST, maxeof, maxeof, oflow_err, WARN);
+#endif
close_testfile(DO_UNLINK);
parentfree(0);
}
@@ -1135,8 +1318,12 @@ test6()
FATAL);
test(6, 3, F_TEST, maxeof - 1, (off_t)END,
denied_err, FATAL);
- test(6, 4, F_TEST, maxeof, (off_t)1, denied_err, FATAL);
+ test(6, 4, F_TEST, maxeof, (off_t)1, denied_err, FATAL);
+#ifdef _WIN32
+ test(6, 5, F_TEST, maxeof, (off_t)2, denied_err, FATAL);
+#else
test(6, 5, F_TEST, maxeof, (off_t)2, oflow_err, WARN);
+#endif
test(6, 6, F_TEST, maxeof, (off_t)END, denied_err,
FATAL);
test(6, 7, F_TEST, (off_t)maxplus1, (off_t)END, EINVAL,
@@ -1320,7 +1507,9 @@ test10()
static void
test11()
{
+#ifndef _WIN32
int dupfd;
+#endif
char *data = "123456789abcdef";
int datalen;
@@ -1330,28 +1519,42 @@ test11()
parentwait();
header(11, "Make sure close() releases the process's locks.");
open_testfile(OPENFLAGS, OPENMODES);
+#ifndef _WIN32
dupfd = dup(testfd);
+#endif
test(11, 0, F_TLOCK, (off_t)0, (off_t)0, PASS, FATAL);
close_testfile(JUST_CLOSE);
childfree(0);
- parentwait();
- testdup2(dupfd, testfd);
+ parentwait();
+#ifdef _WIN32
+ open_testfile(OPENFLAGS, OPENMODES);
+#else
+ testdup2(dupfd, testfd);
+#endif
test(11, 3, F_TLOCK, (off_t)29, (off_t)1463, PASS, FATAL);
test(11, 4, F_TLOCK, (off_t)0x2000, (off_t)87, PASS, FATAL);
close_testfile(JUST_CLOSE);
childfree(0);
- parentwait();
- testdup2(dupfd, testfd);
+ parentwait();
+#ifdef _WIN32
+ open_testfile(OPENFLAGS, OPENMODES);
+#else
+ testdup2(dupfd, testfd);
+#endif
write_testfile(data, (off_t)0, datalen, COMMENT);
test(11, 7, F_TLOCK, (off_t)0, (off_t)0, PASS, FATAL);
write_testfile(data, (off_t)(datalen - 3), datalen, COMMENT);
close_testfile(JUST_CLOSE);
childfree(0);
- parentwait();
+ parentwait();
+#ifdef _WIN32
+ open_testfile(OPENFLAGS, OPENMODES);
+#else
testdup2(dupfd, testfd);
+#endif
write_testfile(data, (off_t)0, datalen, COMMENT);
test(11, 10, F_TLOCK, (off_t)0, (off_t)0, PASS, FATAL);
testtruncate();
@@ -1359,7 +1562,9 @@ test11()
childfree(0);
parentwait();
+#ifndef _WIN32
close(dupfd);
+#endif
close_testfile(DO_UNLINK);
} else {
parentfree(0);
@@ -1400,8 +1605,10 @@ test12()
open_testfile(OPENFLAGS, OPENMODES);
childfree(0);
- parentwait();
+ parentwait();
+#ifndef _WIN32
(void) lseek(testfd, (off_t)0, 0);
+#endif
if (read(pidpipe[0], &target, sizeof (target)) !=
sizeof (target)) {
perror("can't read pid to kill");
@@ -1420,7 +1627,9 @@ test12()
parentfree(0);
childwait();
+#ifndef _WIN32
open_testfile(OPENFLAGS, OPENMODES);
+#endif
/*
* Create a subprocess to obtain a lock and get killed. If
* the parent kills the regular child, tlock will stop
@@ -1440,7 +1649,9 @@ test12()
if (subchild > 0) {
/* original child */
sleep(wait_time);
+#ifndef _WIN32
(void) lseek(testfd, (off_t)0, 0);
+#endif
if (write(pidpipe[1], &subchild, sizeof (subchild)) !=
sizeof (subchild)) {
perror("can't record pid to kill");
@@ -1449,11 +1660,16 @@ test12()
}
parentfree(0);
childwait();
+#ifndef _WIN32
close_testfile(DO_UNLINK);
+#endif
} else {
/* subchild */
+#ifdef _WIN32
+ open_testfile(OPENFLAGS, OPENMODES);
+#endif
signal(SIGINT, SIG_DFL);
- test(12, 0, F_TLOCK, (off_t)0, (off_t)0, PASS, FATAL);
+ test(12, 0, F_TLOCK, (off_t)0, (off_t)0, PASS, FATAL);
for (;;)
sleep(1);
/* NOTREACHED */
@@ -1489,7 +1705,11 @@ test13()
lock1err = testmmap();
report(13, 1, "mmap", (off_t)0, (off_t)mappedlen, EAGAIN,
lock1err, WARN);
+#ifdef _WIN32
+ test(13, 2, F_ULOCK, (off_t)mappedlen - 2, (off_t)END, PASS, FATAL);
+#else
test(13, 2, F_ULOCK, (off_t)0, (off_t)END, PASS, FATAL);
+#endif
if (lock1err == 0)
testmunmap();
@@ -1505,6 +1725,9 @@ test13()
FATAL);
test(13, 4, F_TLOCK, (off_t)mappedlen - 2, (off_t)END,
lock1err, WARN);
+#ifdef _WIN32
+ testmunmap();
+#endif
close_testfile(DO_UNLINK);
childfree(0);
@@ -1589,21 +1812,27 @@ runtests()
if (DO_TEST(7)) {
test7();
}
+#ifndef _WIN32
if (DO_RATE(8)) {
test8();
}
+#endif
if (DO_MAND(9)) {
test9();
}
+#ifndef _WIN32
+ /* windows doesn't allow splitting lock ranges;
+ * unlock ranges must correspond exactly to lock ranges */
if (DO_TEST(10)) {
test10();
}
+#endif
if (DO_TEST(11)) {
test11();
}
if (DO_TEST(12)) {
test12();
- }
+ }
#ifdef MMAP
if (DO_TEST(13)) {
test13();
--
1.6.4.msysgit.0

View file

@ -0,0 +1,26 @@
From 520bd04d9752faa6f77acd50ea759d170fb149d4 Mon Sep 17 00:00:00 2001
From: Casey Bodley <cbodley@citi.umich.edu>
Date: Mon, 11 Oct 2010 15:25:41 -0400
Subject: [PATCH 08/11] cthon: disabling test8 from the basic test
it's a symlink test and we are not supporting symlinks on windows
---
basic/runtests | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/basic/runtests b/basic/runtests
index 32e1d85..0b2f205 100644
--- a/basic/runtests
+++ b/basic/runtests
@@ -69,7 +69,7 @@ fi
# Symlink and readlink test
echo ""
-./test8 $TESTARG
+#./test8 $TESTARG
# Getfs test
echo ""
--
1.6.4.msysgit.0

View file

@ -0,0 +1,26 @@
From aafcd8aea575739115458cf3aeb58611d65647ee Mon Sep 17 00:00:00 2001
From: Casey Bodley <cbodley@citi.umich.edu>
Date: Mon, 11 Oct 2010 15:26:01 -0400
Subject: [PATCH 09/11] cthon: enabling NATIVE64 for special tests
that enables 64bit offset tests in the special tests
---
tests.init | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tests.init b/tests.init
index 3a1ba74..c5116e6 100644
--- a/tests.init
+++ b/tests.init
@@ -205,7 +205,7 @@ LOCKTESTS=`echo tlocklfs tlock64`
# Use with Linux 2.4 / GNU libc 2.2
#CFLAGS=`echo -DLINUX -DGLIBC=22 -DMMAP -DSTDARG -fwritable-strings`
-CFLAGS=`echo -DLINUX -DGLIBC=22 -DMMAP -DSTDARG`
+CFLAGS=`echo -DLINUX -DGLIBC=22 -DMMAP -DSTDARG -DNATIVE64`
#LIBS=`echo -lnsl`
MOUNT=/bin/mount
UMOUNT=/bin/umount
--
1.6.4.msysgit.0

View file

@ -0,0 +1,60 @@
From c8deb58ef9500765aa38fc86747fca0add5d04b1 Mon Sep 17 00:00:00 2001
From: Casey Bodley <cbodley@citi.umich.edu>
Date: Mon, 11 Oct 2010 15:33:50 -0400
Subject: [PATCH 10/11] cthon: fixes for 64-bit locking
cthon04/lock/tlock.c: fixed initialization of LARGE_INTEGERs, and removed the parts of test() that return EINVAL (our driver should be returning ERROR_INVALID_LOCK_RANGE for those)
also updated the nfs_lock test program to take 64-bit input for length and offset
---
lock/tlock.c | 18 ++++++++----------
1 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/lock/tlock.c b/lock/tlock.c
index dac3519..f06de6c 100644
--- a/lock/tlock.c
+++ b/lock/tlock.c
@@ -848,9 +848,12 @@ testmunmap()
#ifdef _WIN32
+#define ERROR_INVALID_LOCK_RANGE 0x133 // 307
+
static int map_lock_error(int num, int sec, int status) {
switch (status) {
case NO_ERROR: return 0;
+ case ERROR_INVALID_LOCK_RANGE: return EINVAL;
case ERROR_NOT_LOCKED:
case ERROR_LOCK_VIOLATION: return denied_err;
default:
@@ -870,22 +873,17 @@ int pass; /* expected return code */
int fail; /* error vs warning */
{
int result = PASS;
- LARGE_INTEGER off = { offset };
- LARGE_INTEGER len = { length };
+ ULARGE_INTEGER off;
+ ULARGE_INTEGER len;
OVERLAPPED overlapped = { 0 };
+
+ off.QuadPart = offset;
+ len.QuadPart = length;
overlapped.Offset = off.LowPart;
overlapped.OffsetHigh = off.HighPart;
- if (off.QuadPart + len.QuadPart < 0) {
- result = EINVAL;
- goto out;
- }
if (length == 0)
len.QuadPart = ULLONG_MAX - offset;
- if (len.QuadPart == 0) {
- result = EINVAL;
- goto out;
- }
switch (func) {
case F_LOCK: /* blocking lock */
--
1.6.4.msysgit.0

View file

@ -0,0 +1,26 @@
From efeb9db4f13e1dabe29e8bcf97a503079efca8ab Mon Sep 17 00:00:00 2001
From: Casey Bodley <cbodley@citi.umich.edu>
Date: Mon, 11 Oct 2010 15:34:14 -0400
Subject: [PATCH 11/11] cthon: setting maxeof to be 64bit
old value was 0x7fffffff
---
lock/runtests | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lock/runtests b/lock/runtests
index a25f101..2335363 100644
--- a/lock/runtests
+++ b/lock/runtests
@@ -38,7 +38,7 @@ esac
if echo "$mntopts" | grep vers=2 > /dev/null
then
- TESTARGS="-v 2 $TESTARGS"
+ TESTARGS="-v 4 $TESTARGS"
fi
for i in $LOCKTESTS
--
1.6.4.msysgit.0