Home - Summaries: (main) : (py3.11) : Everything - Nightly builds - Benchmarks - RPython - Builders - About

rtyper/lltypesystem/test/test_llarena.py::TestStandalone::()::test_compiled_arena_protect

self = <rpython.rtyper.lltypesystem.test.test_llarena.TestStandalone object at 0xfffe2c4e68d0>

    def test_compiled_arena_protect(self):
        import sys
        S = lltype.Struct('S', ('x', lltype.Signed))
        #
        def fn(argv):
            testrun = int(argv[1])
            a = arena_malloc(65536, False)
            arena_reserve(a, llmemory.sizeof(S))
            p = llmemory.cast_adr_to_ptr(a + 23432, lltype.Ptr(S))
            p.x = 123
            assert p.x == 123
            arena_protect(a, 65536, True)
            result = 0
            if testrun == 1:
                print p.x       # segfault
            if testrun == 2:
                p.x = 124       # segfault
            arena_protect(a, 65536, False)
            p.x += 10
            print p.x
            return 0
        #
        t, cbuilder = self.compile(fn)
        data = cbuilder.cmdexec('0')
        assert data == '133\n'
        if has_protect:
            if sys.platform.startswith('win'):
                # Do not open error dialog box
                import ctypes
                SEM_NOGPFAULTERRORBOX = 0x0002 # From MSDN
                old_err_mode = ctypes.windll.kernel32.GetErrorMode()
                new_err_mode = old_err_mode | SEM_NOGPFAULTERRORBOX
                ctypes.windll.kernel32.SetErrorMode(new_err_mode)
>           cbuilder.cmdexec('1', expect_crash=True)

rtyper/lltypesystem/test/test_llarena.py:360: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <rpython.translator.c.genc.CStandaloneBuilder object at 0xfffe2c3ca450>
args = '1', env = None, err = False, expect_crash = True
exe = local('/tmp/pytest/usession-main-6487/testing_2/testing_2')

    def cmdexec(self, args='', env=None, err=False, expect_crash=False, exe=None):
        assert self._compiled
        if sys.platform == 'win32':
            #Prevent opening a dialog box
            import ctypes
            winapi = ctypes.windll.kernel32
            SetErrorMode = winapi.SetErrorMode
            SetErrorMode.argtypes=[ctypes.c_int]
    
            SEM_FAILCRITICALERRORS = 1
            SEM_NOGPFAULTERRORBOX  = 2
            SEM_NOOPENFILEERRORBOX = 0x8000
            flags = SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX \
                    | SEM_NOOPENFILEERRORBOX
            #Since there is no GetErrorMode, do a double Set
            old_mode = SetErrorMode(flags)
            SetErrorMode(old_mode | flags)
        if env is None:
            envrepr = ''
        else:
            envrepr = ' [env=%r]' % (env,)
            env.update(os.environ)
        if exe is None:
            exe = self.executable_name
        log.cmdexec('%s %s%s' % (exe, args, envrepr))
        res = self.translator.platform.execute(exe, args, env=env)
        if sys.platform == 'win32':
            SetErrorMode(old_mode)
        if res.returncode != 0:
            if expect_crash:
                if type(expect_crash) is int and expect_crash != res.returncode:
                    raise Exception("Returned %d, but expected %d" % (
                        res.returncode, expect_crash))
                return res.out, res.err
            print(res.err, file=sys.stderr)
            raise Exception("Returned %d" % (res.returncode,))
        if expect_crash:
>           raise Exception("Program did not crash!")
E           Exception: Program did not crash!

translator/c/genc.py:320: Exception
---------- Captured stderr call ----------
[rtyper] specializing: 100 / 427 blocks   (23%)
[rtyper] specializing: 200 / 430 blocks   (46%)
[rtyper] specializing: 300 / 434 blocks   (69%)
[rtyper] specializing: 400 / 434 blocks   (92%)
[rtyper] -=- specialized 434 blocks -=-
[rtyper] -=- specialized 12 more blocks -=-
[rtyper] -=- specialized 4 more blocks -=-
[rtyper] -=- specialized 25 more blocks -=-
[rtyper] specializing: 500 / 535 blocks   (93%)
[rtyper] -=- specialized 60 more blocks -=-
[backendopt:inlining] phase with threshold factor: 32.4
[backendopt:inlining] heuristic: rpython.translator.backendopt.inline.inlining_heuristic
[backendopt:inlining] inlined 6 callsites.
[backendopt:malloc] starting malloc removal
[backendopt:malloc] removed 0 simple mallocs in total
[backendopt:mergeifblocks] starting to merge if blocks
[rtyper] specializing: 600 / 611 blocks   (98%)
[rtyper] -=- specialized 76 more blocks -=-
[rtyper] -=- specialized 0 more blocks -=-
[rtyper] -=- specialized 30 more blocks -=-
[backendopt:inlining] phase with threshold factor: 32.4
[backendopt:inlining] heuristic: rpython.translator.backendopt.inline.inlining_heuristic
[backendopt:inlining] inlined 1 callsites.
[backendopt:malloc] starting malloc removal
[backendopt:malloc] removed 0 simple mallocs in total
[backendopt:mergeifblocks] starting to merge if blocks
[backendopt:malloc] removed 0 simple mallocs in total
[c:database] GC transformer: finished helpers
[c:database] GC transformer: finished tables
[c:database] Inlining GC helpers and postprocessing
[c]      393 nodes  [ array: 26  func: 165  refcnt rtti: 18  struct: 184 ]
[c:database] Completed
[c:writing] structdef.h
[c:writing] forwarddecl.h
[c:writing] preimpl.h
[c:writing] data_rpython_flowspace.c
[c:writing] data_rpython_memory_gctransform.c
[c:writing] data_rpython_rlib.c
[c:writing] data_rpython_rtyper.c
[c:writing] data_rpython_rtyper_lltypesystem.c
[c:writing] data_rpython_rtyper_lltypesystem_test.c
[c:writing] data_rpython_translator_c.c
[c:writing] nonfuncnodes.c
[c:writing] data_rpython_rlib_1.c
[c:writing] data_rpython_rtyper_lltypesystem_1.c
[c:writing] implement.c
[c:writing] rpython_flowspace.c
[c:writing] rpython_memory_gctransform.c
[c:writing] rpython_rlib.c
[c:writing] rpython_rtyper.c
[c:writing] rpython_rtyper_lltypesystem.c
[c:writing] rpython_rtyper_lltypesystem_test.c
[c:writing] rpython_translator.c
[c:writing] rpython_translator_c.c
[platform:execute] make  in /tmp/pytest/usession-main-6487/testing_2
[c:cmdexec] /tmp/pytest/usession-main-6487/testing_2/testing_2 0
[c:cmdexec] /tmp/pytest/usession-main-6487/testing_2/testing_2 1
builder: rpython-linux-aarch64 build #538
test: rtyper/lltypesystem/test/test_llarena/py/TestStandalone/()/test_compiled_arena_protect