Ticket #13748: 13748_fix_sig_block_test.patch

File 13748_fix_sig_block_test.patch, 3.2 KB (added by jdemeyer, 9 years ago)
  • c_lib/include/interrupt.h

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1357238060 -3600
    # Node ID b61c14deeb02d7aa55afa05ea5d21b727dc9dd3a
    # Parent  06b291a2f9840802870775041c1b5214f3666b5a
    Fix test_sig_block() test, move all code inside the try/except block
    
    diff --git a/c_lib/include/interrupt.h b/c_lib/include/interrupt.h
    a b  
    184184{
    185185    _signals.s = message;
    186186#if ENABLE_DEBUG_INTERRUPT
    187     fprintf(stderr, "sig_on (counter = %i) at %s:%i\n", _signals.sig_on_count+1, file, line);
     187    fprintf(stderr, "sig_on (count = %i) at %s:%i\n", _signals.sig_on_count+1, file, line);
    188188    fflush(stderr);
    189189#endif
    190190    if (_signals.sig_on_count > 0)
     
    241241static inline void _sig_off_(const char* file, int line)
    242242{
    243243#if ENABLE_DEBUG_INTERRUPT
    244     fprintf(stderr, "sig_off (counter = %i) at %s:%i\n", _signals.sig_on_count, file, line);
     244    fprintf(stderr, "sig_off (count = %i) at %s:%i\n", _signals.sig_on_count, file, line);
    245245    fflush(stderr);
    246246#endif
    247247    if (unlikely(_signals.sig_on_count <= 0))
     
    311311 */
    312312static inline void sig_block()
    313313{
     314#if ENABLE_DEBUG_INTERRUPT
     315    if (_signals.block_sigint != 0)
     316    {
     317        fprintf(stderr, "\n*** WARNING *** sig_block() with sig_on_count = %i, block_sigint = %i\n", _signals.sig_on_count, _signals.block_sigint);
     318        print_backtrace();
     319    }
     320#endif
    314321    _signals.block_sigint = 1;
    315322}
    316323
    317324static inline void sig_unblock()
    318325{
     326#if ENABLE_DEBUG_INTERRUPT
     327    if (_signals.block_sigint != 1)
     328    {
     329        fprintf(stderr, "\n*** WARNING *** sig_unblock() with sig_on_count = %i, block_sigint = %i\n", _signals.sig_on_count, _signals.block_sigint);
     330        print_backtrace();
     331    }
     332#endif
    319333    _signals.block_sigint = 0;
    320334
    321335    if (unlikely(_signals.interrupt_received) && _signals.sig_on_count > 0)
  • sage/tests/c_lib.c

    diff --git a/sage/tests/c_lib.c b/sage/tests/c_lib.c
    a b  
    1111#include <signal.h>
    1212#include <sys/select.h>
    1313#include <sys/wait.h>
     14#include "interrupt.h"
    1415
    1516void ms_sleep(long ms)
    1617{
     
    5253        /* New process group to prevent us getting the signals. */
    5354        setpgid(0,0);
    5455
     56        /* Unblock SIGINT (to fix a warning when testing sig_block()) */
     57        _signals.block_sigint = 0;
     58
    5559        /* Make sure SIGTERM simply terminates the process */
    5660        signal(SIGTERM, SIG_DFL);
    5761
  • sage/tests/interrupt.pyx

    diff --git a/sage/tests/interrupt.pyx b/sage/tests/interrupt.pyx
    a b  
    698698
    699699    try:
    700700        sig_on()
     701        sig_block()
     702        signal_after_delay(SIGINT, delay)
     703        ms_sleep(delay * 2)  # We get signaled during this sleep
     704        v = 42
     705        sig_unblock()        # Here, the interrupt will be handled
     706        sig_off()
    701707    except KeyboardInterrupt:
    702708        return v
    703709
    704     sig_block()
    705     signal_after_delay(SIGINT, delay)
    706     ms_sleep(delay * 2)  # We get signaled during this sleep
    707     v = 42
    708     sig_unblock()        # Here, the interrupt will be handled
    709     return 1             # Never reached
     710    # Never reached
     711    return 1
    710712
    711713def test_sig_block_outside_sig_on(long delay = DEFAULT_DELAY):
    712714    """