Jeremy Hylton | 74ce77f | 2002-04-23 20:21:22 +0000 | [diff] [blame] | 1 | import os |
| 2 | import resource |
| 3 | |
Barry Warsaw | 04f357c | 2002-07-23 19:04:11 +0000 | [diff] [blame] | 4 | from test.test_support import TESTFN |
Jeremy Hylton | 74ce77f | 2002-04-23 20:21:22 +0000 | [diff] [blame] | 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 | |
| 12 | try: |
| 13 | cur, max = resource.getrlimit(resource.RLIMIT_FSIZE) |
| 14 | except AttributeError: |
| 15 | pass |
| 16 | else: |
| 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 | try: |
| 26 | resource.setrlimit(resource.RLIMIT_FSIZE, (1024, max)) |
| 27 | f = open(TESTFN, "wb") |
| 28 | f.write("X" * 1024) |
| 29 | try: |
| 30 | f.write("Y") |
| 31 | f.flush() |
| 32 | except IOError: |
| 33 | pass |
| 34 | f.close() |
| 35 | os.unlink(TESTFN) |
| 36 | finally: |
| 37 | resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max)) |
| 38 | |
| 39 | # And be sure that setrlimit is checking for really large values |
| 40 | too_big = 10L**50 |
| 41 | try: |
| 42 | resource.setrlimit(resource.RLIMIT_FSIZE, (too_big, max)) |
| 43 | except OverflowError: |
| 44 | pass |
| 45 | try: |
| 46 | resource.setrlimit(resource.RLIMIT_FSIZE, (max, too_big)) |
| 47 | except OverflowError: |
| 48 | pass |