File: test_rsignal.py

package info (click to toggle)
pypy 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 107,216 kB
  • sloc: python: 1,201,787; ansic: 62,419; asm: 5,169; cpp: 3,017; sh: 2,534; makefile: 545; xml: 243; lisp: 45; awk: 4
file content (60 lines) | stat: -rw-r--r-- 1,723 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os, py, errno
from rpython.translator.c.test.test_genc import compile
from rpython.rlib import rsignal

def setup_module(mod):
    if not hasattr(os, 'kill') or not hasattr(os, 'getpid'):
        py.test.skip("requires os.kill() and os.getpid()")
    if not hasattr(rsignal, 'SIGUSR1'):
        py.test.skip("requires SIGUSR1 in signal")


def check(expected):
    res = rsignal.pypysig_poll()
    os.write(1, "poll() => %d, expected %d\n" % (res, expected))
    assert res == expected

def test_simple():
    import os
    check(-1)
    check(-1)
    for i in range(3):
        rsignal.pypysig_setflag(rsignal.SIGUSR1)
        os.kill(os.getpid(), rsignal.SIGUSR1)
        check(rsignal.SIGUSR1)
        check(-1)
        check(-1)

    rsignal.pypysig_ignore(rsignal.SIGUSR1)
    os.kill(os.getpid(), rsignal.SIGUSR1)
    check(-1)
    check(-1)

    rsignal.pypysig_default(rsignal.SIGUSR1)
    check(-1)


def test_compile():
    fn = compile(test_simple, [])
    fn()

def test_compile_wakeup_fd():
    def fn():
        rd, wr = os.pipe()
        rsignal.pypysig_set_wakeup_fd(wr, False)
        for i in range(3):
            rsignal.pypysig_setflag(rsignal.SIGUSR1)
            os.kill(os.getpid(), rsignal.SIGUSR1)
            check(rsignal.SIGUSR1)
            check(-1)
            check(-1)
        x = os.read(rd, 10)
        assert x == chr(rsignal.SIGUSR1) * 3
        #
        rsignal.pypysig_set_wakeup_fd(rd, False)   # can't write there
        os.kill(os.getpid(), rsignal.SIGUSR1)

    fn = compile(fn, [], return_stderr=True)
    stderr = fn()
    assert stderr.endswith('Exception ignored when trying to write to the '
                           'signal wakeup fd: Errno %d\n' % errno.EBADF)