summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTrent Mick <trentm@activestate.com>2000-08-11 19:02:59 (GMT)
committerTrent Mick <trentm@activestate.com>2000-08-11 19:02:59 (GMT)
commitf29f47b38beae54db959d0dd2f0800d5dd3fc174 (patch)
tree72e00382e13f07c3299c36e851b5c766a3ef8783 /Lib
parent7932ed0ac4fb3db990ebffce0d281865d680a10e (diff)
downloadcpython-f29f47b38beae54db959d0dd2f0800d5dd3fc174.zip
cpython-f29f47b38beae54db959d0dd2f0800d5dd3fc174.tar.gz
cpython-f29f47b38beae54db959d0dd2f0800d5dd3fc174.tar.bz2
Add largefile support for Linux64 and WIn64. Add test_largefile and some minor
change to regrtest.py to allow optional running of test_largefile ('cause it's slow on Win64). This closes patches: http://sourceforge.net/patch/index.php?func=detailpatch&patch_id=100510&group_id=5470 and http://sourceforge.net/patch/index.php?func=detailpatch&patch_id=100511&group_id=5470
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/output/test_largefile1
-rwxr-xr-xLib/test/regrtest.py19
-rw-r--r--Lib/test/test_largefile.py129
3 files changed, 142 insertions, 7 deletions
diff --git a/Lib/test/output/test_largefile b/Lib/test/output/test_largefile
new file mode 100644
index 0000000..6cbf082
--- /dev/null
+++ b/Lib/test/output/test_largefile
@@ -0,0 +1 @@
+test_largefile
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 9b2466f..3bebca4 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -15,6 +15,7 @@ Command line options:
-s: single -- run only a single test (see below)
-r: random -- randomize test execution order
-l: leakdebug -- if cycle garbage collection is enabled, run with DEBUG_LEAK
+--have-resources -- run tests that require large resources (time/space)
If non-option arguments are present, they are names for tests to run,
unless -x is given, in which case they are names for tests not to run.
@@ -40,7 +41,8 @@ import random
import test_support
def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
- exclude=0, single=0, randomize=0, leakdebug=0):
+ exclude=0, single=0, randomize=0, leakdebug=0,
+ use_large_resources=0):
"""Execute a test suite.
This also parses command-line options and modifies its behavior
@@ -65,7 +67,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
"""
try:
- opts, args = getopt.getopt(sys.argv[1:], 'vgqxsrl')
+ opts, args = getopt.getopt(sys.argv[1:], 'vgqxsrl', ['have-resources'])
except getopt.error, msg:
print msg
print __doc__
@@ -78,6 +80,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
if o == '-s': single = 1
if o == '-r': randomize = 1
if o == '-l': leakdebug = 1
+ if o == '--have-resources': use_large_resources = 1
if generate and verbose:
print "-g and -v don't go together!"
return 2
@@ -121,19 +124,17 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
if randomize:
random.shuffle(tests)
test_support.verbose = verbose # Tell tests to be moderately quiet
+ test_support.use_large_resources = use_large_resources
save_modules = sys.modules.keys()
for test in tests:
if not quiet:
print test
- ok = runtest(test, generate, verbose, testdir)
+ ok = runtest(test, generate, verbose, quiet, testdir)
if ok > 0:
good.append(test)
elif ok == 0:
bad.append(test)
else:
- if not quiet:
- print "test", test,
- print "skipped -- an optional feature could not be imported"
skipped.append(test)
# Unload the newly imported modules (best effort finalization)
for module in sys.modules.keys():
@@ -194,12 +195,13 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
tests.sort()
return stdtests + tests
-def runtest(test, generate, verbose, testdir = None):
+def runtest(test, generate, verbose, quiet, testdir = None):
"""Run a single test.
test -- the name of the test
generate -- if true, generate output, instead of running the test
and comparing it to a previously created output file
verbose -- if true, print more messages
+ quiet -- if true, don't print 'skipped' messages (probably redundant)
testdir -- test directory
"""
test_support.unload(test)
@@ -228,6 +230,9 @@ def runtest(test, generate, verbose, testdir = None):
finally:
sys.stdout = save_stdout
except (ImportError, test_support.TestSkipped), msg:
+ if not quiet:
+ print "test", test,
+ print "skipped -- ", msg
return -1
except KeyboardInterrupt, v:
raise KeyboardInterrupt, v, sys.exc_info()[2]
diff --git a/Lib/test/test_largefile.py b/Lib/test/test_largefile.py
new file mode 100644
index 0000000..5b65237
--- /dev/null
+++ b/Lib/test/test_largefile.py
@@ -0,0 +1,129 @@
+#!python
+
+#----------------------------------------------------------------------
+# test largefile support on system where this makes sense
+#
+#XXX how to only run this when support is there
+#XXX how to only optionally run this, it will take along time
+#----------------------------------------------------------------------
+
+import test_support
+import os, struct, stat, sys
+
+
+# only run if the current system support large files
+f = open(test_support.TESTFN, 'w')
+try:
+ # 2**31 == 2147483648
+ f.seek(2147483649L)
+except OverflowError:
+ raise test_support.TestSkipped, "platform does not have largefile support"
+else:
+ f.close()
+
+
+# create >2GB file (2GB = 2147483648 bytes)
+size = 2500000000L
+name = test_support.TESTFN
+
+
+# on Windows this test comsumes large resources:
+# it takes a long time to build the >2GB file and takes >2GB of disk space
+# therefore test_support.use_large_resources must be defined to run this test
+if sys.platform[:3] == 'win' and not test_support.use_large_resources:
+ raise test_support.TestSkipped, \
+ "test requires %s bytes and a long time to run" % str(size)
+
+
+
+def expect(got_this, expect_this):
+ if test_support.verbose:
+ print '%s =?= %s ...' % (`got_this`, `expect_this`),
+ if got_this != expect_this:
+ if test_support.verbose:
+ print 'no'
+ raise test_support.TestFailed, 'got %s, but expected %s' %\
+ (str(got_this), str(expect_this))
+ else:
+ if test_support.verbose:
+ print 'yes'
+
+
+# test that each file function works as expected for a large (i.e. >2GB, do
+# we have to check >4GB) files
+
+if test_support.verbose:
+ print 'create large file via seek (may be sparse file) ...'
+f = open(name, 'w')
+f.seek(size)
+f.write('a')
+f.flush()
+expect(os.fstat(f.fileno())[stat.ST_SIZE], size+1)
+if test_support.verbose:
+ print 'check file size with os.fstat'
+f.close()
+if test_support.verbose:
+ print 'check file size with os.stat'
+expect(os.stat(name)[stat.ST_SIZE], size+1)
+
+if test_support.verbose:
+ print 'play around with seek() and read() with the built largefile'
+f = open(name, 'r')
+expect(f.tell(), 0)
+expect(f.read(1), '\000')
+expect(f.tell(), 1)
+f.seek(0)
+expect(f.tell(), 0)
+f.seek(0, 0)
+expect(f.tell(), 0)
+f.seek(42)
+expect(f.tell(), 42)
+f.seek(42, 0)
+expect(f.tell(), 42)
+f.seek(42, 1)
+expect(f.tell(), 84)
+f.seek(0, 1)
+expect(f.tell(), 84)
+f.seek(0, 2) # seek from the end
+expect(f.tell(), size + 1 + 0)
+f.seek(-10, 2)
+expect(f.tell(), size + 1 - 10)
+f.seek(-size-1, 2)
+expect(f.tell(), 0)
+f.seek(size)
+expect(f.tell(), size)
+expect(f.read(1), 'a') # the 'a' that was written at the end of the file above
+f.close()
+
+if test_support.verbose:
+ print 'play around with os.lseek() with the built largefile'
+f = open(name, 'r')
+expect(os.lseek(f.fileno(), 0, 0), 0)
+expect(os.lseek(f.fileno(), 42, 0), 42)
+expect(os.lseek(f.fileno(), 42, 1), 84)
+expect(os.lseek(f.fileno(), 0, 1), 84)
+expect(os.lseek(f.fileno(), 0, 2), size+1+0)
+expect(os.lseek(f.fileno(), -10, 2), size+1-10)
+expect(os.lseek(f.fileno(), -size-1, 2), 0)
+expect(os.lseek(f.fileno(), size, 0), size)
+expect(f.read(1), 'a') # the 'a' that was written at the end of the file above
+f.close()
+
+
+# XXX add tests for truncate if it exists
+# XXX has truncate ever worked on Windows? specifically on WinNT I get:
+# "IOError: [Errno 13] Permission denied"
+##try:
+## newsize = size - 10
+## f.seek(newsize)
+## f.truncate()
+## expect(f.tell(), newsize)
+## newsize = newsize - 1
+## f.seek(0)
+## f.truncate(newsize)
+## expect(f.tell(), newsize)
+##except AttributeError:
+## pass
+
+os.unlink(name)
+