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

jit/backend/aarch64/test/test_runner.py::TestARM64::()::test_call_release_gil_variable_function_and_arguments

self = <rpython.jit.backend.aarch64.test.test_runner.TestARM64 object at 0x000000092b7a46e8>

    def test_call_release_gil_variable_function_and_arguments(self):
        from rpython.translator.tool.cbuild import ExternalCompilationInfo
        from rpython.rlib.libffi import types
        from rpython.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
        from rpython.rlib.rarithmetic import r_singlefloat
        from rpython.translator.c import primitive
    
    
        def same_as_for_box(b):
            if b.type == 'i':
                return rop.SAME_AS_I
            elif b.type == 'f':
                return rop.SAME_AS_F
            else:
                assert False
    
        cpu = self.cpu
        rnd = random.Random(525)
        seed = py.test.config.option.randomseed
        print("random seed %d" % seed)
    
        ALL_TYPES = [
            (types.unsigned, lltype.Unsigned),
            (types.signed,   lltype.Signed),
            (types.uint8,  rffi.UCHAR),
            (types.sint8,  rffi.SIGNEDCHAR),
            (types.uint16, rffi.USHORT),
            (types.sint16, rffi.SHORT),
            (types.uint32, rffi.UINT),
            (types.sint32, rffi.INT),
            ]
        if IS_32_BIT and cpu.supports_longlong:
            ALL_TYPES += [
                (types.uint64, lltype.UnsignedLongLong),
                (types.sint64, lltype.SignedLongLong),
                ] * 2
        if cpu.supports_floats:
            ALL_TYPES += [
                (types.double, rffi.DOUBLE),
                ] * 4
        if cpu.supports_singlefloats:
            ALL_TYPES += [
                (types.float,  rffi.FLOAT),
                ] * 4
    
        NB_TESTS = 100
        c_source = []
        all_tests = []
    
        def prepare_c_source():
            """Pick a random choice of argument types and length,
                and build a C function with these arguments.  The C
                function will simply copy them all into static global
                variables.  There are then additional functions to fetch
                them, one per argument, with a signature 'void(ARG *)'.
                """
            POSSIBLE_TYPES = [rnd.choice(ALL_TYPES)
                              for i in range(random.randrange(2, 5))]
            load_factor = rnd.random()
            keepalive_factor = rnd.random()
            #
            ffitypes = []
            ARGTYPES = []
            for i in range(rnd.randrange(4, 20)):
                ffitype, TP = rnd.choice(POSSIBLE_TYPES)
                ffitypes.append(ffitype)
                ARGTYPES.append(TP)
            fn_name = 'vartest%d' % k
            all_tests.append((ARGTYPES, ffitypes, fn_name))
            #
            fn_args = []
            for i, ARG in enumerate(ARGTYPES):
                arg_decl = primitive.cdecl(primitive.PrimitiveType[ARG],
                                           'x%d' % i)
                fn_args.append(arg_decl)
                var_name = 'argcopy_%s_x%d' % (fn_name, i)
                var_decl = primitive.cdecl(primitive.PrimitiveType[ARG],
                                           var_name)
                c_source.append('static %s;' % var_decl)
                getter_name = '%s_get%d' % (fn_name, i)
                c_source.append('RPY_EXPORTED void %s(%s) { *p = %s; }' % (
                    getter_name,
                    primitive.cdecl(primitive.PrimitiveType[ARG], '*p'),
                    var_name))
            c_source.append('#include <stdio.h>')
            c_source.append('')
            c_source.append('static void real%s(%s)' % (
                fn_name, ', '.join(fn_args)))
            c_source.append('{')
            for i in range(len(ARGTYPES)):
                if ARGTYPES[i] is lltype.Float:
                    c_source.append('    fprintf(stderr, "x%d = %%f\\n", x%d);' % (i, i))
                elif ARGTYPES[i] is lltype.Signed:
                    c_source.append('    fprintf(stderr, "x%d = %%ld\\n", x%d);' % (i, i))
                elif ARGTYPES[i] is rffi.UINT:
                    c_source.append('    fprintf(stderr, "x%d = %%u\\n", x%d);' % (i, i))
            for i in range(len(ARGTYPES)):
                c_source.append('    argcopy_%s_x%d = x%d;' % (fn_name, i, i))
            c_source.append('}')
            c_source.append('RPY_EXPORTED void *%s(void)' % fn_name)
            c_source.append('{')
            c_source.append('    return (void *)&real%s;' % fn_name)
            c_source.append('}')
            c_source.append('')
    
        for k in range(NB_TESTS):
            prepare_c_source()
    
        eci = ExternalCompilationInfo(
            separate_module_sources=['\n'.join(c_source)])
    
        for k in range(NB_TESTS):
            ARGTYPES, ffitypes, fn_name = all_tests[k]
            func_getter_ptr = rffi.llexternal(fn_name, [], lltype.Signed,
                                         compilation_info=eci, _nowrapper=True)
            load_factor = rnd.random()
            keepalive_factor = rnd.random()
            #
            func_raw = func_getter_ptr()
            calldescr = cpu._calldescr_dynamic_for_tests(ffitypes, types.void)
            faildescr = BasicFailDescr(1)
            #
            argboxes = [InputArgInt()]   # for the function to call
            codes = ['X']
            for ffitype in ffitypes:
                kind = types.getkind(ffitype)
                codes.append(kind)
                if kind in 'uis':
                    b1 = InputArgInt()
                elif kind in 'fUI':
                    b1 = InputArgFloat()
                else:
                    assert 0, kind
                argboxes.append(b1)
            codes = ''.join(codes)     # useful for pdb
            print()
            print(codes)
            #
            argvalues = [func_raw]
            for TP in ARGTYPES:
                r = (rnd.random() - 0.5) * 999999999999.9
                r = rffi.cast(TP, r)
                argvalues.append(r)
            #
            argvalues_normal = argvalues[:1]
            for ffitype, r in zip(ffitypes, argvalues[1:]):
                kind = types.getkind(ffitype)
                if kind in 'ui':
                    r = rffi.cast(lltype.Signed, r)
                elif kind in 's':
                    r, = struct.unpack("i", struct.pack("f", float(r)))
                elif kind in 'f':
                    r = longlong.getfloatstorage(r)
                elif kind in 'UI':   # 32-bit only
                    r = rffi.cast(lltype.SignedLongLong, r)
                else:
                    assert 0
                argvalues_normal.append(r)
            #
            ops = []
            loadcodes = []
            insideboxes = []
            for b1 in argboxes:
                load = rnd.random() < load_factor
                loadcodes.append(' ^'[load])
                if load:
                    b2 = ResOperation(same_as_for_box(b1), [b1])
                    ops.insert(rnd.randrange(0, len(ops)+1), b2)
                    b1 = b2
                insideboxes.append(b1)
            loadcodes = ''.join(loadcodes)
            print(loadcodes)
            ops += [
                ResOperation(rop.CALL_RELEASE_GIL_N,
                             [ConstInt(0)] + insideboxes,
                             descr=calldescr),
                ResOperation(rop.GUARD_NOT_FORCED, [], descr=faildescr),
                ResOperation(rop.FINISH, [], descr=BasicFinalDescr(0))
                ]
            ops[-2].setfailargs([])
            # keep alive a random subset of the insideboxes
            for b1 in insideboxes:
                if rnd.random() < keepalive_factor:
                    ops.insert(-1, ResOperation(same_as_for_box(b1), [b1]))
            looptoken = JitCellToken()
            self.cpu.compile_loop(argboxes, ops, looptoken)
            #
            deadframe = self.cpu.execute_token(looptoken, *argvalues_normal)
            fail = self.cpu.get_latest_descr(deadframe)
            assert fail.identifier == 0
            expected = argvalues[1:]
            got = []
            for i, ARG in enumerate(ARGTYPES):
                PARG = rffi.CArrayPtr(ARG)
                getter_name = '%s_get%d' % (fn_name, i)
                getter_ptr = rffi.llexternal(getter_name, [PARG], lltype.Void,
                                             compilation_info=eci,
                                             _nowrapper=True)
                my_arg = lltype.malloc(PARG.TO, 1, zero=True, flavor='raw')
                getter_ptr(my_arg)
                got.append(my_arg[0])
                lltype.free(my_arg, flavor='raw')
            different_values = ['x%d: got %r, expected %r' % (i, a, b)
                                for i, (a, b) in enumerate(zip(got, expected))
                                if a != b]
            assert got == expected, '\n'.join(
>               ['bad args, signature %r' % codes[1:]] + different_values)
E           AssertionError: bad args, signature 'uuuuuuuuuuuu'
E           x9: got 0L, expected 3329L
E           x10: got 0L, expected 127L
E           x11: got 0L, expected 22684L

