Ticket #11079: 11079_sigsegv_test.patch

File 11079_sigsegv_test.patch, 2.9 KB (added by jdemeyer, 11 years ago)
  • sage/tests/interrupt.pyx

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1301405039 -7200
    # Node ID 72d81e85d3b28e83ba406c9b85e08db841f3a654
    # Parent  25931e04f20537a65ae8e4de37fea39b80b691d3
    #11079: Change segmentation_fault test to allow other signals
    (e.g. SIGBUS instead of SIGSEGV) when dereferencing a NULL pointer
    
    diff -r 25931e04f205 -r 72d81e85d3b2 sage/tests/interrupt.pyx
    a b  
    5656        s *= 2
    5757        if (s > 1000000): s = 1
    5858
    59 cdef void segmentation_fault():
     59# Dereference a NULL pointer on purpose. This signals a SIGSEGV on most
     60# systems, but on older Mac OS X and possibly other systems, this
     61# signals a SIGBUS instead. In any case, this should give some signal.
     62cdef void dereference_null_pointer():
    6063    cdef long* ptr = <long*>(0)
    6164    ptr[0] += 1
    6265
     
    443446########################################################################
    444447# Test with "true" errors (not signals raised by hand)                 #
    445448########################################################################
    446 def test_segmentation_fault():
     449def test_dereference_null_pointer():
    447450    """
    448     TESTS::
    449        
     451    TESTS:
     452   
     453    This test should result in either a Segmentation Fault or a Bus
     454    Error. ::
     455
    450456        sage: from sage.tests.interrupt import *
    451         sage: test_segmentation_fault()
     457        sage: test_dereference_null_pointer()
    452458        Traceback (most recent call last):
    453459        ...
    454         RuntimeError: Segmentation fault
     460        RuntimeError: ...
    455461    """
    456462    sig_on()
    457     segmentation_fault()
     463    dereference_null_pointer()
    458464
    459 def unguarded_segmentation_fault():
     465def unguarded_dereference_null_pointer():
    460466    """
    461467    TESTS:
    462468
    463     We run Sage in a subprocess and make it experience a true segmentation fault::
     469    We run Sage in a subprocess and dereference a NULL pointer without
     470    using ``sig_on()``. This will crash Sage::
    464471
    465472        sage: from subprocess import *
    466         sage: cmd = 'from sage.tests.interrupt import *; unguarded_segmentation_fault()'
     473        sage: cmd = 'from sage.tests.interrupt import *; unguarded_dereference_null_pointer()'
    467474        sage: print '---'; print Popen(['sage', '-c', cmd], stdout=PIPE, stderr=PIPE).communicate()[1]  # long time
    468475        -...
    469476        ------------------------------------------------------------------------
    470         Unhandled SIGSEGV: A segmentation fault occurred in Sage.
     477        Unhandled SIG...
    471478        This probably occurred because a *compiled* component of Sage has a bug
    472479        in it and is not properly wrapped with sig_on(), sig_off(). You might
    473480        want to run Sage under gdb with 'sage -gdb' to debug this.
     
    475482        ------------------------------------------------------------------------
    476483        ...
    477484    """
    478     segmentation_fault()
     485    dereference_null_pointer()
    479486
    480487def test_abort():
    481488    """