Beispiel #1
0
    def test_prlimit():
        old_limits = resource.getrlimit(resource.RLIMIT_STACK)
        assert resource.prlimit(0, resource.RLIMIT_STACK) == old_limits
        assert resource.prlimit(os.getpid(),
                                resource.RLIMIT_STACK) == old_limits

        # Unchanged
        assert resource.getrlimit(resource.RLIMIT_STACK) == old_limits

        # Raise the soft limit to match the hard limit
        new_limits = (old_limits[1], old_limits[1])
        assert resource.prlimit(os.getpid(), resource.RLIMIT_STACK,
                                new_limits) == old_limits
        # And make sure it was raised
        assert resource.prlimit(0, resource.RLIMIT_STACK,
                                new_limits) == new_limits
        assert resource.getrlimit(resource.RLIMIT_STACK) == new_limits

        # Change it back
        assert resource.prlimit(0, resource.RLIMIT_STACK,
                                old_limits) == new_limits
        # And make sure it was changed back
        assert resource.prlimit(os.getpid(), resource.RLIMIT_STACK,
                                old_limits) == old_limits
        assert resource.getrlimit(resource.RLIMIT_STACK) == old_limits
Beispiel #2
0
def test_setrlimit():
    # minimal "does not crash" test
    x, y = resource.getrlimit(resource.RLIMIT_CPU)
    resource.setrlimit(resource.RLIMIT_CPU, (x, y))
    # sometimes, x and y are very large (more than 53 bits).
    # for these huge values, int(float(x)) > x...
    xf = x + (0.2 if x >= 0 else -0.2)
    yf = y + (0.3 if y >= 0 else -0.3)
    if int(xf) == x and int(yf) == y:
        resource.setrlimit(resource.RLIMIT_CPU, (x, y))  # truncated to ints
Beispiel #3
0
def test_setrlimit():
    # minimal "does not crash" test
    x, y = resource.getrlimit(resource.RLIMIT_CPU)
    resource.setrlimit(resource.RLIMIT_CPU, (x, y))
    # sometimes, x and y are very large (more than 53 bits).
    # for these huge values, int(float(x)) > x...
    xf = x + (0.2 if x >= 0 else -0.2)
    yf = y + (0.3 if y >= 0 else -0.3)
    if int(xf) == x and int(yf) == y:
        resource.setrlimit(resource.RLIMIT_CPU, (x, y))  # truncated to ints
Beispiel #4
0
def test_getrlimit():
    x = resource.getrlimit(resource.RLIMIT_CPU)
    assert isinstance(x, tuple)
    assert len(x) == 2
    assert isinstance(x[0], (int, long))
    assert isinstance(x[1], (int, long))
Beispiel #5
0
def test_setrlimit():
    # minimal "does not crash" test
    x = resource.getrlimit(resource.RLIMIT_CPU)
    resource.setrlimit(resource.RLIMIT_CPU, x)
Beispiel #6
0
def test_getrlimit():
    x = resource.getrlimit(resource.RLIMIT_CPU)
    assert isinstance(x, tuple)
    assert len(x) == 2
    assert isinstance(x[0], (int, long))
    assert isinstance(x[1], (int, long))
Beispiel #7
0
def test_setrlimit():
    # minimal "does not crash" test
    x = resource.getrlimit(resource.RLIMIT_CPU)
    resource.setrlimit(resource.RLIMIT_CPU, x)