jit/backend/test/runner_test.py:3125: AssertionError
---------- Captured stdout call ----------
random seed 2045

Xffifff
   ^   

Xfuiuffuiiifuu
  ^  ^^^     ^

Xifiifii
^ ^^^^^^

Xiififfiiffff
^^^^^^^ ^^^^^

Xffuufuuu
 ^  ^^^^ 

Xiuifufuuuuiii
^^^^^^^^^^^^^^

Xiiiiiiuii
^   ^^^^^^

Xfffffffff
^ ^ ^^ ^^ 

Xffiffffffffiiiiffi
 ^^  ^^   ^ ^ ^   ^

Xfffufffffuffffff
^^^^^^^^ ^   ^ ^ 

Xuuuuuuuuuuuu
 ^^^ ^^^^^^^^
---------- Captured stderr call ----------
x0 = 286673871893.095215
x1 = -253160892500.616028
x3 = 195801829206.007477
x4 = -404294963499.490540
x5 = -183816851866.232483
x0 = 92041675381.546631
x4 = -143919589763.631775
x5 = 228803711161.628235
x10 = 230394166547.991119
x1 = 53333506647.978310
x4 = 472119434352.025940
x2 = -63716533082.904549
x4 = 108077875232.677490
x5 = 209952675735.888611
x8 = 276360328216.868103
x9 = 162386990246.194153
x10 = 231480032511.534210
x11 = -200129644559.626526
x0 = -272190761434.207703
x1 = -311568987219.753174
x3 = 825192533
x4 = -198882325888.710785
x6 = 2831576112
x7 = 2256334526
x0 = -2142889408
x2 = -178953894152
x3 = 213369325630.198151
x4 = 4071145508
x5 = -498711406134.286560
x7 = 903796632
x8 = 2968246683
x10 = 364644964444
x11 = 427475989689
x12 = 463738133518
x0 = -353619498792.776367
x1 = -288806819209.536560
x2 = -72021016799.689331
x3 = 486667103446.864563
x4 = -434163685240.946960
x5 = 76830253574.004501
x6 = -94929216318.993484
x7 = 313685556272.734009
x8 = -457179065365.605835
x0 = 181971327792.006866
x1 = -7316881887.247596
x3 = -418503275390.994446
x4 = -367786949581.622009
x5 = 322072746891.659302
x6 = -181012285904.721863
x7 = 469205436234.711182
x8 = 178588207512.458313
x9 = 477182860445.114380
x10 = -167300347988.077606
x15 = 331735003635.401123
x16 = 189003078887.394409
x0 = -254679282596.049500
x1 = 375629722457.770142
x2 = -249679153076.549316
x3 = 2964728559
x4 = -427217705862.808960
x5 = -355911972223.586975
x6 = 281476081771.808228
x7 = -33764775861.034946
x8 = -452153471471.818054
x9 = 667438304
x10 = 371342234217.062988
x11 = -468630010952.880676
x12 = -462828730150.132751
x13 = 268069904887.968414
x14 = 283506818792.026855
x15 = 370732777919.585022
x5 = 3870996609
builder: rpython-macos-arm64 build #751*
test: jit/backend/aarch64/test/test_runner.py::TestARM64::()::test_call_release_gil_variable_function_and_arguments