Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / lib / python2.4 / test / test_resource.py
CommitLineData
920dae64
AT
1import os
2import resource
3
4from test.test_support import TESTFN
5
6# This test is checking a few specific problem spots. RLIMIT_FSIZE
7# should be RLIM_INFINITY, which will be a really big number on a
8# platform with large file support. On these platforms, we need to
9# test that the get/setrlimit functions properly convert the number to
10# a C long long and that the conversion doesn't raise an error.
11
12try:
13 cur, max = resource.getrlimit(resource.RLIMIT_FSIZE)
14except AttributeError:
15 pass
16else:
17 print resource.RLIM_INFINITY == max
18 resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))
19
20# Now check to see what happens when the RLIMIT_FSIZE is small. Some
21# versions of Python were terminated by an uncaught SIGXFSZ, but
22# pythonrun.c has been fixed to ignore that exception. If so, the
23# write() should return EFBIG when the limit is exceeded.
24
25# At least one platform has an unlimited RLIMIT_FSIZE and attempts to
26# change it raise ValueError instead.
27
28try:
29 try:
30 resource.setrlimit(resource.RLIMIT_FSIZE, (1024, max))
31 limit_set = 1
32 except ValueError:
33 limit_set = 0
34 f = open(TESTFN, "wb")
35 f.write("X" * 1024)
36 try:
37 f.write("Y")
38 f.flush()
39 except IOError:
40 if not limit_set:
41 raise
42 f.close()
43 os.unlink(TESTFN)
44finally:
45 resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max))
46
47# And be sure that setrlimit is checking for really large values
48too_big = 10L**50
49try:
50 resource.setrlimit(resource.RLIMIT_FSIZE, (too_big, max))
51except (OverflowError, ValueError):
52 pass
53try:
54 resource.setrlimit(resource.RLIMIT_FSIZE, (max, too_big))
55except (OverflowError, ValueError):
56 pass